diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2019-05-31 11:13:38 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2019-09-03 11:44:35 +0200 |
| commit | 299c3aa64955b6acb643f80ddd49dedde5c855fa (patch) | |
| tree | 2f813c1a1c9bcf54f2980adccbbf5a70366d99c0 /gui/src | |
| parent | 6e62c3c65bfe729b9ef2fe5b27721d429b1b2c7e (diff) | |
| download | mullvadvpn-299c3aa64955b6acb643f80ddd49dedde5c855fa.tar.xz mullvadvpn-299c3aa64955b6acb643f80ddd49dedde5c855fa.zip | |
Patch typescript typings and enable node integration (it's off by default now)
Diffstat (limited to 'gui/src')
| -rw-r--r-- | gui/src/main/index.ts | 55 | ||||
| -rw-r--r-- | gui/src/shared/ipc-event-channel.ts | 66 |
2 files changed, 65 insertions, 56 deletions
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index 87d0de1d2e..27bfc61640 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -977,41 +977,44 @@ class ApplicationMain { } }); - ipcMain.on('collect-logs', (event: Electron.Event, requestId: string, toRedact: string[]) => { - const reportPath = path.join(app.getPath('temp'), uuid.v4() + '.log'); - const executable = resolveBin('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('problem-report'); + const args = ['collect', '--output', reportPath]; + if (toRedact.length > 0) { + args.push('--redact', ...toRedact); + } - execFile(executable, args, { windowsHide: true }, (error, stdout, stderr) => { - if (error) { - log.error( - `Failed to collect a problem report. + execFile(executable, args, { windowsHide: true }, (error, stdout, stderr) => { + if (error) { + log.error( + `Failed to collect a problem report. Stdout: ${stdout.toString()} Stderr: ${stderr.toString()}`, - ); + ); - event.sender.send('collect-logs-reply', requestId, { - success: false, - error: error.message, - }); - } else { - log.debug(`Problem report was written to ${reportPath}`); + event.sender.send('collect-logs-reply', requestId, { + success: false, + error: error.message, + }); + } else { + log.debug(`Problem report was written to ${reportPath}`); - event.sender.send('collect-logs-reply', requestId, { - success: true, - reportPath, - }); - } - }); - }); + event.sender.send('collect-logs-reply', requestId, { + success: true, + reportPath, + }); + } + }); + }, + ); ipcMain.on( 'send-problem-report', ( - event: Electron.Event, + event: Electron.IpcMainEvent, requestId: string, email: string, message: string, diff --git a/gui/src/shared/ipc-event-channel.ts b/gui/src/shared/ipc-event-channel.ts index f57368db2d..8283cf43dc 100644 --- a/gui/src/shared/ipc-event-channel.ts +++ b/gui/src/shared/ipc-event-channel.ts @@ -265,7 +265,7 @@ export class IpcRendererEventChannel { export class IpcMainEventChannel { public static state = { handleGet(fn: () => IAppStateSnapshot) { - ipcMain.on(GET_APP_STATE, (event: Electron.Event) => { + ipcMain.on(GET_APP_STATE, (event: Electron.IpcMainEvent) => { event.returnValue = fn(); }); }, @@ -349,7 +349,7 @@ export class IpcMainEventChannel { function listen<T>(event: string): (fn: (value: T) => void) => void { return (fn: (value: T) => void) => { - ipcRenderer.on(event, (_event: Electron.Event, newState: T) => fn(newState)); + ipcRenderer.on(event, (_event: Electron.IpcRendererEvent, newState: T) => fn(newState)); }; } @@ -381,7 +381,7 @@ function senderVoid(event: string): (webContents: WebContents) => void { function handler<T>(event: string): (handlerFn: (value: T) => void) => void { return (handlerFn: (value: T) => void) => { - ipcMain.on(event, (_event: Electron.Event, newValue: T) => { + ipcMain.on(event, (_event: Electron.IpcMainEvent, newValue: T) => { handlerFn(newValue); }); }; @@ -391,26 +391,29 @@ type RequestResult<T> = { type: 'success'; value: T } | { type: 'error'; message function requestHandler<T>(event: string): (fn: (...args: any[]) => Promise<T>) => void { return (fn: (...args: any[]) => Promise<T>) => { - ipcMain.on(event, async (ipcEvent: Electron.Event, requestId: string, ...args: any[]) => { - const responseEvent = `${event}-${requestId}`; - try { - const result: RequestResult<T> = { type: 'success', value: await fn(...args) }; + ipcMain.on( + event, + async (ipcEvent: Electron.IpcMainEvent, requestId: string, ...args: any[]) => { + const responseEvent = `${event}-${requestId}`; + try { + const result: RequestResult<T> = { type: 'success', value: await fn(...args) }; - if (ipcEvent.sender.isDestroyed()) { - log.debug(`Cannot send the reply for ${responseEvent} since the sender was destroyed.`); - } else { - ipcEvent.sender.send(responseEvent, result); - } - } catch (error) { - const result: RequestResult<T> = { type: 'error', message: error.message || '' }; + if (ipcEvent.sender.isDestroyed()) { + log.debug(`Cannot send the reply for ${responseEvent} since the sender was destroyed.`); + } else { + ipcEvent.sender.send(responseEvent, result); + } + } catch (error) { + const result: RequestResult<T> = { type: 'error', message: error.message || '' }; - if (ipcEvent.sender.isDestroyed()) { - log.debug(`Cannot send the reply for ${responseEvent} since the sender was destroyed.`); - } else { - ipcEvent.sender.send(responseEvent, result); + if (ipcEvent.sender.isDestroyed()) { + log.debug(`Cannot send the reply for ${responseEvent} since the sender was destroyed.`); + } else { + ipcEvent.sender.send(responseEvent, result); + } } - } - }); + }, + ); }; } @@ -420,17 +423,20 @@ function requestSender<T>(event: string): (...args: any[]) => Promise<T> { const requestId = uuid.v4(); const responseEvent = `${event}-${requestId}`; - ipcRenderer.once(responseEvent, (_ipcEvent: Electron.Event, result: RequestResult<T>) => { - switch (result.type) { - case 'error': - reject(new Error(result.message)); - break; + ipcRenderer.once( + responseEvent, + (_ipcEvent: Electron.IpcRendererEvent, result: RequestResult<T>) => { + switch (result.type) { + case 'error': + reject(new Error(result.message)); + break; - case 'success': - resolve(result.value); - break; - } - }); + case 'success': + resolve(result.value); + break; + } + }, + ); ipcRenderer.send(event, requestId, ...args); }); |
