fix(cli): allow closing debug console after auto-open via flicker (#18795)

This commit is contained in:
Sandy Tao
2026-02-10 21:37:23 -08:00
committed by GitHub
parent 0d034b8c18
commit 2af5a3a01e
3 changed files with 128 additions and 22 deletions

View File

@@ -210,6 +210,35 @@ async function startDevToolsServerImpl(config: Config): Promise<string> {
return url;
}
/**
* Handles the F12 key toggle for the DevTools panel.
* Starts the DevTools server, attempts to open the browser,
* and always calls the toggle callback regardless of the outcome.
*/
export async function toggleDevToolsPanel(
config: Config,
toggle: () => void,
setOpen: () => void,
): Promise<void> {
try {
const { openBrowserSecurely, shouldLaunchBrowser } = await import(
'@google/gemini-cli-core'
);
const url = await startDevToolsServer(config);
if (shouldLaunchBrowser()) {
try {
await openBrowserSecurely(url);
} catch (e) {
debugLogger.warn('Failed to open browser securely:', e);
}
}
toggle();
} catch (e) {
setOpen();
debugLogger.error('Failed to start DevTools server:', e);
}
}
/** Reset module-level state — test only. */
export function resetForTesting() {
promotionAttempts = 0;