From 3772e70c6ec9a30369cb0db198e0da578d328b0b Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Thu, 9 Oct 2025 09:23:34 -0700 Subject: [PATCH 1/2] refactor: second instance handling Signed-off-by: Adam Setch --- src/main/index.ts | 54 +++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index f5f63bd22..e55408831 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -78,6 +78,8 @@ let shouldUseAlternateIdleIcon = false; let shouldUseUnreadActiveIcon = true; app.whenReady().then(async () => { + preventSecondInstance(); + await onFirstRunMaybe(); appUpdater.start(); @@ -116,31 +118,6 @@ app.whenReady().then(async () => { }); }); - /** Prevent second instances */ - if (isWindows() || isLinux()) { - const gotTheLock = app.requestSingleInstanceLock(); - - if (!gotTheLock) { - logWarn('main:gotTheLock', 'Second instance detected, quitting'); - app.quit(); // Quit the second instance - return; - } - - app.on('second-instance', (_event, commandLine, _workingDirectory) => { - logInfo( - 'main:second-instance', - 'Second instance was launched. extracting command to forward', - ); - - // Get the URL from the command line arguments - const url = commandLine.find((arg) => arg.startsWith(`${protocol}://`)); - - if (url) { - handleURL(url); - } - }); - } - /** * Gitify custom IPC events - no response expected */ @@ -280,3 +257,30 @@ function setActiveIcon() { function setErrorIcon() { mb.tray.setImage(TrayIcons.error); } + +/** + * Prevent second instances + */ +function preventSecondInstance() { + const gotTheLock = app.requestSingleInstanceLock(); + + if (!gotTheLock) { + logWarn('main:gotTheLock', 'Second instance detected, quitting'); + app.quit(); // Quit the second instance + return; + } + + app.on('second-instance', (_event, commandLine, _workingDirectory) => { + logInfo( + 'main:second-instance', + 'Second instance was launched. extracting command to forward', + ); + + // Get the URL from the command line arguments + const url = commandLine.find((arg) => arg.startsWith(`${protocol}://`)); + + if (url) { + handleURL(url); + } + }); +} From f10f9cf51c569cf983852ceaf226638c577c078a Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Thu, 9 Oct 2025 09:24:56 -0700 Subject: [PATCH 2/2] refactor: second instance handling Signed-off-by: Adam Setch --- src/main/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/index.ts b/src/main/index.ts index e55408831..f7f125ea7 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -18,7 +18,6 @@ import { type IOpenExternal, } from '../shared/events'; import { logInfo, logWarn } from '../shared/logger'; -import { isLinux, isWindows } from '../shared/platform'; import { handleMainEvent, onMainEvent, sendRendererEvent } from './events'; import { onFirstRunMaybe } from './first-run';