@@ -22,23 +22,32 @@ export class Entrypoint {
22
22
}
23
23
24
24
public readonly start = ( ) : void => {
25
+ // Check we're the first instance of this application.
26
+ if ( ! this . application . requestSingleInstanceLock ( ) ) {
27
+ this . application . quit ( ) ;
28
+ }
29
+
25
30
const privSchemes = this . customProtocols . map ( ( p ) => p . privilegedSchemes ) . flat ( ) ;
26
31
log . verbose (
27
32
'Registering schemes as privileged:' ,
28
33
privSchemes . map ( ( s ) => s . scheme ) ,
29
34
) ;
30
35
protocol . registerSchemesAsPrivileged ( privSchemes ) ;
31
36
37
+ this . application . on ( 'second-instance' , this . onSecondInstance ) ;
32
38
this . application . on ( 'window-all-closed' , this . onWindowAllClosed ) ;
33
39
34
- // Signal to Electron that we're ready to go when it is .
40
+ // The ready handler should be the last registered as it may be fired immediately .
35
41
this . application . on ( 'ready' , this . onReady ) ;
36
42
} ;
37
43
38
- private readonly onWindowAllClosed = ( ) : void => {
39
- if ( process . platform !== 'darwin' ) {
40
- this . application . quit ( ) ;
41
- }
44
+ private readonly onSecondInstance = (
45
+ _event : Electron . Event ,
46
+ _argv : string [ ] ,
47
+ _workingDirectory : string ,
48
+ _additionalData : unknown ,
49
+ ) : void => {
50
+ this . mainWindow . bringWindowToTop ( ) ;
42
51
} ;
43
52
44
53
private readonly onReady = ( ) : void => {
@@ -49,6 +58,10 @@ export class Entrypoint {
49
58
. catch ( this . onFatalError ) ;
50
59
} ;
51
60
61
+ private readonly onWindowAllClosed = ( ) : void => {
62
+ this . application . quit ( ) ;
63
+ } ;
64
+
52
65
private readonly onFatalError = ( error : unknown ) : never => {
53
66
log . error ( error ) ;
54
67
// eslint-disable-next-line no-process-exit
0 commit comments