@@ -53,7 +53,7 @@ interface App extends EventEmitter {
53
53
hide ( ) : void
54
54
quit ( ) : void
55
55
exit ( exitCode ?: number ) : void
56
- requestSingleInstanceLock ( ) : boolean
56
+ requestSingleInstanceLock ( additionalData ?: Record < any , any > ) : boolean
57
57
}
58
58
59
59
/**
@@ -500,7 +500,12 @@ interface Command {
500
500
subwindowPlease : boolean
501
501
subwindowPrefs : ISubwindowPrefs
502
502
}
503
- export const getCommand = ( argv : string [ ] , screen : ( ) => Promise < { screen : Screen ; BrowserWindow : BW } > ) : Command => {
503
+ export const getCommand = (
504
+ argv : string [ ] ,
505
+ cwd : string ,
506
+ env : Record < any , any > ,
507
+ screen : ( ) => Promise < { screen : Screen ; BrowserWindow : BW } >
508
+ ) : Command => {
504
509
debug ( 'getCommand' , argv )
505
510
const dashDash = argv . lastIndexOf ( '--' )
506
511
argv = dashDash === - 1 ? argv . slice ( 1 ) : argv . slice ( dashDash + 1 )
@@ -528,6 +533,8 @@ export const getCommand = (argv: string[], screen: () => Promise<{ screen: Scree
528
533
529
534
let subwindowPlease = true
530
535
let subwindowPrefs : ISubwindowPrefs = {
536
+ cwd,
537
+ env,
531
538
fullscreen : true ,
532
539
width : windowDefaults . width ,
533
540
height : windowDefaults . height
@@ -537,13 +544,16 @@ export const getCommand = (argv: string[], screen: () => Promise<{ screen: Scree
537
544
// use a full window for 'shell'
538
545
argv = [ 'shell' ]
539
546
subwindowPlease = false
540
- subwindowPrefs = { }
547
+ subwindowPrefs = { cwd , env }
541
548
} else if ( process . env . KUI_POPUP ) {
542
549
argv = JSON . parse ( process . env . KUI_POPUP )
550
+ subwindowPrefs = { cwd, env }
543
551
}
544
552
545
553
if ( process . env . KUI_POPUP_WINDOW_RESIZE ) {
546
554
subwindowPrefs = {
555
+ cwd,
556
+ env,
547
557
fullscreen : true ,
548
558
position : async ( ) => getPositionForPopup ( await screen ( ) ) ,
549
559
width : popupWindowDefaults . width ,
@@ -628,23 +638,31 @@ export async function initElectron(
628
638
const widthFromCaller = subwindowPrefs && subwindowPrefs . width
629
639
const heightFromCaller = subwindowPrefs && subwindowPrefs . height
630
640
631
- app . on ( 'second-instance' , ( event : Electron . Event , commandLine : string [ ] ) => {
632
- // Someone tried to run a second instance, open a new window
633
- // to handle it
634
-
635
- const { argv, subwindowPlease, subwindowPrefs } = getCommand ( commandLine , async ( ) => import ( 'electron' ) )
641
+ app . on (
642
+ 'second-instance' ,
643
+ ( event : Electron . Event , commandLine : string [ ] , cwd : string , additionalData : { env : string } ) => {
644
+ // Someone tried to run a second instance, open a new window
645
+ // to handle it
646
+
647
+ const { argv, subwindowPlease, subwindowPrefs } = getCommand (
648
+ commandLine ,
649
+ cwd ,
650
+ JSON . parse ( additionalData . env ) ,
651
+ async ( ) => import ( 'electron' )
652
+ )
653
+
654
+ if ( widthFromCaller ) {
655
+ subwindowPrefs . width = widthFromCaller
656
+ }
657
+ if ( heightFromCaller ) {
658
+ subwindowPrefs . height = heightFromCaller
659
+ }
636
660
637
- if ( widthFromCaller ) {
638
- subwindowPrefs . width = widthFromCaller
639
- }
640
- if ( heightFromCaller ) {
641
- subwindowPrefs . height = heightFromCaller
661
+ debug ( 'opening window for second instance' , commandLine , subwindowPlease , subwindowPrefs )
662
+ createWindow ( true , argv , subwindowPlease , subwindowPrefs )
642
663
}
643
-
644
- debug ( 'opening window for second instance' , commandLine , subwindowPlease , subwindowPrefs )
645
- createWindow ( true , argv , subwindowPlease , subwindowPrefs )
646
- } )
647
- if ( ! app . requestSingleInstanceLock ( ) ) {
664
+ )
665
+ if ( ! app . requestSingleInstanceLock ( { env : JSON . stringify ( process . env ) } ) ) {
648
666
// The primary instance of app failed to optain the lock, which means another instance of app is already running with the lock
649
667
debug ( 'exiting, since we are not the first instance' )
650
668
return app . exit ( 0 )
0 commit comments