Skip to content

Commit 3772e70

Browse files
committed
refactor: second instance handling
Signed-off-by: Adam Setch <[email protected]>
1 parent 52aeed4 commit 3772e70

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

src/main/index.ts

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ let shouldUseAlternateIdleIcon = false;
7878
let shouldUseUnreadActiveIcon = true;
7979

8080
app.whenReady().then(async () => {
81+
preventSecondInstance();
82+
8183
await onFirstRunMaybe();
8284

8385
appUpdater.start();
@@ -116,31 +118,6 @@ app.whenReady().then(async () => {
116118
});
117119
});
118120

119-
/** Prevent second instances */
120-
if (isWindows() || isLinux()) {
121-
const gotTheLock = app.requestSingleInstanceLock();
122-
123-
if (!gotTheLock) {
124-
logWarn('main:gotTheLock', 'Second instance detected, quitting');
125-
app.quit(); // Quit the second instance
126-
return;
127-
}
128-
129-
app.on('second-instance', (_event, commandLine, _workingDirectory) => {
130-
logInfo(
131-
'main:second-instance',
132-
'Second instance was launched. extracting command to forward',
133-
);
134-
135-
// Get the URL from the command line arguments
136-
const url = commandLine.find((arg) => arg.startsWith(`${protocol}://`));
137-
138-
if (url) {
139-
handleURL(url);
140-
}
141-
});
142-
}
143-
144121
/**
145122
* Gitify custom IPC events - no response expected
146123
*/
@@ -280,3 +257,30 @@ function setActiveIcon() {
280257
function setErrorIcon() {
281258
mb.tray.setImage(TrayIcons.error);
282259
}
260+
261+
/**
262+
* Prevent second instances
263+
*/
264+
function preventSecondInstance() {
265+
const gotTheLock = app.requestSingleInstanceLock();
266+
267+
if (!gotTheLock) {
268+
logWarn('main:gotTheLock', 'Second instance detected, quitting');
269+
app.quit(); // Quit the second instance
270+
return;
271+
}
272+
273+
app.on('second-instance', (_event, commandLine, _workingDirectory) => {
274+
logInfo(
275+
'main:second-instance',
276+
'Second instance was launched. extracting command to forward',
277+
);
278+
279+
// Get the URL from the command line arguments
280+
const url = commandLine.find((arg) => arg.startsWith(`${protocol}://`));
281+
282+
if (url) {
283+
handleURL(url);
284+
}
285+
});
286+
}

0 commit comments

Comments
 (0)