From 28db2f6e2a928e77fee76d71cf69eebc46764133 Mon Sep 17 00:00:00 2001 From: Makito Date: Fri, 13 Mar 2026 00:08:19 +0900 Subject: [PATCH] fix(stage-tamagotchi): handle app exit correctly (#1319) --- apps/stage-tamagotchi/src/main/index.ts | 29 ++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/apps/stage-tamagotchi/src/main/index.ts b/apps/stage-tamagotchi/src/main/index.ts index 40167bc55..3f1a19ce0 100644 --- a/apps/stage-tamagotchi/src/main/index.ts +++ b/apps/stage-tamagotchi/src/main/index.ts @@ -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() })