From f69835b1a783e8b9f129341766185d452928ce79 Mon Sep 17 00:00:00 2001 From: wishfay Date: Tue, 16 Jun 2026 22:33:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E7=94=A8=E4=BA=8Ewindows=E8=B0=83=E8=AF=95=E5=92=8C=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E6=B5=8B=E8=AF=95=E7=9A=84=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- desktop/electron/main.ts | 22 ++++++++++++++++++++++ desktop/scripts/build-sidecars.ts | 4 +--- desktop/scripts/build-windows-x64.ps1 | 5 ++--- desktop/scripts/electron-dev.ts | 16 +++++++++++++--- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/desktop/electron/main.ts b/desktop/electron/main.ts index ecf22a0a..a0036fb1 100644 --- a/desktop/electron/main.ts +++ b/desktop/electron/main.ts @@ -377,6 +377,28 @@ async function createMainWindow() { writeWindowSmokeSnapshot(mainWindow, `did-fail-load:${errorCode}:${errorDescription}:${validatedURL}`) }) + // The default application menu (which registers the Ctrl+Shift+I / F12 + // DevTools accelerators) is replaced by a custom menu on macOS/Linux and + // nulled entirely on Windows, so those shortcuts stop working. Restore them + // in dev builds so the renderer can be debugged. F12 / Ctrl+Shift+I / + // Cmd+Opt+I toggle DevTools (opened detached so it doesn't squeeze the UI). + if (!app.isPackaged) { + mainWindow.webContents.on('before-input-event', (_e, input) => { + if (input.type !== 'keyDown') return + const key = input.key.toLowerCase() + const isToggle = + key === 'f12' || + (input.control && input.shift && key === 'i') || + (process.platform === 'darwin' && input.meta && input.alt && key === 'i') + if (!isToggle) return + if (mainWindow?.webContents.isDevToolsOpened()) { + mainWindow?.webContents.closeDevTools() + } else { + mainWindow?.webContents.openDevTools({ mode: 'detach' }) + } + }) + } + writeWindowSmokeSnapshot(mainWindow, 'after-create') await loadRendererEntry(mainWindow) diff --git a/desktop/scripts/build-sidecars.ts b/desktop/scripts/build-sidecars.ts index 82f477a4..73ba807e 100644 --- a/desktop/scripts/build-sidecars.ts +++ b/desktop/scripts/build-sidecars.ts @@ -68,9 +68,7 @@ function mapTargetTripleToBun(triple: string) { case 'x86_64-apple-darwin': return 'bun-darwin-x64' case 'x86_64-pc-windows-msvc': - // Prefer baseline on Windows x64 so older CPUs do not crash before the - // desktop app can even start the local sidecar process. - return 'bun-windows-x64-baseline' + return 'bun-windows-x64' case 'aarch64-pc-windows-msvc': return 'bun-windows-arm64' case 'x86_64-unknown-linux-gnu': diff --git a/desktop/scripts/build-windows-x64.ps1 b/desktop/scripts/build-windows-x64.ps1 index 5f4029bb..8e4dc124 100644 --- a/desktop/scripts/build-windows-x64.ps1 +++ b/desktop/scripts/build-windows-x64.ps1 @@ -149,9 +149,8 @@ try { } $args = @('electron-builder', '--win', 'nsis', '--x64', '--publish', 'never') - $remainingArgs = @($BuilderArgs) - if ($remainingArgs.Count -gt 0) { - $args += $remainingArgs + if ($BuilderArgs -and $BuilderArgs.Count -gt 0) { + $args += $BuilderArgs } Write-Step 'Packaging Electron app...' diff --git a/desktop/scripts/electron-dev.ts b/desktop/scripts/electron-dev.ts index 50e9fcf5..7f7731ce 100644 --- a/desktop/scripts/electron-dev.ts +++ b/desktop/scripts/electron-dev.ts @@ -1,3 +1,5 @@ +import path from 'node:path' + export const DEFAULT_RENDERER_URL = 'http://localhost:1420' export const LOCAL_NO_PROXY_ENTRIES = ['localhost', '127.0.0.1', '::1'] @@ -37,13 +39,21 @@ async function waitForRenderer(rendererUrl: string) { } async function main() { - const desktopRoot = new URL('..', import.meta.url).pathname + // import.meta.dirname resolves to a native OS path. The previous + // `new URL('..', import.meta.url).pathname` produced a malformed cwd on + // Windows (e.g. `/D:/.../desktop/`) which made Bun.spawn fail with ENOENT. + const desktopRoot = path.resolve(import.meta.dirname, '..') const childEnv = createElectronDevEnv() const rendererUrl = childEnv.ELECTRON_RENDERER_URL process.env.NO_PROXY = childEnv.NO_PROXY process.env.no_proxy = childEnv.no_proxy - const vite = Bun.spawn(['bun', 'run', 'dev'], { + // Use process.execPath (absolute path to the running bun) instead of the + // bare 'bun' command. Bun.spawn resolves bare names via PATH, which is + // unreliable on Windows when bun is reached through an npm .cmd shim that + // the child process does not inherit — it fails with ENOENT on 'bun'. + // process.execPath always resolves because it is the currently running binary. + const vite = Bun.spawn([process.execPath, 'run', 'dev'], { cwd: desktopRoot, env: childEnv, stdout: 'inherit', @@ -65,7 +75,7 @@ async function main() { await waitForRenderer(rendererUrl) - const electron = Bun.spawn(['bunx', 'electron', './electron-dist/main.cjs'], { + const electron = Bun.spawn([process.execPath, 'x', 'electron', './electron-dist/main.cjs'], { cwd: desktopRoot, env: childEnv, stdout: 'inherit',