2026-05-01 20:39:09 +08:00
|
|
|
import type { WebContents } from 'electron/main'
|
|
|
|
|
import { app } from 'electron/main'
|
2026-04-22 00:24:21 +08:00
|
|
|
|
|
|
|
|
function normalizeBooleanEnv(value: string | undefined): boolean | null {
|
|
|
|
|
if (!value) {
|
2026-05-01 20:39:09 +08:00
|
|
|
return null
|
2026-04-22 00:24:21 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
const normalized = value.trim().toLowerCase()
|
|
|
|
|
if (['1', 'true', 'yes', 'on'].includes(normalized)) {
|
|
|
|
|
return true
|
2026-04-22 00:24:21 +08:00
|
|
|
}
|
2026-05-01 20:39:09 +08:00
|
|
|
if (['0', 'false', 'no', 'off'].includes(normalized)) {
|
|
|
|
|
return false
|
2026-04-22 00:24:21 +08:00
|
|
|
}
|
2026-05-01 20:39:09 +08:00
|
|
|
return null
|
2026-04-22 00:24:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function shouldAutoOpenExecutionDevtools(): boolean {
|
2026-05-01 17:20:00 +08:00
|
|
|
if (app.isPackaged) {
|
2026-05-01 20:39:09 +08:00
|
|
|
return false
|
2026-05-01 17:20:00 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
const explicit = normalizeBooleanEnv(process.env.GEO_DESKTOP_EXECUTION_DEVTOOLS)
|
2026-04-22 00:24:21 +08:00
|
|
|
if (explicit !== null) {
|
2026-05-01 20:39:09 +08:00
|
|
|
return explicit
|
2026-04-22 00:24:21 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
return Boolean(process.env.ELECTRON_RENDERER_URL)
|
2026-04-22 00:24:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function shouldAutoOpenBackgroundExecutionDevtools(): boolean {
|
2026-05-01 17:20:00 +08:00
|
|
|
if (app.isPackaged) {
|
2026-05-01 20:39:09 +08:00
|
|
|
return false
|
2026-05-01 17:20:00 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
const explicit = normalizeBooleanEnv(process.env.GEO_DESKTOP_EXECUTION_DEVTOOLS)
|
2026-04-22 00:24:21 +08:00
|
|
|
if (explicit !== null) {
|
2026-05-01 20:39:09 +08:00
|
|
|
return explicit
|
2026-04-22 00:24:21 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
return false
|
2026-04-22 00:24:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function maybeOpenExecutionDevtools(
|
|
|
|
|
webContents: WebContents,
|
|
|
|
|
label: string,
|
|
|
|
|
options: { background?: boolean } = {},
|
|
|
|
|
): void {
|
|
|
|
|
const allowOpen = options.background
|
|
|
|
|
? shouldAutoOpenBackgroundExecutionDevtools()
|
2026-05-01 20:39:09 +08:00
|
|
|
: shouldAutoOpenExecutionDevtools()
|
2026-04-22 00:24:21 +08:00
|
|
|
if (!allowOpen) {
|
2026-05-01 20:39:09 +08:00
|
|
|
return
|
2026-04-22 00:24:21 +08:00
|
|
|
}
|
|
|
|
|
if (webContents.isDestroyed() || webContents.isDevToolsOpened()) {
|
2026-05-01 20:39:09 +08:00
|
|
|
return
|
2026-04-22 00:24:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2026-05-01 20:39:09 +08:00
|
|
|
webContents.openDevTools({ mode: 'detach' })
|
|
|
|
|
console.info('[desktop-devtools] opened execution devtools', { label })
|
2026-04-22 00:24:21 +08:00
|
|
|
} catch (error) {
|
2026-05-01 20:39:09 +08:00
|
|
|
console.warn('[desktop-devtools] failed to open execution devtools', { label, error })
|
2026-04-22 00:24:21 +08:00
|
|
|
}
|
|
|
|
|
}
|