-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: export network info from settings page
- Loading branch information
Showing
7 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { ProtoGrpcType } from '../api/generated'; | ||
|
||
import Logger from './logger'; | ||
import NetServiceFactory from './NetServiceFactory'; | ||
import { getPrivateNodeConnectionConfig } from './main/utils'; | ||
|
||
const PROTO_PATH = 'vendor/api/spacemesh/v1/debug.proto'; | ||
|
||
class DebugService extends NetServiceFactory< | ||
ProtoGrpcType, | ||
'v1', | ||
'DebugService' | ||
> { | ||
logger = Logger({ className: 'DebugService' }); | ||
|
||
createService = () => { | ||
this.createNetService( | ||
PROTO_PATH, | ||
getPrivateNodeConnectionConfig(), | ||
'v1', | ||
'DebugService' | ||
); | ||
}; | ||
|
||
getNetworkInfo = () => this.callService('NetworkInfo', {}); | ||
} | ||
|
||
export default DebugService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { writeFile } from 'fs/promises'; | ||
import { combineLatest, from, map, mergeMap, Observable } from 'rxjs'; | ||
import { BrowserWindow, dialog } from 'electron'; | ||
import { handleIPC, handlerResult, makeSubscription } from '../rx.utils'; | ||
import { ipcConsts } from '../../../app/vars'; | ||
import AdminService from '../../AdminService'; | ||
import DebugService from '../../DebugService'; | ||
import Logger from '../../logger'; | ||
|
||
const logger = Logger({ className: 'handleExportInfoIPC' }); | ||
|
||
const saveDialog = async ( | ||
browser: BrowserWindow, | ||
data: Record<string, any> | ||
) => { | ||
const { canceled, filePath } = await dialog.showSaveDialog(browser, { | ||
title: 'Export network info', | ||
buttonLabel: 'Export', | ||
defaultPath: 'netInfo.json', | ||
}); | ||
if (canceled || !filePath) { | ||
return { filePath: null, data, canceled }; | ||
} | ||
return { filePath, data, canceled }; | ||
}; | ||
|
||
const handleExportInfoIPC = ($mainWindow: Observable<BrowserWindow>) => | ||
makeSubscription( | ||
handleIPC( | ||
ipcConsts.EXPORT_NET_INFO, | ||
() => { | ||
const adminService = new AdminService(); | ||
const debugService = new DebugService(); | ||
debugService.createService(); | ||
adminService.createService(); | ||
|
||
const netInfo = from(debugService.getNetworkInfo()); | ||
const peerInfo = from(adminService.getPeerInfo()); | ||
|
||
return combineLatest([netInfo, peerInfo, $mainWindow]).pipe( | ||
mergeMap(([netInfo, peerInfo, browser]) => | ||
from(saveDialog(browser, { netInfo, peerInfo })) | ||
), | ||
map(handlerResult) | ||
); | ||
}, | ||
(data) => data | ||
), | ||
({ filePath, data }) => { | ||
if (filePath) { | ||
writeFile(filePath, JSON.stringify(data, null, 2), 'utf-8') | ||
// eslint-disable-next-line promise/always-return | ||
.then(() => { | ||
logger.log('Network data exported', { filePath, data }); | ||
}) | ||
.catch((err) => | ||
logger.error('Cannot write file', err, { filePath, data }) | ||
); | ||
} | ||
} | ||
); | ||
|
||
export default handleExportInfoIPC; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters