mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-03-30 05:43:55 +00:00
electron: more robust sidecar kill handling (#18742)
This commit is contained in:
parent
0f5626d2e4
commit
4c27e7fc64
@ -35,6 +35,7 @@ export type CommandEvent =
|
|||||||
export type SqliteMigrationProgress = { type: "InProgress"; value: number } | { type: "Done" }
|
export type SqliteMigrationProgress = { type: "InProgress"; value: number } | { type: "Done" }
|
||||||
|
|
||||||
export type CommandChild = {
|
export type CommandChild = {
|
||||||
|
pid: number | undefined
|
||||||
kill: () => void
|
kill: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,7 +192,7 @@ export function spawnCommand(args: string, extraEnv: Record<string, string>) {
|
|||||||
treeKill(child.pid)
|
treeKill(child.pid)
|
||||||
}
|
}
|
||||||
|
|
||||||
return { events, child: { kill }, exit }
|
return { events, child: { pid: child.pid, kill }, exit }
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleSqliteProgress(events: EventEmitter, line: string) {
|
function handleSqliteProgress(events: EventEmitter, line: string) {
|
||||||
|
|||||||
@ -81,6 +81,17 @@ function setupApp() {
|
|||||||
killSidecar()
|
killSidecar()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.on("will-quit", () => {
|
||||||
|
killSidecar()
|
||||||
|
})
|
||||||
|
|
||||||
|
for (const signal of ["SIGINT", "SIGTERM"] as const) {
|
||||||
|
process.on(signal, () => {
|
||||||
|
killSidecar()
|
||||||
|
app.exit(0)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
void app.whenReady().then(async () => {
|
void app.whenReady().then(async () => {
|
||||||
// migrate()
|
// migrate()
|
||||||
app.setAsDefaultProtocolClient("opencode")
|
app.setAsDefaultProtocolClient("opencode")
|
||||||
@ -234,8 +245,15 @@ registerIpcHandlers({
|
|||||||
|
|
||||||
function killSidecar() {
|
function killSidecar() {
|
||||||
if (!sidecar) return
|
if (!sidecar) return
|
||||||
|
const pid = sidecar.pid
|
||||||
sidecar.kill()
|
sidecar.kill()
|
||||||
sidecar = null
|
sidecar = null
|
||||||
|
// tree-kill is async; also send process group signal as immediate fallback
|
||||||
|
if (pid && process.platform !== "win32") {
|
||||||
|
try {
|
||||||
|
process.kill(-pid, "SIGTERM")
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureLoopbackNoProxy() {
|
function ensureLoopbackNoProxy() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user