@@ -18,7 +18,6 @@ import {
1818 type IOpenExternal ,
1919} from '../shared/events' ;
2020import { logInfo , logWarn } from '../shared/logger' ;
21- import { isLinux , isWindows } from '../shared/platform' ;
2221
2322import { handleMainEvent , onMainEvent , sendRendererEvent } from './events' ;
2423import { onFirstRunMaybe } from './first-run' ;
@@ -78,6 +77,8 @@ let shouldUseAlternateIdleIcon = false;
7877let shouldUseUnreadActiveIcon = true ;
7978
8079app . whenReady ( ) . then ( async ( ) => {
80+ preventSecondInstance ( ) ;
81+
8182 await onFirstRunMaybe ( ) ;
8283
8384 appUpdater . start ( ) ;
@@ -116,31 +117,6 @@ app.whenReady().then(async () => {
116117 } ) ;
117118 } ) ;
118119
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-
144120 /**
145121 * Gitify custom IPC events - no response expected
146122 */
@@ -280,3 +256,30 @@ function setActiveIcon() {
280256function setErrorIcon ( ) {
281257 mb . tray . setImage ( TrayIcons . error ) ;
282258}
259+
260+ /**
261+ * Prevent second instances
262+ */
263+ function preventSecondInstance ( ) {
264+ const gotTheLock = app . requestSingleInstanceLock ( ) ;
265+
266+ if ( ! gotTheLock ) {
267+ logWarn ( 'main:gotTheLock' , 'Second instance detected, quitting' ) ;
268+ app . quit ( ) ; // Quit the second instance
269+ return ;
270+ }
271+
272+ app . on ( 'second-instance' , ( _event , commandLine , _workingDirectory ) => {
273+ logInfo (
274+ 'main:second-instance' ,
275+ 'Second instance was launched. extracting command to forward' ,
276+ ) ;
277+
278+ // Get the URL from the command line arguments
279+ const url = commandLine . find ( ( arg ) => arg . startsWith ( `${ protocol } ://` ) ) ;
280+
281+ if ( url ) {
282+ handleURL ( url ) ;
283+ }
284+ } ) ;
285+ }
0 commit comments