Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"dev": "concurrently -k -n vite,electron -c blue,green \"bun run dev:vite\" \"bun run dev:electron\"",
"dev:split": "bash scripts/dev-split.sh",
"dev:vite": "vite dev",
"dev:kill": "pkill -f 'electronmon \\.' 2>/dev/null; pkill -f 'electron.*dist/main' 2>/dev/null; sleep 0.5; true",
"dev:electron": "bun run dev:kill && bun run build:main && bun run build:preload && bun run build:resources && sleep 2 && concurrently -k -n main,preload,app -c yellow,magenta,cyan \"bun run watch:main\" \"bun run watch:preload\" \"bunx electronmon .\"",
"dev:kill": "bun run scripts/dev-kill.ts",
"dev:electron": "bun run dev:kill && bun run build:main && bun run build:preload && bun run build:resources && bun run scripts/sleep.ts 2 && concurrently -k -n main,preload,app -c yellow,magenta,cyan \"bun run watch:main\" \"bun run watch:preload\" \"bunx electronmon .\"",
"build:main": "esbuild src/main/index.ts --bundle --platform=node --format=cjs --outfile=dist/main.cjs --external:electron --external:@anthropic-ai/claude-agent-sdk",
"build:preload": "esbuild src/preload/index.ts --bundle --platform=node --format=cjs --outfile=dist/preload.cjs --external:electron",
"watch:main": "esbuild src/main/index.ts --bundle --platform=node --format=cjs --outfile=dist/main.cjs --external:electron --external:@anthropic-ai/claude-agent-sdk --watch=forever",
Expand Down
24 changes: 24 additions & 0 deletions apps/electron/scripts/dev-kill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* 跨平台清理残留的 electronmon / electron 进程
* 替代 pkill(Windows 不支持)
*/
import { execSync } from 'child_process'

const isWin = process.platform === 'win32'

function kill(pattern: string): void {
try {
if (isWin) {
// Windows: taskkill 按进程名
execSync(`taskkill /F /IM ${pattern} 2>nul`, { stdio: 'ignore' })
} else {
// Unix: pkill 按模式匹配
execSync(`pkill -f '${pattern}' 2>/dev/null`, { stdio: 'ignore' })
}
} catch {
// 没有匹配进程,忽略
}
}

kill(isWin ? 'electronmon.exe' : 'electronmon \\.')
kill(isWin ? 'electron.exe' : 'electron.*dist/main')
6 changes: 6 additions & 0 deletions apps/electron/scripts/sleep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* 跨平台 sleep 命令
* 用法: bun run scripts/sleep.ts <seconds>
*/
const seconds = Number(process.argv[2]) || 2
await new Promise((resolve) => setTimeout(resolve, seconds * 1000))
6 changes: 4 additions & 2 deletions apps/electron/src/main/lib/global-shortcut-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* - 主进程:globalShortcut.register,系统级生效
*/

import { globalShortcut } from 'electron'
import { app, globalShortcut } from 'electron'
import { getSettings } from './settings-service'

/** 全局快捷键 ID → 回调映射 */
Expand Down Expand Up @@ -124,7 +124,9 @@ export function reregisterAllGlobalShortcuts(): Record<string, boolean> {
* 在 app.will-quit / before-quit 时调用。
*/
export function unregisterAllGlobalShortcuts(): void {
globalShortcut.unregisterAll()
if (app.isReady()) {
globalShortcut.unregisterAll()
}
registeredAccelerators.clear()
globalCallbacks.clear()
console.log('[全局快捷键] 已注销所有')
Expand Down