feat(launcher): implement gated standard launch
Build the selected copy for its port, wait for the local server, and manage the game and server lifecycles. Keep standard launch disabled pending isolation verification. Verified both type checks, the launcher build, and the launch lifecycle against a temporary copy and a stand-in executable.
This commit is contained in:
1 parent
2a97b0d46c
commit
c1dea23955
19 files changed
+522
-105
No files matched your search
@@ -2,7 +2,7 @@ import { useEffect, useState, type ReactNode } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import type { IpcOutput } from '@shared/ipc/contract.ts';
|
||||
import type { Copies } from '@shared/schemas/install.ts';
|
||||
import type { LaunchState } from '@shared/schemas/launch.ts';
|
||||
import { ORDINARY_LAUNCH_ENABLED, 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';
|
||||
@@ -96,6 +96,7 @@ export function App({ info, initialSettings, initialCopies }: AppProps) {
|
||||
const perCopyStatus = ['version-changed', 'failed', 'port-busy', 'server-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, {
|
||||
canStart: ORDINARY_LAUNCH_ENABLED || (info.development && settings.developerMode),
|
||||
start: () => { ipcInvoke('launch:start').catch(report); },
|
||||
stop: () => { ipcInvoke('launch:stop').catch(report); },
|
||||
checkVersion: () => go({ page: 'copies', section: 'features' }),
|
||||
@@ -124,8 +125,8 @@ export function App({ info, initialSettings, initialCopies }: AppProps) {
|
||||
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'} />,
|
||||
launch: <LaunchSettings settings={settings} development={info.development} onError={report} />,
|
||||
diag: <DiagnosticsSettings onError={report} serverRunning={launch.phase === 'running' || launch.phase === 'server-running'} />,
|
||||
dev: <DeveloperSettings settings={settings} onError={report} />,
|
||||
};
|
||||
return {
|
||||
@@ -138,7 +139,7 @@ export function App({ info, initialSettings, initialCopies }: AppProps) {
|
||||
return {
|
||||
side: <SubNav sections={SAVE_SECTIONS} active={route.saves} label={(section) => t(`saves.sections.${section}`)} onSelect={(section) => go({ page: 'saves', section })} />,
|
||||
main: record
|
||||
? <SavesPage key={record.id} copy={record} copies={registry.copies} section={route.saves} readOnly={['checking', 'building', 'starting-server', 'starting-game', 'running', 'stopping'].includes(launch.phase)} onError={report} />
|
||||
? <SavesPage key={record.id} copy={record} copies={registry.copies} section={route.saves} readOnly={['checking', 'building', 'starting-server', 'starting-game', 'running', 'server-running', 'stopping'].includes(launch.phase)} onError={report} />
|
||||
: <Sheet title={t(`saves.sections.${route.saves}`)}><p className="lead">{t('saves.noCopy')}</p></Sheet>,
|
||||
bar: home,
|
||||
};
|
||||
|
||||
@@ -76,7 +76,9 @@
|
||||
"starting": "Starting…",
|
||||
"running": "Game running",
|
||||
"runningDetail": "Local server · Port {{port}}",
|
||||
"stopping": "Stopping game",
|
||||
"server-running": "Local server running",
|
||||
"stopping": "Stopping",
|
||||
"stopServer": "Close local server",
|
||||
"cancel": "Cancel",
|
||||
"stop": "End game",
|
||||
"retry": "Retry",
|
||||
@@ -442,7 +444,13 @@
|
||||
"portHint": "Port set by the installed lab automation",
|
||||
"exit": "When the game exits",
|
||||
"exitHint": "Isolated launch",
|
||||
"automatic": "Close local server"
|
||||
"automatic": "Close local server",
|
||||
"portMode": "Port assignment",
|
||||
"autoPort": "Assign automatically",
|
||||
"fixedPort": "Specify port",
|
||||
"arguments": "Additional arguments",
|
||||
"argumentsHint": "Command-line arguments passed to the game",
|
||||
"argumentsInvalid": "Close each double quote in the launch arguments."
|
||||
},
|
||||
"developer": {
|
||||
"mode": "Developer mode",
|
||||
@@ -597,16 +605,22 @@
|
||||
"maintenance_source_changed": "The installation source changed during the update. Retry once its update is complete.",
|
||||
"launch_no_copy": "A game copy must be installed before launching.",
|
||||
"launch_busy": "A launch is already in progress.",
|
||||
"launch_failed": "Launch failed. See the launcher log.",
|
||||
"launch_disabled": "Standard launch is pending isolation verification.",
|
||||
"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_location": "The game copy, stock backup, or data folder location is invalid.",
|
||||
"launch_stock_version": "The stock backup and game copy versions do not match.",
|
||||
"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_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.",
|
||||
"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}}",
|
||||
|
||||
@@ -76,7 +76,9 @@
|
||||
"starting": "启动中…",
|
||||
"running": "游戏运行中",
|
||||
"runningDetail": "本地服务器 · 端口 {{port}}",
|
||||
"stopping": "正在结束游戏",
|
||||
"server-running": "本地服务器运行中",
|
||||
"stopping": "正在关闭",
|
||||
"stopServer": "关闭本地服务器",
|
||||
"cancel": "取消",
|
||||
"stop": "结束游戏",
|
||||
"retry": "重试",
|
||||
@@ -442,7 +444,13 @@
|
||||
"portHint": "使用已安装实验自动化的端口设置",
|
||||
"exit": "游戏退出后",
|
||||
"exitHint": "隔离启动",
|
||||
"automatic": "关闭本地服务器"
|
||||
"automatic": "关闭本地服务器",
|
||||
"portMode": "端口分配方式",
|
||||
"autoPort": "自动分配",
|
||||
"fixedPort": "指定端口",
|
||||
"arguments": "附加启动参数",
|
||||
"argumentsHint": "传递给游戏的命令行参数",
|
||||
"argumentsInvalid": "请补全启动参数中的双引号。"
|
||||
},
|
||||
"developer": {
|
||||
"mode": "开发模式",
|
||||
@@ -597,16 +605,22 @@
|
||||
"maintenance_source_changed": "安装来源在更新过程中发生变化。请在正版更新完成后重试。",
|
||||
"launch_no_copy": "启动前需要安装游戏副本。",
|
||||
"launch_busy": "启动流程正在运行。",
|
||||
"launch_failed": "启动失败。请查看启动器日志。",
|
||||
"launch_disabled": "普通启动待隔离验收。",
|
||||
"launch_lab_required": "请启用开发模式以通过隔离实验副本启动。",
|
||||
"launch_lab_missing": "无法读取隔离实验自动化配置。",
|
||||
"launch_lab_version": "实验副本和原版文件备份必须使用同一游戏版本。",
|
||||
"launch_lab_failed": "隔离启动失败。请查看启动器日志。",
|
||||
"launch_game_running": "已有游戏进程在运行。",
|
||||
"launch_copy_in_steam": "启动需使用 Steam 目录外的副本和数据目录。",
|
||||
"launch_location": "副本、原版文件备份或数据目录的位置无效。",
|
||||
"launch_stock_version": "原版文件备份的版本与副本不一致。",
|
||||
"launch_build_failed": "无法生成游戏文件。",
|
||||
"launch_build_unavailable": "生成游戏文件时发现需要重新确认的不可用补丁。",
|
||||
"launch_port_busy": "本地服务器端口已被占用。",
|
||||
"launch_server_failed": "无法启动本地服务器。请查看启动器日志。",
|
||||
"launch_server_exited": "本地服务器不可用。",
|
||||
"launch_game_failed": "游戏进程启动失败或意外退出。请查看启动器日志。",
|
||||
"settings_write_failed": "无法保存设置。",
|
||||
"folder_unreadable": "无法读取文件夹:{{path}}",
|
||||
"not_a_game_folder": "所选文件夹不是战争雷霆的安装文件夹:{{path}}",
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { BarModel } from '../../shell/bar-model.ts';
|
||||
import { missingFeatures } from '../copies/missing-features.ts';
|
||||
|
||||
interface LaunchActions {
|
||||
readonly canStart: boolean;
|
||||
readonly start: () => void;
|
||||
readonly stop: () => void;
|
||||
readonly checkVersion: () => void;
|
||||
@@ -18,8 +19,8 @@ export function homeBar(
|
||||
onInstall: () => void,
|
||||
actions: LaunchActions,
|
||||
): BarModel {
|
||||
const launch = { label: t('bar.launch'), onClick: actions.start };
|
||||
const retry = { label: t('launch.retry'), onClick: actions.start };
|
||||
const launch = { label: t('bar.launch'), onClick: actions.start, disabled: !actions.canStart };
|
||||
const retry = { label: t('launch.retry'), onClick: actions.start, disabled: !actions.canStart };
|
||||
const starting = { label: t('launch.starting'), disabled: true };
|
||||
const progress = { value: state.filesWritten ?? 0, max: state.filesTotal || null };
|
||||
switch (state.phase) {
|
||||
@@ -41,6 +42,7 @@ export function homeBar(
|
||||
title: t(`launch.${state.phase}`),
|
||||
progress: { value: 0, max: null },
|
||||
primary: starting,
|
||||
...(state.phase === 'stopping' ? {} : { secondary: { label: t('launch.cancel'), onClick: actions.stop } }),
|
||||
};
|
||||
case 'running':
|
||||
return {
|
||||
@@ -50,6 +52,14 @@ export function homeBar(
|
||||
primary: { label: t('launch.running'), disabled: true },
|
||||
secondary: { label: t('launch.stop'), onClick: actions.stop },
|
||||
};
|
||||
case 'server-running':
|
||||
return {
|
||||
tone: 'ok',
|
||||
title: t('launch.server-running'),
|
||||
detail: t('launch.runningDetail', { port: state.port }),
|
||||
primary: launch,
|
||||
secondary: { label: t('launch.stopServer'), onClick: actions.stop },
|
||||
};
|
||||
case 'port-busy':
|
||||
return { tone: 'bad', title: t('launch.port-busy', { port: state.port }), primary: retry };
|
||||
case 'server-exited':
|
||||
@@ -62,7 +72,7 @@ export function homeBar(
|
||||
primary: { label: t('launch.check'), onClick: actions.checkVersion },
|
||||
};
|
||||
case 'failed':
|
||||
return { tone: 'bad', title: t(`errors.${state.error ?? 'launch_lab_failed'}`), primary: retry };
|
||||
return { tone: 'bad', title: t(`errors.${state.error ?? 'launch_failed'}`), primary: retry };
|
||||
case 'ready':
|
||||
break;
|
||||
}
|
||||
@@ -75,6 +85,9 @@ export function homeBar(
|
||||
primary: { label: t('bar.install'), onClick: onInstall },
|
||||
};
|
||||
}
|
||||
if (!actions.canStart) {
|
||||
return { tone: 'warn', title: t('errors.launch_disabled'), primary: launch };
|
||||
}
|
||||
const missing = missingFeatures(record).length;
|
||||
return {
|
||||
tone: missing ? 'warn' : 'ok',
|
||||
|
||||
@@ -1,28 +1,104 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import type { IpcOutput } from '@shared/ipc/contract.ts';
|
||||
import { parseLaunchArguments } from '@shared/launch-arguments.ts';
|
||||
import { ORDINARY_LAUNCH_ENABLED } from '@shared/schemas/launch.ts';
|
||||
import { LAUNCH_ARGUMENTS_LIMIT, type Settings, type SettingsPatch } from '@shared/schemas/settings.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 }) {
|
||||
interface LaunchSettingsProps {
|
||||
readonly settings: Settings;
|
||||
readonly development: boolean;
|
||||
readonly onError: (error: unknown) => void;
|
||||
}
|
||||
|
||||
export function LaunchSettings({ settings, development, onError }: LaunchSettingsProps) {
|
||||
const { t } = useTranslation();
|
||||
const [lab, setLab] = useState<IpcOutput<'launch:getLabInfo'>>(null);
|
||||
const useLab = development && settings.developerMode;
|
||||
useEffect(() => {
|
||||
if (!useLab) return;
|
||||
let mounted = true;
|
||||
ipcInvoke('launch:getLabInfo').then((info) => {
|
||||
if (mounted) setLab(info);
|
||||
}).catch(onError);
|
||||
return () => { mounted = false; };
|
||||
}, [onError]);
|
||||
}, [onError, useLab]);
|
||||
|
||||
const update = (patch: SettingsPatch): void => { ipcInvoke('settings:update', patch).catch(onError); };
|
||||
const title = t('settings.sections.launch');
|
||||
if (useLab) {
|
||||
return (
|
||||
<Sheet title={title}>
|
||||
<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>
|
||||
);
|
||||
}
|
||||
if (!ORDINARY_LAUNCH_ENABLED) {
|
||||
return <Sheet title={title}><p className="lead">{t('errors.launch_disabled')}</p></Sheet>;
|
||||
}
|
||||
|
||||
return (
|
||||
<Sheet title={t('settings.sections.launch')}>
|
||||
<Row label={t('settings.launch.port')} hint={t('settings.launch.portHint')}>
|
||||
{lab?.port ?? '—'}
|
||||
<Sheet title={title}>
|
||||
<Row label={t('settings.launch.port')}>
|
||||
<select
|
||||
className="select"
|
||||
aria-label={t('settings.launch.portMode')}
|
||||
value={settings.launchPortMode}
|
||||
onChange={(event) => update({ launchPortMode: event.currentTarget.value === 'fixed' ? 'fixed' : 'auto' })}
|
||||
>
|
||||
<option value="auto">{t('settings.launch.autoPort')}</option>
|
||||
<option value="fixed">{t('settings.launch.fixedPort')}</option>
|
||||
</select>
|
||||
<input
|
||||
className="select"
|
||||
aria-label={t('settings.launch.port')}
|
||||
type="number"
|
||||
min={1}
|
||||
max={65535}
|
||||
required
|
||||
disabled={settings.launchPortMode === 'auto'}
|
||||
defaultValue={settings.launchPort}
|
||||
key={settings.launchPort}
|
||||
onBlur={(event) => {
|
||||
const input = event.currentTarget;
|
||||
if (!input.reportValidity()) return;
|
||||
if (settings.launchPort !== input.valueAsNumber) update({ launchPort: input.valueAsNumber });
|
||||
}}
|
||||
/>
|
||||
</Row>
|
||||
<Row label={t('settings.launch.exit')} hint={t('settings.launch.exitHint')}>
|
||||
{t('settings.launch.automatic')}
|
||||
<Row label={t('settings.launch.exit')}>
|
||||
<label className="check check-inline">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={settings.closeServerOnGameExit}
|
||||
onChange={(event) => update({ closeServerOnGameExit: event.currentTarget.checked })}
|
||||
/>
|
||||
{t('settings.launch.automatic')}
|
||||
</label>
|
||||
</Row>
|
||||
<Row label={t('settings.launch.arguments')} hint={t('settings.launch.argumentsHint')}>
|
||||
<input
|
||||
className="select"
|
||||
aria-label={t('settings.launch.arguments')}
|
||||
placeholder="-windowed"
|
||||
maxLength={LAUNCH_ARGUMENTS_LIMIT}
|
||||
defaultValue={settings.launchArguments}
|
||||
key={settings.launchArguments}
|
||||
onChange={(event) => event.currentTarget.setCustomValidity('')}
|
||||
onBlur={(event) => {
|
||||
const input = event.currentTarget;
|
||||
if (!parseLaunchArguments(input.value)) {
|
||||
input.setCustomValidity(t('settings.launch.argumentsInvalid'));
|
||||
input.reportValidity();
|
||||
return;
|
||||
}
|
||||
if (input.value !== settings.launchArguments) update({ launchArguments: input.value });
|
||||
}}
|
||||
/>
|
||||
</Row>
|
||||
</Sheet>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user