From faeceb71f3303dd36e8ac506cf6a9aaf25fa5862 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Sat, 25 Dec 2021 13:08:22 +0100 Subject: refactor: Fetch service inject asynchronously Since we don't plan to shim any APIs that must be present immediately when the service loads, we might as well switch to asynchronous IPC for fetching the script to inject into the main world. --- packages/main/src/index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'packages/main') diff --git a/packages/main/src/index.ts b/packages/main/src/index.ts index 4a51518..b134002 100644 --- a/packages/main/src/index.ts +++ b/packages/main/src/index.ts @@ -219,8 +219,8 @@ function createWindow(): Promise { webContents.send(MainToRendererIpcMessage.SharedStorePatch, patch); }); - ipcMain.on(ServiceToMainIpcMessage.ApiExposedInMainWorld, (event) => { - event.returnValue = event.sender.id == browserView.webContents.id + ipcMain.handle(ServiceToMainIpcMessage.ApiExposedInMainWorld, (event) => { + return event.sender.id == browserView.webContents.id ? serviceInject : null; }); @@ -229,7 +229,8 @@ function createWindow(): Promise { try { switch (channel) { case ServiceToMainIpcMessage.ApiExposedInMainWorld: - // Synchronous message must be handled with `ipcMain.on` + // Asynchronous message with reply must be handled in `ipcMain.handle`, + // otherwise electron emits a no handler registered warning. break; case ServiceToMainIpcMessage.SetUnreadCount: console.log('Unread count:', unreadCount.parse(args[0])); -- cgit v1.2.3-70-g09d2