summaryrefslogtreecommitdiffhomepage
path: root/gui/src/shared
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2019-05-31 11:13:38 +0200
committerAndrej Mihajlov <and@mullvad.net>2019-09-03 11:44:35 +0200
commit299c3aa64955b6acb643f80ddd49dedde5c855fa (patch)
tree2f813c1a1c9bcf54f2980adccbbf5a70366d99c0 /gui/src/shared
parent6e62c3c65bfe729b9ef2fe5b27721d429b1b2c7e (diff)
downloadmullvadvpn-299c3aa64955b6acb643f80ddd49dedde5c855fa.tar.xz
mullvadvpn-299c3aa64955b6acb643f80ddd49dedde5c855fa.zip
Patch typescript typings and enable node integration (it's off by default now)
Diffstat (limited to 'gui/src/shared')
-rw-r--r--gui/src/shared/ipc-event-channel.ts66
1 files changed, 36 insertions, 30 deletions
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);
});