diff options
Diffstat (limited to 'gui/src')
| -rw-r--r-- | gui/src/main/index.ts | 89 | ||||
| -rw-r--r-- | gui/src/renderer/app.tsx | 17 | ||||
| -rw-r--r-- | gui/src/renderer/containers/SupportPage.tsx | 10 | ||||
| -rw-r--r-- | gui/src/renderer/lib/problem-report.ts | 53 | ||||
| -rw-r--r-- | gui/src/shared/ipc-event-channel.ts | 4 |
5 files changed, 49 insertions, 124 deletions
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index 36744104b5..159c8b7dfa 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -1,15 +1,5 @@ import { execFile } from 'child_process'; -import { - app, - BrowserWindow, - ipcMain, - Menu, - nativeImage, - screen, - session, - shell, - Tray, -} from 'electron'; +import { app, BrowserWindow, Menu, nativeImage, screen, session, shell, Tray } from 'electron'; import log from 'electron-log'; import mkdirp from 'mkdirp'; import moment from 'moment'; @@ -530,6 +520,11 @@ class ApplicationMain { if (this.windowController) { IpcMainEventChannel.daemonConnected.notify(this.windowController.webContents); } + + // show window when account is not set + if (!this.settings.accountToken) { + this.windowController?.show(); + } }; private onDaemonDisconnected = (error?: Error) => { @@ -1090,59 +1085,36 @@ class ApplicationMain { } }); - ipcMain.on('show-window', () => { - const windowController = this.windowController; - if (windowController) { - windowController.show(); + IpcMainEventChannel.problemReport.handleCollectLogs((toRedact) => { + const reportPath = path.join(app.getPath('temp'), uuid.v4() + '.log'); + const executable = resolveBin('mullvad-problem-report'); + const args = ['collect', '--output', reportPath]; + if (toRedact.length > 0) { + args.push('--redact', ...toRedact); } - }); - - ipcMain.on( - 'collect-logs', - (event: Electron.IpcMainEvent, requestId: string, toRedact: string[]) => { - const reportPath = path.join(app.getPath('temp'), uuid.v4() + '.log'); - const executable = resolveBin('mullvad-problem-report'); - const args = ['collect', '--output', reportPath]; - if (toRedact.length > 0) { - args.push('--redact', ...toRedact); - } + return new Promise((resolve, reject) => { execFile(executable, args, { windowsHide: true }, (error, stdout, stderr) => { if (error) { log.error( `Failed to collect a problem report. - Stdout: ${stdout.toString()} - Stderr: ${stderr.toString()}`, + Stdout: ${stdout.toString()} + Stderr: ${stderr.toString()}`, ); - - event.sender.send('collect-logs-reply', requestId, { - success: false, - error: error.message, - }); + reject(error.message); } else { log.debug(`Problem report was written to ${reportPath}`); - - event.sender.send('collect-logs-reply', requestId, { - success: true, - reportPath, - }); + resolve(reportPath); } }); - }, - ); + }); + }); - ipcMain.on( - 'send-problem-report', - ( - event: Electron.IpcMainEvent, - requestId: string, - email: string, - message: string, - savedReport: string, - ) => { - const executable = resolveBin('mullvad-problem-report'); - const args = ['send', '--email', email, '--message', message, '--report', savedReport]; + IpcMainEventChannel.problemReport.handleSendReport(({ email, message, savedReport }) => { + const executable = resolveBin('mullvad-problem-report'); + const args = ['send', '--email', email, '--message', message, '--report', savedReport]; + return new Promise((resolve, reject) => { execFile(executable, args, { windowsHide: true }, (error, stdout, stderr) => { if (error) { log.error( @@ -1150,21 +1122,14 @@ class ApplicationMain { Stdout: ${stdout.toString()} Stderr: ${stderr.toString()}`, ); - - event.sender.send('send-problem-report-reply', requestId, { - success: false, - error: error.message, - }); + reject(error.message); } else { log.info('Problem report was sent.'); - - event.sender.send('send-problem-report-reply', requestId, { - success: true, - }); + resolve(); } }); - }, - ); + }); + }); } private async createNewAccount(): Promise<string> { diff --git a/gui/src/renderer/app.tsx b/gui/src/renderer/app.tsx index a16718945c..76679427f4 100644 --- a/gui/src/renderer/app.tsx +++ b/gui/src/renderer/app.tsx @@ -1,4 +1,4 @@ -import { ipcRenderer, shell, webFrame } from 'electron'; +import { shell, webFrame } from 'electron'; import log from 'electron-log'; import * as React from 'react'; import { Provider } from 'react-redux'; @@ -424,6 +424,18 @@ export default class AppRenderer { consumePromise(IpcRendererEventChannel.splitTunneling.launchApplication(application)); } + public collectProblemReport(toRedact: string[]): Promise<string> { + return IpcRendererEventChannel.problemReport.collectLogs(toRedact); + } + + public async sendProblemReport( + email: string, + message: string, + savedReport: string, + ): Promise<void> { + await IpcRendererEventChannel.problemReport.sendReport({ email, message, savedReport }); + } + public getPreferredLocaleList(): IPreferredLocaleDescriptor[] { return [ { @@ -534,9 +546,6 @@ export default class AppRenderer { await this.autoConnect(); } else { this.history.resetWith('/login'); - - // show window when account is not set - ipcRenderer.send('show-window'); } } diff --git a/gui/src/renderer/containers/SupportPage.tsx b/gui/src/renderer/containers/SupportPage.tsx index d77ec3e421..e3e5ee7d4f 100644 --- a/gui/src/renderer/containers/SupportPage.tsx +++ b/gui/src/renderer/containers/SupportPage.tsx @@ -4,7 +4,7 @@ import { RouteComponentProps, withRouter } from 'react-router'; import { bindActionCreators } from 'redux'; import consumePromise from '../../shared/promise'; import Support from '../components/Support'; -import { collectProblemReport, sendProblemReport } from '../lib/problem-report'; +import withAppContext, { IAppContext } from '../context'; import { IReduxState, ReduxDispatch } from '../redux/store'; import supportActions from '../redux/support/actions'; @@ -16,7 +16,7 @@ const mapStateToProps = (state: IReduxState) => ({ outdatedVersion: state.version.suggestedUpgrade ? true : false, }); -const mapDispatchToProps = (dispatch: ReduxDispatch, props: RouteComponentProps) => { +const mapDispatchToProps = (dispatch: ReduxDispatch, props: IAppContext & RouteComponentProps) => { const { saveReportForm, clearReportForm } = bindActionCreators(supportActions, dispatch); return { @@ -28,10 +28,10 @@ const mapDispatchToProps = (dispatch: ReduxDispatch, props: RouteComponentProps) }, saveReportForm, clearReportForm, - collectProblemReport, - sendProblemReport, + collectProblemReport: props.app.collectProblemReport, + sendProblemReport: props.app.sendProblemReport, onExternalLink: (url: string) => shell.openExternal(url), }; }; -export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Support)); +export default withAppContext(withRouter(connect(mapStateToProps, mapDispatchToProps)(Support))); diff --git a/gui/src/renderer/lib/problem-report.ts b/gui/src/renderer/lib/problem-report.ts deleted file mode 100644 index 7213ed8d07..0000000000 --- a/gui/src/renderer/lib/problem-report.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { ipcRenderer } from 'electron'; -import * as uuid from 'uuid'; - -interface IErrorResult { - success: false; - error: string; -} -type CollectResult = { success: true; reportPath: string } | IErrorResult; -type SendResult = { success: true } | IErrorResult; - -const collectProblemReport = (toRedact: string[]): Promise<string> => { - return new Promise((resolve, reject) => { - const requestId = uuid.v4(); - const responseListener = ( - _event: Electron.Event, - responseId: string, - result: CollectResult, - ) => { - if (responseId === requestId) { - ipcRenderer.removeListener('collect-logs-reply', responseListener); - if (result.success) { - resolve(result.reportPath); - } else { - reject(new Error(result.error)); - } - } - }; - - ipcRenderer.on('collect-logs-reply', responseListener); - ipcRenderer.send('collect-logs', requestId, toRedact); - }); -}; - -const sendProblemReport = (email: string, message: string, savedReport: string): Promise<void> => { - return new Promise((resolve, reject) => { - const requestId = uuid.v4(); - const responseListener = (_event: Electron.Event, responseId: string, result: SendResult) => { - if (requestId === responseId) { - ipcRenderer.removeListener('send-problem-report-reply', responseListener); - if (result.success) { - resolve(); - } else { - reject(new Error(result.error)); - } - } - }; - - ipcRenderer.on('send-problem-report-reply', responseListener); - ipcRenderer.send('send-problem-report', requestId, email, message, savedReport); - }); -}; - -export { collectProblemReport, sendProblemReport }; diff --git a/gui/src/shared/ipc-event-channel.ts b/gui/src/shared/ipc-event-channel.ts index 11bbeef31f..b18e47e9f9 100644 --- a/gui/src/shared/ipc-event-channel.ts +++ b/gui/src/shared/ipc-event-channel.ts @@ -172,6 +172,10 @@ const ipc = { getApplications: invoke<void, ISplitTunnelingApplication[]>(), launchApplication: invoke<ISplitTunnelingApplication | string, void>(), }, + problemReport: { + collectLogs: invoke<string[], string>(), + sendReport: invoke<{ email: string; message: string; savedReport: string }, void>(), + }, }; export const IpcMainEventChannel = createIpcMain(ipc); |
