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.
This commit is contained in:
1 parent
b3a30c0fd9
commit
84158f719d
9 files changed
+55
-26
No files matched your search
@@ -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<boolean>
|
||||
|
||||
export async function runGameProcess(
|
||||
copyPath: string, additionalArguments: readonly string[], signal: AbortSignal, onStart: () => void,
|
||||
): Promise<void> {
|
||||
): Promise<GameExit> {
|
||||
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<void>((resolve, reject) => {
|
||||
return await new Promise<GameExit>((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 });
|
||||
});
|
||||
|
||||
@@ -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<void> {
|
||||
});
|
||||
});
|
||||
|
||||
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<string | null> {
|
||||
|
||||
@@ -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<void> {
|
||||
publish: (phase: OrdinaryPhase, gameExit?: GameExit) => void,
|
||||
): Promise<GameExit> {
|
||||
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);
|
||||
|
||||
@@ -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); },
|
||||
|
||||
@@ -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}}",
|
||||
|
||||
@@ -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}}",
|
||||
|
||||
@@ -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':
|
||||
|
||||
@@ -12,7 +12,7 @@ export function BottomBar({ model }: { readonly model: BarModel }) {
|
||||
<span className={`status-icon status-icon-${tone}`} aria-hidden="true">{TONE_MARKS[tone]}</span>
|
||||
<div className="status-text">
|
||||
<div className="status-title">{title}</div>
|
||||
{detail !== undefined && <div className="status-detail">{detail}</div>}
|
||||
{detail !== undefined && <div className="status-detail" title={typeof detail === 'string' ? detail : undefined}>{detail}</div>}
|
||||
</div>
|
||||
</div>
|
||||
{secondary && (
|
||||
|
||||
@@ -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<typeof GameExitSchema>;
|
||||
|
||||
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(),
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user