feat(launcher): launch the game through the guarded lab

This commit is contained in:
N0VAN0M4LY committed 2026-11-29 15:02:39 +08:00
1 parent d633280e23
commit e41b73aaa3
25 files changed
+920 -23

No files matched your search

+34 -7
View File
@@ -2,10 +2,11 @@ import { useEffect, useState, type ReactNode } from 'react';
import { useTranslation } from 'react-i18next';
import type { IpcOutput } from '@shared/ipc/contract.ts';
import type { InstallRecord } from '@shared/schemas/install.ts';
import type { LaunchState } from '@shared/schemas/launch.ts';
import type { Settings } from '@shared/schemas/settings.ts';
import { Sheet } from './components/Sheet.tsx';
import { applyLanguage, resolveLanguage } from './i18n/index.ts';
import { ipcOn } from './ipc.ts';
import { ipcInvoke, ipcOn } from './ipc.ts';
import { AboutPage } from './pages/about/AboutPage.tsx';
import { CopySummary } from './pages/copies/CopySummary.tsx';
import { FeatureStatus } from './pages/copies/FeatureStatus.tsx';
@@ -17,8 +18,10 @@ import { useInstallWizard } from './pages/install/useInstallWizard.ts';
import { WizardMain } from './pages/install/WizardMain.tsx';
import { WizardSide } from './pages/install/WizardSide.tsx';
import { wizardBar } from './pages/install/wizard-bar.ts';
import { DeveloperSettings } from './pages/settings/DeveloperSettings.tsx';
import { DiagnosticsSettings } from './pages/settings/DiagnosticsSettings.tsx';
import { GeneralSettings } from './pages/settings/GeneralSettings.tsx';
import { LaunchSettings } from './pages/settings/LaunchSettings.tsx';
import { Background } from './shell/Background.tsx';
import { BottomBar } from './shell/BottomBar.tsx';
import type { BarModel } from './shell/bar-model.ts';
@@ -52,6 +55,7 @@ export function App({ info, initialSettings, initialRecord, defaultDataPath }: A
const { message, report } = useErrorMessage();
const [settings, setSettings] = useState(initialSettings);
const [record, setRecord] = useState(initialRecord);
const [launch, setLaunch] = useState<LaunchState>({ phase: 'ready' });
const [route, setRoute] = useState<Route>(START_ROUTE);
const supported = info.supportedGameVersions;
@@ -68,8 +72,25 @@ export function App({ info, initialSettings, initialRecord, defaultDataPath }: A
useEffect(() => ipcOn('event:settings-changed', setSettings), []);
useEffect(() => applyLanguage(resolveLanguage(settings.language, info.systemLocale)), [settings.language, info.systemLocale]);
useEffect(() => {
let mounted = true;
let receivedEvent = false;
const dispose = ipcOn('event:launch-state', (state) => {
receivedEvent = true;
setLaunch(state);
});
ipcInvoke('launch:getState').then((state) => {
if (mounted && !receivedEvent) setLaunch(state);
}).catch(report);
return () => { mounted = false; dispose(); };
}, [report]);
const go = (to: Destination): void => setRoute((current) => navigate(current, to));
const home = homeBar(record, t, wizard.start);
const home = homeBar(record, launch, t, wizard.start, {
start: () => { ipcInvoke('launch:start').catch(report); },
stop: () => { ipcInvoke('launch:stop').catch(report); },
checkVersion: () => go({ page: 'copies', section: 'features' }),
});
const view = ((): View => {
if (wizard.active) {
@@ -90,14 +111,20 @@ export function App({ info, initialSettings, initialRecord, defaultDataPath }: A
};
case 'about':
return { side: homeSide, main: <AboutPage launcherVersion={info.version} supportedVersions={supported} />, bar: home };
case 'settings':
case 'settings': {
const sections = SETTINGS_SECTIONS.filter((section) => info.development || section !== 'dev');
const content = {
general: <GeneralSettings settings={settings} pictures={backgrounds.pictures} onError={report} />,
launch: <LaunchSettings onError={report} />,
diag: <DiagnosticsSettings onError={report} serverRunning={launch.phase === 'running'} />,
dev: <DeveloperSettings settings={settings} onError={report} />,
};
return {
side: <SubNav sections={SETTINGS_SECTIONS} active={route.settings} label={(section) => t(`settings.sections.${section}`)} onSelect={(section) => go({ page: 'settings', section })} />,
main: route.settings === 'diag'
? <DiagnosticsSettings onError={report} />
: <GeneralSettings settings={settings} pictures={backgrounds.pictures} onError={report} />,
side: <SubNav sections={sections} active={route.settings} label={(section) => t(`settings.sections.${section}`)} onSelect={(section) => go({ page: 'settings', section })} />,
main: content[route.settings],
bar: home,
};
}
case 'copies': {
const side = (
<>
@@ -62,9 +62,27 @@
"install": "Install",
"ready": "Ready",
"readyMissing": "Ready · {{count}} features unavailable",
"readyDetail": "Game {{version}} · Launch unavailable",
"readyDetail": "Game {{version}}",
"launch": "Launch"
},
"launch": {
"checking": "Checking the game copy",
"building": "Generating game files",
"starting-server": "Starting local server",
"starting-game": "Starting game",
"starting": "Starting…",
"running": "Game running",
"runningDetail": "Local server · Port {{port}}",
"stopping": "Stopping game",
"cancel": "Cancel",
"stop": "End game",
"retry": "Retry",
"check": "Check",
"version-changed": "The copy version has changed",
"versionDetail": "Game version {{version}}",
"port-busy": "Port {{port}} is already in use",
"server-exited": "The local server exited unexpectedly"
},
"folder": {
"none": "Not selected",
"choose": "Browse…",
@@ -199,8 +217,33 @@
"settings": {
"sections": {
"general": "General",
"launch": "Launch",
"dev": "Developer",
"diag": "Diagnostics"
},
"windowClose": "When closing the window",
"windowQuit": "Quit launcher",
"windowTray": "Minimize to system tray",
"afterGameStarts": "When the game starts",
"windowMinimize": "Minimize launcher",
"windowKeep": "Keep window open",
"launch": {
"port": "Local server port",
"portHint": "Port set by the installed lab automation",
"exit": "When the game exits",
"exitHint": "Isolated launch",
"automatic": "Close local server"
},
"developer": {
"mode": "Developer mode",
"modeHint": "Launches the lab copy under the wto-lab Windows account",
"enabled": "Enabled",
"stock": "Stock backup",
"stockHint": "Defaults to the selected copy’s stock backup",
"data": "Lab data folder",
"dataHint": "Defaults to the selected copy’s data folder",
"reset": "Restore default"
},
"diagnostics": {
"logs": "Logs",
"logsHint": "Logs recorded by the launcher",
@@ -208,7 +251,9 @@
"export": "Export diagnostics",
"exportHint": "Save logs, settings and the installation record to a ZIP file",
"save": "Export…",
"saved": "Diagnostics saved to {{path}}."
"saved": "Diagnostics saved to {{path}}.",
"serverStatus": "Local server status",
"openStatus": "Open in browser"
},
"language": "Language",
"languageHint": "Display language of the launcher"
@@ -281,6 +326,18 @@
"internal_error": "An internal launcher error occurred.",
"logs_folder_open_failed": "The launcher log folder could not be opened.",
"diagnostics_export_failed": "The diagnostics archive could not be saved.",
"launch_no_copy": "A game copy must be installed before launching.",
"launch_busy": "A launch is already in progress.",
"launch_lab_required": "Enable developer mode to launch through the isolated lab.",
"launch_lab_missing": "The isolated lab automation could not be loaded.",
"launch_lab_version": "The lab copy and the stock backup must use the same game version.",
"launch_lab_failed": "The isolated launch failed. See the launcher log.",
"launch_game_running": "Another game process is running.",
"launch_copy_in_steam": "The launch requires a separate copy and data folder outside Steam.",
"launch_build_failed": "The game files could not be generated.",
"launch_build_unavailable": "The build found unavailable patches that require review.",
"launch_port_busy": "The local server port is already in use.",
"launch_server_exited": "The local server is unavailable.",
"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}}",
@@ -62,9 +62,27 @@
"install": "安装",
"ready": "就绪",
"readyMissing": "就绪 · {{count}} 项功能不可用",
"readyDetail": "游戏 {{version}} · 启动暂不可用",
"readyDetail": "游戏 {{version}}",
"launch": "启动"
},
"launch": {
"checking": "正在检查副本",
"building": "正在生成游戏文件",
"starting-server": "正在启动本地服务器",
"starting-game": "正在启动游戏",
"starting": "启动中…",
"running": "游戏运行中",
"runningDetail": "本地服务器 · 端口 {{port}}",
"stopping": "正在结束游戏",
"cancel": "取消",
"stop": "结束游戏",
"retry": "重试",
"check": "检查",
"version-changed": "副本版本已变更",
"versionDetail": "游戏版本 {{version}}",
"port-busy": "端口 {{port}} 已被占用",
"server-exited": "本地服务器意外退出"
},
"folder": {
"none": "未选择",
"choose": "浏览…",
@@ -199,8 +217,33 @@
"settings": {
"sections": {
"general": "常规",
"launch": "启动",
"dev": "开发者",
"diag": "诊断"
},
"windowClose": "关闭窗口时",
"windowQuit": "退出启动器",
"windowTray": "最小化到系统托盘",
"afterGameStarts": "游戏启动后",
"windowMinimize": "最小化启动器",
"windowKeep": "保持窗口",
"launch": {
"port": "本地服务器端口",
"portHint": "使用已安装实验自动化的端口设置",
"exit": "游戏退出后",
"exitHint": "隔离启动",
"automatic": "关闭本地服务器"
},
"developer": {
"mode": "开发模式",
"modeHint": "以 wto-lab 用户身份启动实验副本",
"enabled": "启用",
"stock": "原版文件备份",
"stockHint": "默认使用当前副本的原版文件备份",
"data": "实验数据目录",
"dataHint": "默认使用当前副本的数据目录",
"reset": "恢复默认"
},
"diagnostics": {
"logs": "日志",
"logsHint": "启动器运行日志",
@@ -208,7 +251,9 @@
"export": "导出诊断信息",
"exportHint": "导出包含日志、设置和安装记录的 ZIP 文件",
"save": "导出…",
"saved": "诊断信息已保存到 {{path}}。"
"saved": "诊断信息已保存到 {{path}}。",
"serverStatus": "本地服务器状态页",
"openStatus": "在浏览器中打开"
},
"language": "语言",
"languageHint": "启动器界面的显示语言"
@@ -281,6 +326,18 @@
"internal_error": "启动器内部错误。",
"logs_folder_open_failed": "无法打开启动器日志文件夹。",
"diagnostics_export_failed": "无法保存诊断信息。",
"launch_no_copy": "启动前需要安装游戏副本。",
"launch_busy": "启动流程正在运行。",
"launch_lab_required": "请启用开发模式以通过隔离实验副本启动。",
"launch_lab_missing": "无法读取隔离实验自动化配置。",
"launch_lab_version": "实验副本和原版文件备份必须使用同一游戏版本。",
"launch_lab_failed": "隔离启动失败。请查看启动器日志。",
"launch_game_running": "已有游戏进程在运行。",
"launch_copy_in_steam": "启动需使用 Steam 目录外的副本和数据目录。",
"launch_build_failed": "无法生成游戏文件。",
"launch_build_unavailable": "生成游戏文件时发现需要重新确认的不可用补丁。",
"launch_port_busy": "本地服务器端口已被占用。",
"launch_server_exited": "本地服务器不可用。",
"settings_write_failed": "无法保存设置。",
"folder_unreadable": "无法读取文件夹:{{path}}",
"not_a_game_folder": "所选文件夹不是战争雷霆的安装文件夹:{{path}}",
@@ -1,13 +1,72 @@
import type { TFunction } from 'i18next';
import type { InstallRecord } from '@shared/schemas/install.ts';
import type { LaunchState } from '@shared/schemas/launch.ts';
import type { BarModel } from '../../shell/bar-model.ts';
import { missingFeatures } from '../copies/missing-features.ts';
/**
* The bottom bar outside the wizard: install before the first installation, launch after it.
* The launch action is disabled until the launcher can start a copy.
*/
export function homeBar(record: InstallRecord | null, t: TFunction, onInstall: () => void): BarModel {
interface LaunchActions {
readonly start: () => void;
readonly stop: () => void;
readonly checkVersion: () => void;
}
/** The installation and launch actions shown outside the wizard. */
export function homeBar(
record: InstallRecord | null,
state: LaunchState,
t: TFunction,
onInstall: () => void,
actions: LaunchActions,
): BarModel {
const launch = { label: t('bar.launch'), onClick: actions.start };
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 };
switch (state.phase) {
case 'checking':
case 'building':
return {
tone: 'busy',
title: state.phase === 'checking' ? t('launch.checking') : t('launch.building'),
detail: state.file,
progress,
primary: starting,
secondary: { label: t('launch.cancel'), onClick: actions.stop },
};
case 'starting-server':
case 'starting-game':
case 'stopping':
return {
tone: 'busy',
title: t(`launch.${state.phase}`),
progress: { value: 0, max: null },
primary: starting,
};
case 'running':
return {
tone: 'ok',
title: t('launch.running'),
detail: t('launch.runningDetail', { port: state.port }),
primary: { label: t('launch.running'), disabled: true },
secondary: { label: t('launch.stop'), onClick: actions.stop },
};
case 'port-busy':
return { tone: 'bad', title: t('launch.port-busy', { port: state.port }), primary: retry };
case 'server-exited':
return { tone: 'bad', title: t('launch.server-exited'), primary: retry };
case 'version-changed':
return {
tone: 'warn',
title: t('launch.version-changed'),
detail: t('launch.versionDetail', { version: state.actualVersion ?? t('source.versionUnknown') }),
primary: { label: t('launch.check'), onClick: actions.checkVersion },
};
case 'failed':
return { tone: 'bad', title: t(`errors.${state.error ?? 'launch_lab_failed'}`), primary: retry };
case 'ready':
break;
}
if (!record) {
return {
tone: 'idle',
@@ -21,6 +80,6 @@ export function homeBar(record: InstallRecord | null, t: TFunction, onInstall: (
tone: missing ? 'warn' : 'ok',
title: missing ? t('bar.readyMissing', { count: missing }) : t('bar.ready'),
detail: t('bar.readyDetail', { version: record.gameVersion ?? t('source.versionUnknown') }),
primary: { label: t('bar.launch'), disabled: true },
primary: launch,
};
}
@@ -0,0 +1,35 @@
import { useTranslation } from 'react-i18next';
import type { Settings, SettingsPatch } from '@shared/schemas/settings.ts';
import { FolderField } from '../../components/FolderField.tsx';
import { Row } from '../../components/Row.tsx';
import { Sheet } from '../../components/Sheet.tsx';
import { ipcInvoke } from '../../ipc.ts';
interface DeveloperSettingsProps {
readonly settings: Settings;
readonly onError: (error: unknown) => void;
}
export function DeveloperSettings({ settings, onError }: DeveloperSettingsProps) {
const { t } = useTranslation();
const update = (patch: SettingsPatch): void => { ipcInvoke('settings:update', patch).catch(onError); };
return (
<Sheet title={t('settings.sections.dev')}>
<Row label={t('settings.developer.mode')} hint={t('settings.developer.modeHint')}>
<label className="check check-inline">
<input type="checkbox" checked={settings.developerMode} onChange={(event) => update({ developerMode: event.target.checked })} />
{t('settings.developer.enabled')}
</label>
</Row>
<Row label={t('settings.developer.stock')} hint={t('settings.developer.stockHint')}>
<FolderField path={settings.labStockPath} dialogTitle={t('settings.developer.stock')} onChosen={(path) => update({ labStockPath: path })} onError={onError} />
{settings.labStockPath && <button type="button" className="button" onClick={() => update({ labStockPath: null })}>{t('settings.developer.reset')}</button>}
</Row>
<Row label={t('settings.developer.data')} hint={t('settings.developer.dataHint')}>
<FolderField path={settings.labDataPath} dialogTitle={t('settings.developer.data')} onChosen={(path) => update({ labDataPath: path })} onError={onError} />
{settings.labDataPath && <button type="button" className="button" onClick={() => update({ labDataPath: null })}>{t('settings.developer.reset')}</button>}
</Row>
</Sheet>
);
}
@@ -5,10 +5,11 @@ import { Sheet } from '../../components/Sheet.tsx';
import { ipcInvoke } from '../../ipc.ts';
interface DiagnosticsSettingsProps {
readonly serverRunning: boolean;
readonly onError: (error: unknown) => void;
}
export function DiagnosticsSettings({ onError }: DiagnosticsSettingsProps) {
export function DiagnosticsSettings({ onError, serverRunning }: DiagnosticsSettingsProps) {
const { t } = useTranslation();
const [exporting, setExporting] = useState(false);
const [savedPath, setSavedPath] = useState<string | null>(null);
@@ -38,6 +39,11 @@ export function DiagnosticsSettings({ onError }: DiagnosticsSettingsProps) {
{t('settings.diagnostics.save')}
</button>
</Row>
<Row label={t('settings.diagnostics.serverStatus')}>
<button type="button" className="button" disabled={!serverRunning} onClick={() => ipcInvoke('launch:openServerStatus').catch(onError)}>
{t('settings.diagnostics.openStatus')}
</button>
</Row>
{savedPath && <p className="small" role="status">{t('settings.diagnostics.saved', { path: savedPath })}</p>}
</Sheet>
);
@@ -38,6 +38,18 @@ export function GeneralSettings({ settings, pictures, onError }: GeneralSettings
<Row label={t('settings.language')} hint={t('settings.languageHint')}>
<LanguageMenu value={settings.language} onError={onError} plain />
</Row>
<Row label={t('settings.windowClose')}>
<select className="select" value={settings.windowClose} onChange={(event) => update({ windowClose: event.target.value === 'tray' ? 'tray' : 'quit' })}>
<option value="quit">{t('settings.windowQuit')}</option>
<option value="tray">{t('settings.windowTray')}</option>
</select>
</Row>
<Row label={t('settings.afterGameStarts')}>
<select className="select" value={settings.afterGameStarts} onChange={(event) => update({ afterGameStarts: event.target.value === 'keep' ? 'keep' : 'minimize' })}>
<option value="minimize">{t('settings.windowMinimize')}</option>
<option value="keep">{t('settings.windowKeep')}</option>
</select>
</Row>
<Row label={t('background.official')} hint={t('background.officialHint')}>
<label className="check check-inline">
<input type="checkbox" checked={settings.officialWallpapers} onChange={(event) => update({ officialWallpapers: event.target.checked })} />
@@ -0,0 +1,29 @@
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import type { IpcOutput } from '@shared/ipc/contract.ts';
import { Row } from '../../components/Row.tsx';
import { Sheet } from '../../components/Sheet.tsx';
import { ipcInvoke } from '../../ipc.ts';
export function LaunchSettings({ onError }: { readonly onError: (error: unknown) => void }) {
const { t } = useTranslation();
const [lab, setLab] = useState<IpcOutput<'launch:getLabInfo'>>(null);
useEffect(() => {
let mounted = true;
ipcInvoke('launch:getLabInfo').then((info) => {
if (mounted) setLab(info);
}).catch(onError);
return () => { mounted = false; };
}, [onError]);
return (
<Sheet title={t('settings.sections.launch')}>
<Row label={t('settings.launch.port')} hint={t('settings.launch.portHint')}>
{lab?.port ?? '—'}
</Row>
<Row label={t('settings.launch.exit')} hint={t('settings.launch.exitHint')}>
{t('settings.launch.automatic')}
</Row>
</Sheet>
);
}
@@ -9,7 +9,7 @@ export type PageId = (typeof PAGES)[number];
export const COPY_SECTIONS = ['summary', 'features'] as const;
export type CopySection = (typeof COPY_SECTIONS)[number];
export const SETTINGS_SECTIONS = ['general', 'diag'] as const;
export const SETTINGS_SECTIONS = ['general', 'launch', 'diag', 'dev'] as const;
export type SettingsSection = (typeof SETTINGS_SECTIONS)[number];
export interface Route {