From 84158f719dc1a724739b5e084605f2e6db4c729a Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Mon, 30 Nov 2026 15:23:15 +0800 Subject: [PATCH] fix(launcher): report game exits separately Keep successful process creation separate from exit status. Report the exit code and game log directory when the process exits abnormally. Verified by type checking and launcher build. The guarded game exit remains part of acceptance. --- .../src/main/services/launch/game-process.ts | 13 +++++++------ .../main/services/launch/launch-controller.ts | 16 ++++++++++------ .../src/main/services/launch/ordinary-launch.ts | 13 +++++++------ apps/launcher/src/renderer/src/App.tsx | 2 +- .../src/renderer/src/i18n/locales/en.json | 6 +++++- .../src/renderer/src/i18n/locales/zh-CN.json | 6 +++++- .../src/renderer/src/pages/home/home-bar.ts | 12 +++++++++--- .../src/renderer/src/shell/BottomBar.tsx | 2 +- apps/launcher/src/shared/schemas/launch.ts | 11 ++++++++++- 9 files changed, 55 insertions(+), 26 deletions(-) diff --git a/apps/launcher/src/main/services/launch/game-process.ts b/apps/launcher/src/main/services/launch/game-process.ts index 9799be2..b0a29bb 100644 --- a/apps/launcher/src/main/services/launch/game-process.ts +++ b/apps/launcher/src/main/services/launch/game-process.ts @@ -3,6 +3,7 @@ import { join } from 'node:path'; import { promisify } from 'node:util'; import { GAME_FILES } from '@wto/patcher'; import { AppError } from '@shared/errors.ts'; +import type { GameExit } from '@shared/schemas/launch.ts'; const execute = promisify(execFile); const OFFLINE_ARGUMENTS = ['-forcestart', '-nobeac', '-crashpad-disable-upload']; @@ -15,7 +16,7 @@ export async function gameProcessRunning(signal: AbortSignal): Promise export async function runGameProcess( copyPath: string, additionalArguments: readonly string[], signal: AbortSignal, onStart: () => void, -): Promise { +): Promise { if (await gameProcessRunning(signal)) throw new AppError('launch_game_running'); signal.throwIfAborted(); const child = spawn(join(copyPath, GAME_FILES.executable), [...OFFLINE_ARGUMENTS, ...additionalArguments], { @@ -24,7 +25,7 @@ export async function runGameProcess( const stop = (): void => { child.kill(); }; try { - await new Promise((resolve, reject) => { + return await new Promise((resolve, reject) => { child.once('spawn', () => { if (signal.aborted) stop(); else onStart(); @@ -34,11 +35,11 @@ export async function runGameProcess( reject(new AppError('launch_game_failed')); }); child.once('close', (code, reason) => { - if (code === 0 || signal.aborted) resolve(); - else { - console.error('[game] process exited:', code ?? reason); - reject(new AppError('launch_game_failed')); + const logFolder = join(copyPath, '.game_logs'); + if (code !== 0 && !signal.aborted) { + console.warn('[game] process exited:', code ?? reason, logFolder); } + resolve({ code, signal: reason, logFolder }); }); signal.addEventListener('abort', stop, { once: true }); }); diff --git a/apps/launcher/src/main/services/launch/launch-controller.ts b/apps/launcher/src/main/services/launch/launch-controller.ts index bf2a71b..86f1ecc 100644 --- a/apps/launcher/src/main/services/launch/launch-controller.ts +++ b/apps/launcher/src/main/services/launch/launch-controller.ts @@ -5,7 +5,7 @@ import { app, BrowserWindow, shell } from 'electron'; import { AccountStore, LOOPBACK } from '@wto/server'; import { executableVersion, GAME_FILES, isInSteamLibrary } from '@wto/patcher'; import { AppError } from '@shared/errors.ts'; -import type { LaunchState } from '@shared/schemas/launch.ts'; +import type { GameExit, LaunchState } from '@shared/schemas/launch.ts'; import { getSettings } from '../config/settings-store.ts'; import { decalCachePath } from '../install/decals.ts'; import { copyPathContains, readInstallRecord } from '../install/install-record.ts'; @@ -160,16 +160,20 @@ async function launch(job: LaunchJob): Promise { }); }); - const publish = (phase: LaunchState['phase']): void => { + const publish = (phase: LaunchState['phase'], gameExit?: GameExit): void => { if (signal.aborted) return; - update(job, { phase, port }); + update(job, { phase, port, gameExit }); if (phase === 'running' && settings.afterGameStarts === 'minimize') { for (const window of BrowserWindow.getAllWindows()) window.minimize(); } }; - if (lab) await runLab(lab, stockPath, dataPath, signal, publish); - else await runOrdinaryLaunch(copyPath, dataPath, port, settings, signal, publish); - update(job, { phase: 'ready' }); + if (lab) { + await runLab(lab, stockPath, dataPath, signal, publish); + update(job, { phase: 'ready' }); + return; + } + const gameExit = await runOrdinaryLaunch(copyPath, dataPath, port, settings, signal, publish); + update(job, { phase: 'game-exited', gameExit }); } async function readVersion(folder: string, signal: AbortSignal): Promise { diff --git a/apps/launcher/src/main/services/launch/ordinary-launch.ts b/apps/launcher/src/main/services/launch/ordinary-launch.ts index 07c5c43..1d4ebe3 100644 --- a/apps/launcher/src/main/services/launch/ordinary-launch.ts +++ b/apps/launcher/src/main/services/launch/ordinary-launch.ts @@ -4,6 +4,7 @@ import { GAME_FILES, isInSteamLibrary } from '@wto/patcher'; import { AppError } from '@shared/errors.ts'; import { parseLaunchArguments } from '@shared/launch-arguments.ts'; import type { InstallRecord } from '@shared/schemas/install.ts'; +import type { GameExit } from '@shared/schemas/launch.ts'; import type { Settings } from '@shared/schemas/settings.ts'; import { canonicalCopyPath, copyPathContains } from '../install/install-record.ts'; import { STOCK_BACKUP_FOLDER } from '../install/stock-backup.ts'; @@ -32,8 +33,8 @@ type OrdinaryPhase = 'starting-server' | 'starting-game' | 'running' | 'server-r export async function runOrdinaryLaunch( copyPath: string, dataPath: string, port: number, settings: Settings, signal: AbortSignal, - publish: (phase: OrdinaryPhase) => void, -): Promise { + publish: (phase: OrdinaryPhase, gameExit?: GameExit) => void, +): Promise { const args = parseLaunchArguments(settings.launchArguments); if (!args) throw new AppError('launch_game_failed'); publish('starting-server'); @@ -44,12 +45,12 @@ export async function runOrdinaryLaunch( publish('starting-game'); const game = runGameProcess(copyPath, args, runSignal, () => publish('running')); try { - await Promise.race([game, serverExited]); - runSignal.throwIfAborted(); - if (!settings.closeServerOnGameExit) { - publish('server-running'); + const gameExit = await Promise.race([game, serverExited]); + if (!runSignal.aborted && !settings.closeServerOnGameExit) { + publish('server-running', gameExit); if (!runSignal.aborted) await Promise.race([once(runSignal, 'abort'), serverExited]); } + return gameExit; } finally { stop.abort(); await game.catch(() => undefined); diff --git a/apps/launcher/src/renderer/src/App.tsx b/apps/launcher/src/renderer/src/App.tsx index 97724f6..f93a536 100644 --- a/apps/launcher/src/renderer/src/App.tsx +++ b/apps/launcher/src/renderer/src/App.tsx @@ -95,7 +95,7 @@ export function App({ info, initialSettings, initialCopies }: AppProps) { if (details) go({ page: 'copies', section: 'summary' }); }).catch(report); }; - const perCopyStatus = ['version-changed', 'failed', 'port-busy', 'server-exited'].includes(launch.phase); + const perCopyStatus = ['version-changed', 'failed', 'port-busy', 'server-exited', 'game-exited'].includes(launch.phase); const launchStatus: LaunchState = perCopyStatus && launch.copyId && launch.copyId !== record?.id ? { phase: 'ready' } : launch; const home = homeBar(record, launchStatus, t, wizard.start, { start: () => { ipcInvoke('launch:start').catch(report); }, diff --git a/apps/launcher/src/renderer/src/i18n/locales/en.json b/apps/launcher/src/renderer/src/i18n/locales/en.json index 44562e3..c233515 100644 --- a/apps/launcher/src/renderer/src/i18n/locales/en.json +++ b/apps/launcher/src/renderer/src/i18n/locales/en.json @@ -78,6 +78,10 @@ "running": "Game running", "runningDetail": "Local server · Port {{port}}", "server-running": "Local server running", + "game-exited": "Game exited", + "gameExitedServerRunning": "Game exited. The local server is still running.", + "exitDetail": "Exit code {{code}}. Game logs: {{path}}", + "exitCodeUnknown": "unknown", "stopping": "Stopping", "stopServer": "Close local server", "cancel": "Cancel", @@ -658,7 +662,7 @@ "launch_port_busy": "The local server port is already in use.", "launch_server_failed": "The local server could not be started. See the launcher log.", "launch_server_exited": "The local server is unavailable.", - "launch_game_failed": "The game process failed to start or exited unexpectedly. See the launcher log.", + "launch_game_failed": "The game process could not start. See the launcher log.", "settings_write_failed": "The settings could not be saved.", "folder_unreadable": "The folder cannot be read: {{path}}", "not_a_game_folder": "The selected folder is not a War Thunder installation: {{path}}", diff --git a/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json b/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json index 9b04b4a..cad1d21 100644 --- a/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json +++ b/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json @@ -78,6 +78,10 @@ "running": "游戏运行中", "runningDetail": "本地服务器 · 端口 {{port}}", "server-running": "本地服务器运行中", + "game-exited": "游戏已退出", + "gameExitedServerRunning": "游戏已退出。本地服务器仍在运行。", + "exitDetail": "退出码 {{code}}。游戏日志位于 {{path}}。", + "exitCodeUnknown": "未知", "stopping": "正在关闭", "stopServer": "关闭本地服务器", "cancel": "取消", @@ -658,7 +662,7 @@ "launch_port_busy": "本地服务器端口已被占用。", "launch_server_failed": "无法启动本地服务器。请查看启动器日志。", "launch_server_exited": "本地服务器不可用。", - "launch_game_failed": "游戏进程启动失败或意外退出。请查看启动器日志。", + "launch_game_failed": "游戏进程无法启动。请查看启动器日志。", "settings_write_failed": "无法保存设置。", "folder_unreadable": "无法读取文件夹:{{path}}", "not_a_game_folder": "所选文件夹不是战争雷霆的安装文件夹:{{path}}", diff --git a/apps/launcher/src/renderer/src/pages/home/home-bar.ts b/apps/launcher/src/renderer/src/pages/home/home-bar.ts index 4c9825b..00b3cd8 100644 --- a/apps/launcher/src/renderer/src/pages/home/home-bar.ts +++ b/apps/launcher/src/renderer/src/pages/home/home-bar.ts @@ -22,6 +22,10 @@ export function homeBar( const retry = { label: t('launch.retry'), onClick: actions.start }; const starting = { label: t('launch.starting'), disabled: true }; const progress = { value: state.filesWritten ?? 0, max: state.filesTotal || null }; + const { gameExit } = state; + const exitDetail = gameExit && gameExit.code !== 0 + ? t('launch.exitDetail', { code: gameExit.code ?? gameExit.signal ?? t('launch.exitCodeUnknown'), path: gameExit.logFolder }) + : undefined; switch (state.phase) { case 'checking': case 'building': @@ -53,12 +57,14 @@ export function homeBar( }; case 'server-running': return { - tone: 'ok', - title: t('launch.server-running'), - detail: t('launch.runningDetail', { port: state.port }), + tone: exitDetail ? 'warn' : 'ok', + title: t('launch.gameExitedServerRunning'), + detail: exitDetail ?? t('launch.runningDetail', { port: state.port }), primary: launch, secondary: { label: t('launch.stopServer'), onClick: actions.stop }, }; + case 'game-exited': + return { tone: exitDetail ? 'warn' : 'ok', title: t('launch.game-exited'), detail: exitDetail, primary: launch }; case 'port-busy': return { tone: 'bad', title: t('launch.port-busy', { port: state.port }), primary: retry }; case 'server-exited': diff --git a/apps/launcher/src/renderer/src/shell/BottomBar.tsx b/apps/launcher/src/renderer/src/shell/BottomBar.tsx index bd4372c..1d955a0 100644 --- a/apps/launcher/src/renderer/src/shell/BottomBar.tsx +++ b/apps/launcher/src/renderer/src/shell/BottomBar.tsx @@ -12,7 +12,7 @@ export function BottomBar({ model }: { readonly model: BarModel }) {
{title}
- {detail !== undefined &&
{detail}
} + {detail !== undefined &&
{detail}
}
{secondary && ( diff --git a/apps/launcher/src/shared/schemas/launch.ts b/apps/launcher/src/shared/schemas/launch.ts index 587d180..38eb723 100644 --- a/apps/launcher/src/shared/schemas/launch.ts +++ b/apps/launcher/src/shared/schemas/launch.ts @@ -1,10 +1,18 @@ import { z } from 'zod'; import { APP_ERROR_CODES } from '../errors.ts'; +const GameExitSchema = z.object({ + code: z.number().int().nullable(), + signal: z.string().nullable(), + logFolder: z.string(), +}); + +export type GameExit = z.output; + export const LaunchStateSchema = z.object({ phase: z.enum([ 'ready', 'checking', 'building', 'starting-server', 'starting-game', 'running', - 'server-running', 'stopping', 'port-busy', 'version-changed', 'server-exited', 'failed', + 'server-running', 'game-exited', 'stopping', 'port-busy', 'version-changed', 'server-exited', 'failed', ]), copyId: z.uuid().optional(), port: z.number().int().min(1).max(65535).optional(), @@ -12,6 +20,7 @@ export const LaunchStateSchema = z.object({ filesTotal: z.number().int().nonnegative().optional(), file: z.string().optional(), actualVersion: z.string().nullable().optional(), + gameExit: GameExitSchema.optional(), error: z.enum(APP_ERROR_CODES).optional(), });