Skip to content

Commit a7039f2

Browse files
committedJan 12, 2023
fix: second popup window does now execute desired command line
1 parent 16ac9a7 commit a7039f2

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed
 

‎packages/core/src/main/headless.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,15 @@ export function initHeadless(argv: string[], force = false, isRunningHeadless =
344344
// craft a createWindow that has a first argument of true, which will indicate `noHeadless`
345345
// because this will be called for cases where we want a headless -> GUI transition
346346
const { createWindow: createElectronWindow } = await import('./spawn-electron')
347-
return createElectronWindow(true, executeThisArgvPlease, subwindowPlease, subwindowPrefs, false, true)
347+
return createElectronWindow(
348+
true,
349+
process.env,
350+
executeThisArgvPlease,
351+
subwindowPlease,
352+
subwindowPrefs,
353+
false,
354+
true
355+
)
348356
}
349357
},
350358
argv,

‎packages/core/src/main/spawn-electron.ts

+22-16
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function getPositionForPopup({ screen, BrowserWindow }: { screen: Screen; Browse
126126
/** Special purpose createWindow that accepts only an argv */
127127
function createWindowWithArgv(executeThisArgvPlease?: string[]) {
128128
// eslint-disable-next-line @typescript-eslint/no-use-before-define
129-
createWindow(true, executeThisArgvPlease)
129+
createWindow(true, process.env, executeThisArgvPlease)
130130
}
131131

132132
function getClientProductName(): Promise<string> {
@@ -144,6 +144,7 @@ function getClientStyles(): Promise<BrowserWindowConstructorOptions & { defaultT
144144
/** Open a new Electron window */
145145
export async function createWindow(
146146
noHeadless = false,
147+
env: Record<any, any>,
147148
executeThisArgvPlease?: string | string[],
148149
subwindowPlease?: boolean,
149150
subwindowPrefs?: ISubwindowPrefs,
@@ -479,6 +480,7 @@ export async function createWindow(
479480
case 'new-window':
480481
createWindow(
481482
true,
483+
env,
482484
message.argv,
483485
undefined,
484486
{
@@ -492,7 +494,7 @@ export async function createWindow(
492494
)
493495
break
494496
case 'open-graphical-shell':
495-
createWindow(true)
497+
createWindow(true, env)
496498
break
497499
case 'enlarge-window':
498500
mainWindow.setContentSize(1400, 1050, true)
@@ -533,7 +535,7 @@ export async function createWindow(
533535
const returnValue = await mod[message.main || 'main'](
534536
message.args,
535537
event.sender,
536-
(argv: string | string[], prefs?: ISubwindowPrefs) => createWindow(true, argv, undefined, prefs)
538+
(argv: string | string[], prefs?: ISubwindowPrefs) => createWindow(true, env, argv, undefined, prefs)
537539
)
538540
debug('invoke got returnValue', returnValue)
539541

@@ -607,10 +609,8 @@ export const getCommand = (
607609

608610
// re: argv.length === 0, this should happen for double-click launches
609611
const isShell =
610-
!process.env.KUI_POPUP &&
611-
(argv.length === 0 ||
612-
argv.find(_ => _ === 'shell') ||
613-
(process.env.RUNNING_SHELL_TEST && !process.env.KUI_TEE_TO_FILE))
612+
!env.KUI_POPUP &&
613+
(argv.length === 0 || argv.find(_ => _ === 'shell') || (env.RUNNING_SHELL_TEST && !env.KUI_TEE_TO_FILE))
614614

615615
debug('isShell', argv, isShell)
616616

@@ -628,12 +628,12 @@ export const getCommand = (
628628
argv = ['shell']
629629
subwindowPlease = false
630630
subwindowPrefs = { cwd, env }
631-
} else if (process.env.KUI_POPUP) {
632-
argv = JSON.parse(process.env.KUI_POPUP)
631+
} else if (env.KUI_POPUP) {
632+
argv = JSON.parse(env.KUI_POPUP)
633633
subwindowPrefs = { cwd, env }
634634
}
635635

636-
if (process.env.KUI_POPUP_WINDOW_RESIZE) {
636+
if (env.KUI_POPUP_WINDOW_RESIZE) {
637637
subwindowPrefs = {
638638
cwd,
639639
env,
@@ -727,11 +727,12 @@ export async function initElectron(
727727
// Someone tried to run a second instance, open a new window
728728
// to handle it
729729

730+
const env = !additionalData.env ? process.env : JSON.parse(additionalData.env)
730731
const {
731732
argv,
732733
subwindowPlease,
733734
subwindowPrefs: defaultSubwindowPrefs
734-
} = getCommand(commandLine, cwd, JSON.parse(additionalData.env), async () => import('electron'))
735+
} = getCommand(commandLine, cwd, env, async () => import('electron'))
735736

736737
const mySubwindowPrefs = additionalData.subwindowPrefs || defaultSubwindowPrefs
737738
if (!mySubwindowPrefs.width && widthFromCaller) {
@@ -741,8 +742,8 @@ export async function initElectron(
741742
mySubwindowPrefs.height = heightFromCaller
742743
}
743744

744-
debug('opening window for second instance', commandLine, subwindowPlease, mySubwindowPrefs)
745-
createWindow(true, argv, subwindowPlease, mySubwindowPrefs)
745+
debug('opening window for second instance', commandLine, subwindowPlease, mySubwindowPrefs, additionalData)
746+
createWindow(true, env, argv, subwindowPlease, mySubwindowPrefs)
746747
}
747748
)
748749

@@ -755,7 +756,12 @@ export async function initElectron(
755756
env: JSON.stringify(process.env),
756757
subwindowPrefs: !subwindowPrefs
757758
? undefined
758-
: { width: subwindowPrefs.width, height: subwindowPrefs.height, title: subwindowPrefs.title }
759+
: {
760+
width: subwindowPrefs.width,
761+
height: subwindowPrefs.height,
762+
title: subwindowPrefs.title,
763+
fullscreen: subwindowPrefs.fullscreen
764+
}
759765
}
760766

761767
if (!app.requestSingleInstanceLock(additionalData)) {
@@ -776,7 +782,7 @@ export async function initElectron(
776782
// Some APIs can only be used after this event occurs.
777783
app.once('ready', () => {
778784
debug('opening primary window', command)
779-
createWindow(true, command.length > 0 && command, subwindowPlease, subwindowPrefs)
785+
createWindow(true, process.env, command.length > 0 && command, subwindowPlease, subwindowPrefs)
780786
})
781787

782788
// Quit when all windows are closed.
@@ -795,7 +801,7 @@ export async function initElectron(
795801
// On OS X it's common to re-create a window in the app when the
796802
// dock icon is clicked and there are no other windows open.
797803
if (nWindows === 0) {
798-
createWindow()
804+
createWindow(false, process.env)
799805
}
800806
})
801807
}

0 commit comments

Comments
 (0)
Please sign in to comment.