Skip to content

Open-source and local-first Slack and Notion alternative that puts you in control of your data

Fix window initialization

Hakan Shehu2a2bbea93cfb
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}`);
- }
-
- const localFileUrl = `file://${path.join(
- process.resourcesPath,
- 'assets',
- url,
- )}`;
- return net.fetch(localFileUrl);
- });
+ 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);
+ });
+ }
};
// 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 <T extends MutationInput>(