feat(launcher): merge add-client entry and choose setup mode in wizard step 1

This commit is contained in:
N0VAN0M4LY committed 2026-12-01 04:39:48 +08:00
1 parent a0515c4ed3
commit f182e205e3
7 files changed
+80 -19

No files matched your search

+3 -7
View File
@@ -124,7 +124,7 @@ export function App({ info, initialSettings, initialCopies }: AppProps) {
};
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('new'), {
const home = homeBar(record, launchStatus, t, wizard.start, {
start: () => { ipcInvoke('launch:start').catch(report); },
stop: () => { ipcInvoke('launch:stop').catch(report); },
checkVersion: () => go({ page: 'copies', section: 'features' }),
@@ -191,8 +191,7 @@ export function App({ info, initialSettings, initialCopies }: AppProps) {
supportedVersions={supported}
onSelect={selectCopy}
onRelocate={relocateCopy}
onAdd={() => wizard.start('new')}
onAddExisting={() => wizard.start('existing')}
onAdd={wizard.start}
/>
),
bar: home,
@@ -204,10 +203,7 @@ export function App({ info, initialSettings, initialCopies }: AppProps) {
main: (
<Sheet title={t(`copies.sections.${route.copies}`)}>
<p className="lead">{t('copies.none')}</p>
<div className="copy-list-actions">
<button type="button" className="button button-primary" onClick={() => wizard.start('new')}>{t('bar.install')}</button>
<button type="button" className="button" onClick={() => wizard.start('existing')}>{t('copies.addExisting')}</button>
</div>
<button type="button" className="button button-primary" onClick={wizard.start}>{t('bar.install')}</button>
</Sheet>
),
bar: home,
@@ -111,6 +111,7 @@
"wizard": {
"title": "Add a client",
"steps": {
"mode": "Setup mode",
"source": "Game location",
"method": "Installation type",
"data": "Data folder",
@@ -127,6 +128,13 @@
"checking": "Checking patches",
"checkingDetail": "Checking which patches apply to the selected game"
},
"mode": {
"body": "Choose how to add an offline client.",
"newTitle": "Fresh installation from online client",
"newBody": "Create a new offline client from an installed online War Thunder folder via full copy, space-saving copy, or in-place setup.",
"existingTitle": "Add existing offline client",
"existingBody": "Register an already prepared offline client folder directly without copying game files."
},
"source": {
"body": "Select the folder where War Thunder is installed.",
"dialogTitle": "Select the War Thunder installation folder",
@@ -215,7 +223,6 @@
"maintain": "Maintenance"
},
"add": "Add a client",
"addExisting": "Add existing client",
"missingFolder": "Folder missing",
"relocate": "Relocate…",
"relocateDialogTitle": "Select the moved client folder",
@@ -111,6 +111,7 @@
"wizard": {
"title": "添加客户端",
"steps": {
"mode": "添加方式",
"source": "游戏位置",
"method": "安装方式",
"data": "数据目录",
@@ -127,6 +128,13 @@
"checking": "正在检查补丁",
"checkingDetail": "正在核对补丁对所选游戏的适用情况"
},
"mode": {
"body": "选择添加离线客户端的方式。",
"newTitle": "从在线版全新安装",
"newBody": "从已安装的战争雷霆在线版创建新的离线客户端,支持完整复制、省空间复制或原位安装。",
"existingTitle": "添加已有离线客户端",
"existingBody": "直接登记已准备好的离线客户端文件夹,不重新复制游戏文件。"
},
"source": {
"body": "选择已安装的战争雷霆文件夹。",
"dialogTitle": "选择战争雷霆安装文件夹",
@@ -215,7 +223,6 @@
"maintain": "维护"
},
"add": "添加客户端",
"addExisting": "添加已有客户端",
"missingFolder": "目录不存在",
"relocate": "重新定位…",
"relocateDialogTitle": "选择挪动后的客户端文件夹",
@@ -9,10 +9,9 @@ interface CopyListProps {
readonly onSelect: (id: string, detail?: boolean) => void;
readonly onRelocate: (id: string) => void;
readonly onAdd: () => void;
readonly onAddExisting: () => void;
}
export function CopyList({ registry, supportedVersions, onSelect, onRelocate, onAdd, onAddExisting }: CopyListProps) {
export function CopyList({ registry, supportedVersions, onSelect, onRelocate, onAdd }: CopyListProps) {
const { t } = useTranslation();
return (
<Sheet title={t('copies.sections.list')}>
@@ -55,7 +54,6 @@ export function CopyList({ registry, supportedVersions, onSelect, onRelocate, on
);
})}
<button type="button" className="button copy-list-add" onClick={onAdd}>{t('copies.add')}</button>
<button type="button" className="button copy-list-add" onClick={onAddExisting}>{t('copies.addExisting')}</button>
</div>
</Sheet>
);
@@ -0,0 +1,41 @@
import { useTranslation } from 'react-i18next';
import type { WizardMode } from './useInstallWizard.ts';
interface ModeStepProps {
readonly mode: WizardMode;
readonly onMode: (mode: WizardMode) => void;
}
/** Step 1: choose whether to install a new offline client or register an existing one. */
export function ModeStep({ mode, onMode }: ModeStepProps) {
const { t } = useTranslation();
const options: ReadonlyArray<{ readonly value: WizardMode; readonly title: string; readonly body: string }> = [
{ value: 'new', title: t('mode.newTitle'), body: t('mode.newBody') },
{ value: 'existing', title: t('mode.existingTitle'), body: t('mode.existingBody') },
];
return (
<>
<p className="lead">{t('mode.body')}</p>
{options.map((option) => {
const selected = mode === option.value;
return (
<div
key={option.value}
className={selected ? 'choice choice-selected' : 'choice'}
onClick={selected ? undefined : () => onMode(option.value)}
>
<input
type="radio"
name="wizard-mode"
checked={selected}
onChange={() => onMode(option.value)}
aria-label={option.title}
/>
<span className="choice-title">{option.title}</span>
<div className="choice-body">{option.body}</div>
</div>
);
})}
</>
);
}
@@ -4,6 +4,7 @@ import { Sheet } from '../../components/Sheet.tsx';
import { CheckStep } from './CheckStep.tsx';
import { DataStep } from './DataStep.tsx';
import { MethodStep } from './MethodStep.tsx';
import { ModeStep } from './ModeStep.tsx';
import { ProgressStep } from './ProgressStep.tsx';
import { SourceStep, sourceUsable } from './SourceStep.tsx';
import { WIZARD_STEPS, type InstallWizard } from './useInstallWizard.ts';
@@ -14,6 +15,7 @@ export function WizardMain({ wizard, supportedVersions }: { readonly wizard: Ins
const { step, source } = wizard;
return (
<Sheet title={t(`wizard.steps.${step}`)} aside={t('wizard.stepOf', { index: wizard.index + 1, total: WIZARD_STEPS.length })}>
{step === 'mode' && <ModeStep mode={wizard.mode} onMode={wizard.chooseMode} />}
{step === 'source' && (
<SourceStep
mode={wizard.mode}
@@ -6,7 +6,7 @@ import { checkUsable } from './CheckStep.tsx';
import { methodUsable, type MethodChoice } from './MethodStep.tsx';
import { sourceUsable } from './SourceStep.tsx';
export const WIZARD_STEPS = ['source', 'method', 'data', 'check', 'installing'] as const;
export const WIZARD_STEPS = ['mode', 'source', 'method', 'data', 'check', 'installing'] as const;
export type WizardStep = (typeof WIZARD_STEPS)[number];
export type WizardMode = 'new' | 'existing';
@@ -25,7 +25,7 @@ export function useInstallWizard({ onInstalled }: WizardOptions) {
const { message, report, clear } = useErrorMessage();
const [active, setActive] = useState(false);
const [mode, setMode] = useState<WizardMode>('new');
const [step, setStep] = useState<WizardStep>('source');
const [step, setStep] = useState<WizardStep>('mode');
const [source, setSource] = useState<GameFolderInspection | null>(null);
const [stockSource, setStockSource] = useState<GameFolderInspection | null>(null);
const [sourceSize, setSourceSize] = useState<FolderSize | null>(null);
@@ -97,13 +97,13 @@ export function useInstallWizard({ onInstalled }: WizardOptions) {
useEffect(() => ipcOn('event:install-progress', setProgress), []);
const start = (nextMode: WizardMode = 'new'): void => {
const start = (): void => {
clear();
setMode(nextMode);
setStep('source');
setMode('new');
setStep('mode');
setSource(null);
setStockSource(null);
setChoice(nextMode === 'existing' ? { method: 'existing', target: null, steamConfirmed: false } : NO_CHOICE);
setChoice(NO_CHOICE);
setName('');
setDraftId(null);
setDataPath('');
@@ -116,6 +116,15 @@ export function useInstallWizard({ onInstalled }: WizardOptions) {
}).catch(report);
};
const chooseMode = (nextMode: WizardMode): void => {
if (nextMode === mode) return;
setMode(nextMode);
setSource(null);
setStockSource(null);
setChoice(nextMode === 'existing' ? { method: 'existing', target: null, steamConfirmed: false } : NO_CHOICE);
setName('');
};
const chooseSource = (found: GameFolderInspection | null): void => {
setSource(found);
setStockSource(null);
@@ -169,6 +178,7 @@ export function useInstallWizard({ onInstalled }: WizardOptions) {
const canGoOn = ((): boolean => {
switch (step) {
case 'mode': return draftId !== null;
case 'source': return draftId !== null && sourceUsable(source, stockSource);
case 'method': return name.trim().length > 0 && sourceUsable(source, stockSource) && methodUsable(source, sourceSize, choice);
case 'data': return dataReady;
@@ -200,7 +210,7 @@ export function useInstallWizard({ onInstalled }: WizardOptions) {
return {
active, mode, step, index, source, stockSource, sourceSize, choice, name, dataPath, decalSource, check, missingAccepted, progress, cancelling, message, canGoOn,
steamDataPath: dataChecked?.inSteam ? dataChecked.path : null, steamDataConfirmed: dataChecked?.confirmed ?? false,
start, back, next, cancel, report, chooseSource, setStockSource, setChoice, setName, setDataPath, setSteamDataConfirmed, setDecalSource, setMissingAccepted,
start, back, next, cancel, report, chooseMode, chooseSource, setStockSource, setChoice, setName, setDataPath, setSteamDataConfirmed, setDecalSource, setMissingAccepted,
};
}