From 2a2bbea93cfb962425d1b9b6a6b9bf7dca420a60 Mon Sep 17 00:00:00 2001 From: Hakan Shehu Date: Sun, 27 Oct 2024 16:06:14 +0100 Subject: [PATCH] Fix window initialization --- desktop/src/main.ts | 50 +++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/desktop/src/main.ts b/desktop/src/main.ts index b970d67d..4f1481f7 100644 --- a/desktop/src/main.ts +++ b/desktop/src/main.ts @@ -50,27 +50,33 @@ const createWindow = async () => { }); } - protocol.handle('avatar', (request) => { - return avatarManager.handleAvatarRequest(request); - }); + if (!protocol.isProtocolHandled('avatar')) { + protocol.handle('avatar', (request) => { + return avatarManager.handleAvatarRequest(request); + }); + } - protocol.handle('local-file', (request) => { - return fileManager.handleFileRequest(request); - }); + if (!protocol.isProtocolHandled('local-file')) { + protocol.handle('local-file', (request) => { + return fileManager.handleFileRequest(request); + }); + } - protocol.handle('asset', (request) => { - const url = request.url.replace('asset://', ''); - if (MAIN_WINDOW_VITE_DEV_SERVER_URL) { - return net.fetch(`${MAIN_WINDOW_VITE_DEV_SERVER_URL}/assets/${url}`); - } + if (!protocol.isProtocolHandled('asset')) { + protocol.handle('asset', (request) => { + const url = request.url.replace('asset://', ''); + if (MAIN_WINDOW_VITE_DEV_SERVER_URL) { + return net.fetch(`${MAIN_WINDOW_VITE_DEV_SERVER_URL}/assets/${url}`); + } - const localFileUrl = `file://${path.join( - process.resourcesPath, - 'assets', - url, - )}`; - return net.fetch(localFileUrl); - }); + const localFileUrl = `file://${path.join( + process.resourcesPath, + 'assets', + url, + )}`; + return net.fetch(localFileUrl); + }); + } }; // This method will be called when Electron has finished @@ -82,6 +88,8 @@ app.on('ready', createWindow); // for applications and their menu bar to stay active until the user quits // explicitly with Cmd + Q. app.on('window-all-closed', () => { + eventBus.unsubscribe(subscriptionId); + subscriptionId = null; if (process.platform !== 'darwin') { app.quit(); } @@ -95,12 +103,6 @@ app.on('activate', () => { } }); -app.on('before-quit', () => { - if (subscriptionId !== null) { - eventBus.unsubscribe(subscriptionId); - } -}); - ipcMain.handle( 'execute-mutation', async (