162abdc97c
- Add Prettier 3 with prettier-plugin-organize-imports (sorts/removes unused imports) - Add ESLint 10 flat config with typescript-eslint + eslint-plugin-vue + eslint-config-prettier - Add root scripts: format, format:check, lint, lint:fix - Reformat 257 files across admin-web, ops-web, desktop-client, packages - Remove unused locals/exports flagged by --noUnusedLocals/--noUnusedParameters - Fix duplicate localTabLabel key, surrogate-pair regex u-flag, NBSP literal in regex - Skip server/ (Go) and apps/browser-extension/ (deprecated per ADR) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
67 lines
1.6 KiB
TypeScript
67 lines
1.6 KiB
TypeScript
import type { WebContents } from 'electron/main'
|
|
import { app } from 'electron/main'
|
|
|
|
function normalizeBooleanEnv(value: string | undefined): boolean | null {
|
|
if (!value) {
|
|
return null
|
|
}
|
|
|
|
const normalized = value.trim().toLowerCase()
|
|
if (['1', 'true', 'yes', 'on'].includes(normalized)) {
|
|
return true
|
|
}
|
|
if (['0', 'false', 'no', 'off'].includes(normalized)) {
|
|
return false
|
|
}
|
|
return null
|
|
}
|
|
|
|
export function shouldAutoOpenExecutionDevtools(): boolean {
|
|
if (app.isPackaged) {
|
|
return false
|
|
}
|
|
|
|
const explicit = normalizeBooleanEnv(process.env.GEO_DESKTOP_EXECUTION_DEVTOOLS)
|
|
if (explicit !== null) {
|
|
return explicit
|
|
}
|
|
|
|
return Boolean(process.env.ELECTRON_RENDERER_URL)
|
|
}
|
|
|
|
export function shouldAutoOpenBackgroundExecutionDevtools(): boolean {
|
|
if (app.isPackaged) {
|
|
return false
|
|
}
|
|
|
|
const explicit = normalizeBooleanEnv(process.env.GEO_DESKTOP_EXECUTION_DEVTOOLS)
|
|
if (explicit !== null) {
|
|
return explicit
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
export function maybeOpenExecutionDevtools(
|
|
webContents: WebContents,
|
|
label: string,
|
|
options: { background?: boolean } = {},
|
|
): void {
|
|
const allowOpen = options.background
|
|
? shouldAutoOpenBackgroundExecutionDevtools()
|
|
: shouldAutoOpenExecutionDevtools()
|
|
if (!allowOpen) {
|
|
return
|
|
}
|
|
if (webContents.isDestroyed() || webContents.isDevToolsOpened()) {
|
|
return
|
|
}
|
|
|
|
try {
|
|
webContents.openDevTools({ mode: 'detach' })
|
|
console.info('[desktop-devtools] opened execution devtools', { label })
|
|
} catch (error) {
|
|
console.warn('[desktop-devtools] failed to open execution devtools', { label, error })
|
|
}
|
|
}
|