fix(stage-tamagotchi): handle app exit correctly (#1319)

This commit is contained in:
Makito
2026-03-12 23:08:19 +08:00
committed by GitHub
parent 879b92f713
commit 28db2f6e2a
+24 -5
View File
@@ -1,7 +1,8 @@
import type { FileLoggerHandle } from './app/file-logger'
import process, { env, platform } from 'node:process'
import { dirname } from 'node:path'
import { env, platform } from 'node:process'
import { fileURLToPath } from 'node:url'
import messages from '@proj-airi/i18n/locales'
@@ -201,9 +202,27 @@ app.on('window-all-closed', () => {
}
})
let appExiting = false
// Clean up server and intervals when app quits
app.on('before-quit', async () => {
emitAppBeforeQuit()
injeca.stop()
await fileLogger.close() // Ensure all logs are flushed
async function handleAppExit() {
if (appExiting)
return
appExiting = true
await Promise.all([
emitAppBeforeQuit(),
injeca.stop(),
fileLogger.close(), // Ensure all logs are flushed
])
app.exit(0)
}
process.on('SIGINT', () => handleAppExit())
app.on('before-quit', (event) => {
event.preventDefault()
handleAppExit()
})