mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-26 15:03:34 +08:00
更新了一些用于windows调试和本地测试的代码。
This commit is contained in:
parent
f793895fb3
commit
f69835b1a7
@ -377,6 +377,28 @@ async function createMainWindow() {
|
|||||||
writeWindowSmokeSnapshot(mainWindow, `did-fail-load:${errorCode}:${errorDescription}:${validatedURL}`)
|
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')
|
writeWindowSmokeSnapshot(mainWindow, 'after-create')
|
||||||
|
|
||||||
await loadRendererEntry(mainWindow)
|
await loadRendererEntry(mainWindow)
|
||||||
|
|||||||
@ -68,9 +68,7 @@ function mapTargetTripleToBun(triple: string) {
|
|||||||
case 'x86_64-apple-darwin':
|
case 'x86_64-apple-darwin':
|
||||||
return 'bun-darwin-x64'
|
return 'bun-darwin-x64'
|
||||||
case 'x86_64-pc-windows-msvc':
|
case 'x86_64-pc-windows-msvc':
|
||||||
// Prefer baseline on Windows x64 so older CPUs do not crash before the
|
return 'bun-windows-x64'
|
||||||
// desktop app can even start the local sidecar process.
|
|
||||||
return 'bun-windows-x64-baseline'
|
|
||||||
case 'aarch64-pc-windows-msvc':
|
case 'aarch64-pc-windows-msvc':
|
||||||
return 'bun-windows-arm64'
|
return 'bun-windows-arm64'
|
||||||
case 'x86_64-unknown-linux-gnu':
|
case 'x86_64-unknown-linux-gnu':
|
||||||
|
|||||||
@ -149,9 +149,8 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$args = @('electron-builder', '--win', 'nsis', '--x64', '--publish', 'never')
|
$args = @('electron-builder', '--win', 'nsis', '--x64', '--publish', 'never')
|
||||||
$remainingArgs = @($BuilderArgs)
|
if ($BuilderArgs -and $BuilderArgs.Count -gt 0) {
|
||||||
if ($remainingArgs.Count -gt 0) {
|
$args += $BuilderArgs
|
||||||
$args += $remainingArgs
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Step 'Packaging Electron app...'
|
Write-Step 'Packaging Electron app...'
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
import path from 'node:path'
|
||||||
|
|
||||||
export const DEFAULT_RENDERER_URL = 'http://localhost:1420'
|
export const DEFAULT_RENDERER_URL = 'http://localhost:1420'
|
||||||
export const LOCAL_NO_PROXY_ENTRIES = ['localhost', '127.0.0.1', '::1']
|
export const LOCAL_NO_PROXY_ENTRIES = ['localhost', '127.0.0.1', '::1']
|
||||||
|
|
||||||
@ -37,13 +39,21 @@ async function waitForRenderer(rendererUrl: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
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 childEnv = createElectronDevEnv()
|
||||||
const rendererUrl = childEnv.ELECTRON_RENDERER_URL
|
const rendererUrl = childEnv.ELECTRON_RENDERER_URL
|
||||||
process.env.NO_PROXY = childEnv.NO_PROXY
|
process.env.NO_PROXY = childEnv.NO_PROXY
|
||||||
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,
|
cwd: desktopRoot,
|
||||||
env: childEnv,
|
env: childEnv,
|
||||||
stdout: 'inherit',
|
stdout: 'inherit',
|
||||||
@ -65,7 +75,7 @@ async function main() {
|
|||||||
|
|
||||||
await waitForRenderer(rendererUrl)
|
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,
|
cwd: desktopRoot,
|
||||||
env: childEnv,
|
env: childEnv,
|
||||||
stdout: 'inherit',
|
stdout: 'inherit',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user