Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 27b6d2f

Browse files
starpitk8s-ci-robot
authored andcommitted
feat(packages/core): restore support for opening a popup window from headless mode
1 parent f8e9100 commit 27b6d2f

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

packages/core/src/main/headless-pretty-print.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,14 @@ const colorMap: Record<string, ColorFunction> = {
6767
}
6868

6969
let graphicalShellIsOpen = false
70+
/** @return whether the state has changed as a result of this call */
7071
export const setGraphicalShellIsOpen = () => {
71-
graphicalShellIsOpen = true
72+
if (!graphicalShellIsOpen) {
73+
graphicalShellIsOpen = true
74+
return true
75+
} else {
76+
return false
77+
}
7278
}
7379

7480
/**

packages/core/src/main/headless.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ export const createWindow = async (argv: string[], subwindowPlease: boolean, sub
177177
try {
178178
graphicalShellIsOpen = true
179179
const { setGraphicalShellIsOpen } = await import('./headless-pretty-print')
180-
setGraphicalShellIsOpen()
180+
if (!setGraphicalShellIsOpen()) {
181+
debug('probably a bug somewhere; detected loop in opening window from headless mode')
182+
return
183+
}
181184

182185
const commandLine = argv
183186
if (commandContext) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,8 @@ export async function initElectron(
559559
// DEBUG=* or DEBUG=main
560560
const env = Object.assign({}, process.env, windowOptions)
561561
delete env.KUI_HEADLESS
562+
delete env.ELECTRON_RUN_AS_NODE
563+
562564
const child = spawn(Electron.toString(), args, {
563565
stdio: debug.enabled ? 'inherit' : 'ignore',
564566
env,

packages/core/src/repl/exec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,21 @@ class InProcessExecutor implements Executor {
352352
return err
353353
}
354354

355+
// if we don't have a head (yet), but this command requires one,
356+
// then ask for a head and try again. note that we ignore this
357+
// needsUI constraint if the user is asking for help
358+
if (
359+
isHeadless() &&
360+
!parsedOptions.cli &&
361+
((process.env.DEFAULT_TO_UI && !parsedOptions.cli) || (evaluator.options && evaluator.options.needsUI))
362+
) {
363+
import('../main/headless').then(({ createWindow }) =>
364+
createWindow(argv, evaluator.options.fullscreen, evaluator.options)
365+
)
366+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
367+
return (true as any) as T
368+
}
369+
355370
const execUUID = execOptions.execUUID || uuid()
356371
execOptions.execUUID = execUUID
357372
const evaluatorOptions = evaluator.options

0 commit comments

Comments
 (0)