feat(launcher)!: manage multiple game copies
BREAKING CHANGE: The launcher stores copy registrations in copies.json. Installations recorded only in install.json must be registered again.
This commit is contained in:
1 parent
e41b73aaa3
commit
7d68dc0548
24 files changed
+408
-97
No files matched your search
@@ -1,13 +1,14 @@
|
||||
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 { Copies } 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 { ipcInvoke, ipcOn } from './ipc.ts';
|
||||
import { AboutPage } from './pages/about/AboutPage.tsx';
|
||||
import { CopyList } from './pages/copies/CopyList.tsx';
|
||||
import { CopySummary } from './pages/copies/CopySummary.tsx';
|
||||
import { FeatureStatus } from './pages/copies/FeatureStatus.tsx';
|
||||
import { BackgroundSwitch } from './pages/home/BackgroundSwitch.tsx';
|
||||
@@ -35,8 +36,7 @@ import { useErrorMessage } from './useErrorMessage.ts';
|
||||
interface AppProps {
|
||||
readonly info: IpcOutput<'app:getInfo'>;
|
||||
readonly initialSettings: Settings;
|
||||
readonly initialRecord: InstallRecord | null;
|
||||
readonly defaultDataPath: string;
|
||||
readonly initialCopies: Copies;
|
||||
}
|
||||
|
||||
interface View {
|
||||
@@ -50,26 +50,22 @@ interface View {
|
||||
* panel and the main area; the bottom bar belongs to the current task (the install wizard while
|
||||
* it runs, otherwise install / launch).
|
||||
*/
|
||||
export function App({ info, initialSettings, initialRecord, defaultDataPath }: AppProps) {
|
||||
export function App({ info, initialSettings, initialCopies }: AppProps) {
|
||||
const { t } = useTranslation();
|
||||
const { message, report } = useErrorMessage();
|
||||
const [settings, setSettings] = useState(initialSettings);
|
||||
const [record, setRecord] = useState(initialRecord);
|
||||
const [registry, setRegistry] = useState(initialCopies);
|
||||
const record = registry.copies.find((copy) => copy.id === registry.current) ?? null;
|
||||
const [launch, setLaunch] = useState<LaunchState>({ phase: 'ready' });
|
||||
const [route, setRoute] = useState<Route>(START_ROUTE);
|
||||
const supported = info.supportedGameVersions;
|
||||
|
||||
const wizard = useInstallWizard({
|
||||
defaultDataPath: record?.dataPath ?? defaultDataPath,
|
||||
onInstalled: (installed) => {
|
||||
setRecord(installed);
|
||||
setRoute(START_ROUTE);
|
||||
},
|
||||
});
|
||||
const wizard = useInstallWizard({ onInstalled: () => setRoute(START_ROUTE) });
|
||||
|
||||
const backgrounds = useBackgrounds(record?.copyPath ?? null, settings, report);
|
||||
|
||||
useEffect(() => ipcOn('event:settings-changed', setSettings), []);
|
||||
useEffect(() => ipcOn('event:copies-changed', setRegistry), []);
|
||||
useEffect(() => applyLanguage(resolveLanguage(settings.language, info.systemLocale)), [settings.language, info.systemLocale]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -86,7 +82,14 @@ export function App({ info, initialSettings, initialRecord, defaultDataPath }: A
|
||||
}, [report]);
|
||||
|
||||
const go = (to: Destination): void => setRoute((current) => navigate(current, to));
|
||||
const home = homeBar(record, launch, t, wizard.start, {
|
||||
const selectCopy = (id: string, details = false): void => {
|
||||
ipcInvoke('copies:setCurrent', { id }).then(() => {
|
||||
if (details) go({ page: 'copies', section: 'summary' });
|
||||
}).catch(report);
|
||||
};
|
||||
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, {
|
||||
start: () => { ipcInvoke('launch:start').catch(report); },
|
||||
stop: () => { ipcInvoke('launch:stop').catch(report); },
|
||||
checkVersion: () => go({ page: 'copies', section: 'features' }),
|
||||
@@ -96,7 +99,7 @@ export function App({ info, initialSettings, initialRecord, defaultDataPath }: A
|
||||
if (wizard.active) {
|
||||
return { side: <WizardSide step={wizard.step} />, main: <WizardMain wizard={wizard} supportedVersions={supported} />, bar: wizardBar(wizard, t) };
|
||||
}
|
||||
const homeSide = <HomeSide record={record} supportedVersions={supported} onNavigate={go} />;
|
||||
const homeSide = <HomeSide record={record} copies={registry.copies} supportedVersions={supported} onNavigate={go} onSelectCopy={selectCopy} />;
|
||||
switch (route.page) {
|
||||
case 'home':
|
||||
return {
|
||||
@@ -126,14 +129,10 @@ export function App({ info, initialSettings, initialRecord, defaultDataPath }: A
|
||||
};
|
||||
}
|
||||
case 'copies': {
|
||||
const side = (
|
||||
<>
|
||||
<SubNav sections={COPY_SECTIONS} active={route.copies} label={(section) => t(`copies.sections.${section}`)} onSelect={(section) => go({ page: 'copies', section })} />
|
||||
<div className="side-foot">
|
||||
<button type="button" className="button" onClick={wizard.start}>{record ? t('copies.reinstall') : t('bar.install')}</button>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
const side = <SubNav sections={COPY_SECTIONS} active={route.copies} label={(section) => t(`copies.sections.${section}`)} onSelect={(section) => go({ page: 'copies', section })} />;
|
||||
if (route.copies === 'list') {
|
||||
return { side, main: <CopyList registry={registry} supportedVersions={supported} onSelect={selectCopy} onAdd={wizard.start} />, bar: home };
|
||||
}
|
||||
if (!record) {
|
||||
return {
|
||||
side,
|
||||
@@ -148,7 +147,7 @@ export function App({ info, initialSettings, initialRecord, defaultDataPath }: A
|
||||
}
|
||||
const main = route.copies === 'features'
|
||||
? <FeatureStatus record={record} supportedVersions={supported} onError={report} />
|
||||
: <CopySummary record={record} supportedVersions={supported} onShowFeatures={() => go({ page: 'copies', section: 'features' })} onReinstall={wizard.start} onError={report} />;
|
||||
: <CopySummary record={record} supportedVersions={supported} onShowFeatures={() => go({ page: 'copies', section: 'features' })} onError={report} />;
|
||||
return { side, main, bar: home };
|
||||
}
|
||||
}
|
||||
@@ -165,7 +164,7 @@ export function App({ info, initialSettings, initialRecord, defaultDataPath }: A
|
||||
{message && <p className="app-error" role="alert">{message}</p>}
|
||||
</main>
|
||||
<BottomBar model={view.bar} />
|
||||
<Footer launcherVersion={info.version} gameVersion={record?.gameVersion ?? null} installed={record !== null} />
|
||||
<Footer launcherVersion={info.version} gameVersion={record?.gameVersion ?? null} copyName={record?.name ?? null} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -21,7 +21,7 @@
|
||||
},
|
||||
"footer": {
|
||||
"launcher": "Launcher {{version}}",
|
||||
"game": "Game {{version}}",
|
||||
"game": "{{name}} · Game {{version}}",
|
||||
"notInstalled": "Not installed"
|
||||
},
|
||||
"home": {
|
||||
@@ -89,7 +89,7 @@
|
||||
"change": "Change…"
|
||||
},
|
||||
"wizard": {
|
||||
"title": "Install the offline edition",
|
||||
"title": "Add a copy",
|
||||
"steps": {
|
||||
"source": "Game location",
|
||||
"method": "Installation type",
|
||||
@@ -97,7 +97,7 @@
|
||||
"check": "Patch check",
|
||||
"installing": "Install"
|
||||
},
|
||||
"barTitle": "Install · {{step}}",
|
||||
"barTitle": "Add a copy · {{step}}",
|
||||
"stepOf": "Step {{index}} of {{total}}",
|
||||
"back": "Back",
|
||||
"next": "Next",
|
||||
@@ -164,12 +164,17 @@
|
||||
},
|
||||
"copies": {
|
||||
"sections": {
|
||||
"list": "All copies",
|
||||
"summary": "Copy details",
|
||||
"features": "Feature status"
|
||||
},
|
||||
"reinstall": "Reinstall…",
|
||||
"add": "Add a copy",
|
||||
"list": { "current": "Current", "select": "Set as current" },
|
||||
"none": "The offline edition is not installed yet.",
|
||||
"summary": {
|
||||
"name": "Copy name",
|
||||
"rename": "Rename",
|
||||
"source": "Installation source",
|
||||
"version": "Game version",
|
||||
"adaptation": "Adaptation",
|
||||
"adaptationHint": "Selected automatically by game version",
|
||||
@@ -326,6 +331,9 @@
|
||||
"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.",
|
||||
"copy_not_found": "The selected copy is no longer available.",
|
||||
"copies_write_failed": "The copy registry could not be saved.",
|
||||
"copy_location_in_use": "The copy or data location overlaps an existing copy.",
|
||||
"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.",
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
},
|
||||
"footer": {
|
||||
"launcher": "启动器 {{version}}",
|
||||
"game": "游戏 {{version}}",
|
||||
"game": "{{name}} · 游戏 {{version}}",
|
||||
"notInstalled": "未安装"
|
||||
},
|
||||
"home": {
|
||||
@@ -89,7 +89,7 @@
|
||||
"change": "更改…"
|
||||
},
|
||||
"wizard": {
|
||||
"title": "安装离线版",
|
||||
"title": "添加副本",
|
||||
"steps": {
|
||||
"source": "游戏位置",
|
||||
"method": "安装方式",
|
||||
@@ -97,7 +97,7 @@
|
||||
"check": "补丁检查",
|
||||
"installing": "安装"
|
||||
},
|
||||
"barTitle": "安装 · {{step}}",
|
||||
"barTitle": "添加副本 · {{step}}",
|
||||
"stepOf": "第 {{index}} 步,共 {{total}} 步",
|
||||
"back": "上一步",
|
||||
"next": "下一步",
|
||||
@@ -164,12 +164,17 @@
|
||||
},
|
||||
"copies": {
|
||||
"sections": {
|
||||
"list": "全部副本",
|
||||
"summary": "副本详情",
|
||||
"features": "功能状态"
|
||||
},
|
||||
"reinstall": "重新安装…",
|
||||
"add": "添加副本",
|
||||
"list": { "current": "当前", "select": "设为当前" },
|
||||
"none": "尚未安装离线版。",
|
||||
"summary": {
|
||||
"name": "副本名称",
|
||||
"rename": "重命名",
|
||||
"source": "安装来源",
|
||||
"version": "游戏版本",
|
||||
"adaptation": "适配版本",
|
||||
"adaptationHint": "按游戏版本自动选择",
|
||||
@@ -326,6 +331,9 @@
|
||||
"internal_error": "启动器内部错误。",
|
||||
"logs_folder_open_failed": "无法打开启动器日志文件夹。",
|
||||
"diagnostics_export_failed": "无法保存诊断信息。",
|
||||
"copy_not_found": "所选副本已不可用。",
|
||||
"copies_write_failed": "无法保存副本记录。",
|
||||
"copy_location_in_use": "副本位置或数据目录与已有副本重叠。",
|
||||
"launch_no_copy": "启动前需要安装游戏副本。",
|
||||
"launch_busy": "启动流程正在运行。",
|
||||
"launch_lab_required": "请启用开发模式以通过隔离实验副本启动。",
|
||||
|
||||
@@ -12,7 +12,7 @@ import './styles/controls.css';
|
||||
import './styles/pages.css';
|
||||
|
||||
async function start(): Promise<void> {
|
||||
const [settings, info, install] = await Promise.all([ipcInvoke('settings:get'), ipcInvoke('app:getInfo'), ipcInvoke('install:getRecord')]);
|
||||
const [settings, info, copies] = await Promise.all([ipcInvoke('settings:get'), ipcInvoke('app:getInfo'), ipcInvoke('copies:list')]);
|
||||
const language = resolveLanguage(settings.language, info.systemLocale);
|
||||
await initI18n(language);
|
||||
document.documentElement.lang = language;
|
||||
@@ -20,7 +20,7 @@ async function start(): Promise<void> {
|
||||
if (!root) throw new Error('#root is missing from index.html');
|
||||
createRoot(root).render(
|
||||
<StrictMode>
|
||||
<App info={info} initialSettings={settings} initialRecord={install.record} defaultDataPath={install.defaultDataPath} />
|
||||
<App info={info} initialSettings={settings} initialCopies={copies} />
|
||||
</StrictMode>,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import type { Copies } from '@shared/schemas/install.ts';
|
||||
import { Sheet } from '../../components/Sheet.tsx';
|
||||
import { adaptationFor } from '../../versions.ts';
|
||||
|
||||
interface CopyListProps {
|
||||
readonly registry: Copies;
|
||||
readonly supportedVersions: readonly string[];
|
||||
readonly onSelect: (id: string, detail?: boolean) => void;
|
||||
readonly onAdd: () => void;
|
||||
}
|
||||
|
||||
export function CopyList({ registry, supportedVersions, onSelect, onAdd }: CopyListProps) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<Sheet title={t('copies.sections.list')}>
|
||||
{registry.copies.length === 0 && <p className="lead">{t('copies.none')}</p>}
|
||||
<div className="copy-list">
|
||||
{registry.copies.map((copy) => {
|
||||
const current = copy.id === registry.current;
|
||||
const unknown = t('source.versionUnknown');
|
||||
return (
|
||||
<article key={copy.id} className={current ? 'copy-list-card copy-list-current' : 'copy-list-card'}>
|
||||
<div className="copy-list-heading">
|
||||
<strong>{copy.name}</strong>
|
||||
{current && <span className="ok">{t('copies.list.current')}</span>}
|
||||
</div>
|
||||
<dl className="kv">
|
||||
<dt>{t('copies.summary.version')}</dt>
|
||||
<dd>{copy.gameVersion ?? unknown}</dd>
|
||||
<dt>{t('copies.summary.adaptation')}</dt>
|
||||
<dd>{adaptationFor(copy.gameVersion, supportedVersions) ?? unknown}</dd>
|
||||
<dt>{t('copies.summary.location')}</dt>
|
||||
<dd className="folder-path" title={copy.copyPath}>{copy.copyPath}</dd>
|
||||
</dl>
|
||||
<div className="copy-list-actions">
|
||||
{!current && <button type="button" className="button button-primary" onClick={() => onSelect(copy.id)}>{t('copies.list.select')}</button>}
|
||||
<button type="button" className="button" onClick={() => onSelect(copy.id, true)}>{t('side.details')}</button>
|
||||
</div>
|
||||
</article>
|
||||
);
|
||||
})}
|
||||
<button type="button" className="button copy-list-add" onClick={onAdd}>{t('copies.add')}</button>
|
||||
</div>
|
||||
</Sheet>
|
||||
);
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import type { InstallRecord } from '@shared/schemas/install.ts';
|
||||
import { Row } from '../../components/Row.tsx';
|
||||
@@ -10,13 +11,14 @@ interface CopySummaryProps {
|
||||
readonly record: InstallRecord;
|
||||
readonly supportedVersions: readonly string[];
|
||||
readonly onShowFeatures: () => void;
|
||||
readonly onReinstall: () => void;
|
||||
readonly onError: (error: unknown) => void;
|
||||
}
|
||||
|
||||
/** What is installed where: version, adaptation, folders, installation type. */
|
||||
export function CopySummary({ record, supportedVersions, onShowFeatures, onReinstall, onError }: CopySummaryProps) {
|
||||
export function CopySummary({ record, supportedVersions, onShowFeatures, onError }: CopySummaryProps) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const [name, setName] = useState(record.name);
|
||||
useEffect(() => setName(record.name), [record.id, record.name]);
|
||||
const missing = missingFeatures(record).length;
|
||||
const verified = isVerified(record.gameVersion, supportedVersions);
|
||||
const folder = (path: string) => (
|
||||
@@ -26,10 +28,13 @@ export function CopySummary({ record, supportedVersions, onShowFeatures, onReins
|
||||
</>
|
||||
);
|
||||
return (
|
||||
<Sheet
|
||||
title={t('copies.sections.summary')}
|
||||
foot={<button type="button" className="button" onClick={onReinstall}>{t('copies.reinstall')}</button>}
|
||||
>
|
||||
<Sheet title={t('copies.sections.summary')} aside={record.name}>
|
||||
<Row label={t('copies.summary.name')}>
|
||||
<input className="input" aria-label={t('copies.summary.name')} value={name} onChange={(event) => setName(event.target.value)} />
|
||||
<button type="button" className="button" disabled={name.trim().length === 0 || name.trim() === record.name} onClick={() => {
|
||||
ipcInvoke('copies:rename', { id: record.id, name }).catch(onError);
|
||||
}}>{t('copies.summary.rename')}</button>
|
||||
</Row>
|
||||
<Row label={t('copies.summary.version')}>{record.gameVersion ?? t('source.versionUnknown')}</Row>
|
||||
<Row label={t('copies.summary.adaptation')} hint={t('copies.summary.adaptationHint')}>
|
||||
{adaptationFor(record.gameVersion, supportedVersions) ?? t('source.versionUnknown')}
|
||||
@@ -37,6 +42,7 @@ export function CopySummary({ record, supportedVersions, onShowFeatures, onReins
|
||||
</Row>
|
||||
<Row label={t('copies.summary.location')}>{folder(record.copyPath)}</Row>
|
||||
<Row label={t('copies.summary.method')}>{t(`copies.summary.methods.${record.method}`)}</Row>
|
||||
{record.sourcePath && <Row label={t('copies.summary.source')}>{folder(record.sourcePath)}</Row>}
|
||||
<Row label={t('copies.summary.stock')} hint={t('copies.summary.stockHint')}>{folder(record.stockBackupPath)}</Row>
|
||||
<Row label={t('copies.summary.data')} hint={t('copies.summary.dataHint')}>{folder(record.dataPath)}</Row>
|
||||
<Row label={t('copies.summary.installedAt')}>{new Date(record.installedAt).toLocaleString(i18n.language)}</Row>
|
||||
|
||||
@@ -8,7 +8,7 @@ export function HomeMain({ record }: { readonly record: InstallRecord | null })
|
||||
return (
|
||||
<div className="hero">
|
||||
<div className="hero-kicker">{t('home.installedKicker', { version: record.gameVersion ?? t('source.versionUnknown') })}</div>
|
||||
<h1 className="hero-title">{t('app.title')}</h1>
|
||||
<h1 className="hero-title">{record.name}</h1>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import type { InstallRecord } from '@shared/schemas/install.ts';
|
||||
import type { Destination } from '../../shell/navigation.ts';
|
||||
@@ -6,13 +7,16 @@ import { missingFeatures } from '../copies/missing-features.ts';
|
||||
|
||||
interface HomeSideProps {
|
||||
readonly record: InstallRecord | null;
|
||||
readonly copies: readonly InstallRecord[];
|
||||
readonly onSelectCopy: (id: string) => void;
|
||||
readonly supportedVersions: readonly string[];
|
||||
readonly onNavigate: (to: Destination) => void;
|
||||
}
|
||||
|
||||
/** The side panel of the home and about pages: requirements before installation, the current copy after. */
|
||||
export function HomeSide({ record, supportedVersions, onNavigate }: HomeSideProps) {
|
||||
export function HomeSide({ record, copies, supportedVersions, onNavigate, onSelectCopy }: HomeSideProps) {
|
||||
const { t } = useTranslation();
|
||||
const [choosingCopy, setChoosingCopy] = useState(false);
|
||||
if (!record) {
|
||||
return (
|
||||
<>
|
||||
@@ -35,10 +39,22 @@ export function HomeSide({ record, supportedVersions, onNavigate }: HomeSideProp
|
||||
return (
|
||||
<>
|
||||
<h3 className="side-heading">{t('side.currentCopy')}</h3>
|
||||
<div className="copy-card">
|
||||
<div className="copy-card-name">{t('side.copyName')}</div>
|
||||
<div className="copy-card-meta" title={record.copyPath}>{record.gameVersion ?? t('source.versionUnknown')} · {record.copyPath}</div>
|
||||
</div>
|
||||
<button type="button" className="copy-card copy-card-button" aria-expanded={choosingCopy} onClick={() => setChoosingCopy(!choosingCopy)}>
|
||||
<span className="copy-card-name">{record.name}</span>
|
||||
<span className="copy-card-meta" title={record.copyPath}>{record.gameVersion ?? t('source.versionUnknown')} · {record.copyPath}</span>
|
||||
</button>
|
||||
{choosingCopy && (
|
||||
<div className="copy-picker">
|
||||
{copies.map((copy) => (
|
||||
<button key={copy.id} type="button" className="button" disabled={copy.id === record.id} onClick={() => {
|
||||
setChoosingCopy(false);
|
||||
onSelectCopy(copy.id);
|
||||
}}>
|
||||
{copy.name} · {copy.gameVersion ?? t('source.versionUnknown')}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<div className="side-block">
|
||||
<dl className="kv">
|
||||
<dt>{t('side.adaptation')}</dt>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Row } from '../../components/Row.tsx';
|
||||
import { Sheet } from '../../components/Sheet.tsx';
|
||||
import { CheckStep } from './CheckStep.tsx';
|
||||
import { DataStep } from './DataStep.tsx';
|
||||
@@ -17,7 +18,12 @@ export function WizardMain({ wizard, supportedVersions }: { readonly wizard: Ins
|
||||
<SourceStep source={source} sourceSize={wizard.sourceSize} supportedVersions={supportedVersions} onSource={wizard.chooseSource} onError={wizard.report} />
|
||||
)}
|
||||
{step === 'method' && sourceUsable(source) && (
|
||||
<MethodStep source={source} sourceSize={wizard.sourceSize} choice={wizard.choice} onChoice={wizard.setChoice} onError={wizard.report} />
|
||||
<>
|
||||
<Row label={t('copies.summary.name')}>
|
||||
<input className="input" aria-label={t('copies.summary.name')} value={wizard.name} onChange={(event) => wizard.setName(event.target.value)} />
|
||||
</Row>
|
||||
<MethodStep source={source} sourceSize={wizard.sourceSize} choice={wizard.choice} onChoice={wizard.setChoice} onError={wizard.report} />
|
||||
</>
|
||||
)}
|
||||
{step === 'data' && <DataStep dataPath={wizard.dataPath} onDataPath={wizard.setDataPath} onError={wizard.report} />}
|
||||
{step === 'check' && <CheckStep check={wizard.check} missingAccepted={wizard.missingAccepted} onMissingAccepted={wizard.setMissingAccepted} />}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import type { FolderSize, GameFolderInspection, InstallProgress, InstallRecord, InstallRequest, PatchCheck } from '@shared/schemas/install.ts';
|
||||
import type { FolderSize, GameFolderInspection, InstallProgress, InstallRequest, PatchCheck } from '@shared/schemas/install.ts';
|
||||
import { ipcInvoke, ipcOn } from '../../ipc.ts';
|
||||
import { useErrorMessage } from '../../useErrorMessage.ts';
|
||||
import { checkUsable } from './CheckStep.tsx';
|
||||
@@ -12,8 +12,7 @@ export type WizardStep = (typeof WIZARD_STEPS)[number];
|
||||
const NO_CHOICE: MethodChoice = { method: 'copy', target: null, steamConfirmed: false };
|
||||
|
||||
interface WizardOptions {
|
||||
readonly defaultDataPath: string;
|
||||
readonly onInstalled: (record: InstallRecord) => void;
|
||||
readonly onInstalled: () => void;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -21,14 +20,16 @@ interface WizardOptions {
|
||||
* the side panel, the current step in the main area, and back / next in the bottom bar. The work
|
||||
* is done by the main process over IPC.
|
||||
*/
|
||||
export function useInstallWizard({ defaultDataPath, onInstalled }: WizardOptions) {
|
||||
export function useInstallWizard({ onInstalled }: WizardOptions) {
|
||||
const { message, report, clear } = useErrorMessage();
|
||||
const [active, setActive] = useState(false);
|
||||
const [step, setStep] = useState<WizardStep>('source');
|
||||
const [source, setSource] = useState<GameFolderInspection | null>(null);
|
||||
const [sourceSize, setSourceSize] = useState<FolderSize | null>(null);
|
||||
const [choice, setChoice] = useState<MethodChoice>(NO_CHOICE);
|
||||
const [dataPath, setDataPath] = useState(defaultDataPath);
|
||||
const [draftId, setDraftId] = useState<string | null>(null);
|
||||
const [name, setName] = useState('');
|
||||
const [dataPath, setDataPath] = useState('');
|
||||
const [check, setCheck] = useState<PatchCheck | null>(null);
|
||||
const [missingAccepted, setMissingAccepted] = useState(false);
|
||||
const [progress, setProgress] = useState<InstallProgress | null>(null);
|
||||
@@ -70,17 +71,27 @@ export function useInstallWizard({ defaultDataPath, onInstalled }: WizardOptions
|
||||
const start = (): void => {
|
||||
clear();
|
||||
setStep('source');
|
||||
setSource(null);
|
||||
setChoice(NO_CHOICE);
|
||||
setName('');
|
||||
setDraftId(null);
|
||||
setDataPath('');
|
||||
setActive(true);
|
||||
ipcInvoke('install:prepareCopy').then(({ id, dataPath: folder }) => {
|
||||
setDraftId(id);
|
||||
setDataPath(folder);
|
||||
}).catch(report);
|
||||
};
|
||||
|
||||
const chooseSource = (found: GameFolderInspection | null): void => {
|
||||
setSource(found);
|
||||
setChoice(NO_CHOICE);
|
||||
setName(found?.path.split(/[\\/]/).filter(Boolean).at(-1) ?? '');
|
||||
};
|
||||
|
||||
const install = (): void => {
|
||||
if (!sourceUsable(source)) return;
|
||||
const choices = { dataPath, steamLibraryConfirmed: choice.steamConfirmed, missingFeaturesAccepted: missingAccepted };
|
||||
if (!sourceUsable(source) || !draftId) return;
|
||||
const choices = { id: draftId, name, dataPath, steamLibraryConfirmed: choice.steamConfirmed, missingFeaturesAccepted: missingAccepted };
|
||||
const request: InstallRequest = choice.method === 'copy'
|
||||
? { method: 'copy', sourcePath: source.path, copyPath: choice.target!.path, ...choices }
|
||||
: { method: 'in-place', gamePath: source.path, ...choices };
|
||||
@@ -89,9 +100,9 @@ export function useInstallWizard({ defaultDataPath, onInstalled }: WizardOptions
|
||||
setCancelling(false);
|
||||
setStep('installing');
|
||||
ipcInvoke('install:start', request)
|
||||
.then((record) => {
|
||||
.then(() => {
|
||||
setActive(false);
|
||||
onInstalled(record);
|
||||
onInstalled();
|
||||
})
|
||||
.catch((error: unknown) => {
|
||||
report(error);
|
||||
@@ -101,8 +112,8 @@ export function useInstallWizard({ defaultDataPath, onInstalled }: WizardOptions
|
||||
|
||||
const canGoOn = ((): boolean => {
|
||||
switch (step) {
|
||||
case 'source': return sourceUsable(source);
|
||||
case 'method': return sourceUsable(source) && methodUsable(source, sourceSize, choice);
|
||||
case 'source': return draftId !== null && sourceUsable(source);
|
||||
case 'method': return name.trim().length > 0 && sourceUsable(source) && methodUsable(source, sourceSize, choice);
|
||||
case 'data': return dataPath.length > 0;
|
||||
case 'check': return checkUsable(check, missingAccepted);
|
||||
case 'installing': return false;
|
||||
@@ -130,8 +141,8 @@ export function useInstallWizard({ defaultDataPath, onInstalled }: WizardOptions
|
||||
};
|
||||
|
||||
return {
|
||||
active, step, index, source, sourceSize, choice, dataPath, check, missingAccepted, progress, cancelling, message, canGoOn,
|
||||
start, back, next, cancel, report, chooseSource, setChoice, setDataPath, setMissingAccepted,
|
||||
active, step, index, source, sourceSize, choice, name, dataPath, check, missingAccepted, progress, cancelling, message, canGoOn,
|
||||
start, back, next, cancel, report, chooseSource, setChoice, setName, setDataPath, setMissingAccepted,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -4,17 +4,17 @@ interface FooterProps {
|
||||
readonly launcherVersion: string;
|
||||
/** The installed copy's game version; null before installation, or when it is unknown. */
|
||||
readonly gameVersion: string | null;
|
||||
readonly installed: boolean;
|
||||
readonly copyName: string | null;
|
||||
}
|
||||
|
||||
/** Launcher and game versions along the bottom edge. */
|
||||
export function Footer({ launcherVersion, gameVersion, installed }: FooterProps) {
|
||||
export function Footer({ launcherVersion, gameVersion, copyName }: FooterProps) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<footer className="footer">
|
||||
<span>{t('footer.launcher', { version: launcherVersion })}</span>
|
||||
<span className="footer-separator">|</span>
|
||||
<span>{installed ? t('footer.game', { version: gameVersion ?? t('source.versionUnknown') }) : t('footer.notInstalled')}</span>
|
||||
<span>{copyName ? t('footer.game', { name: copyName, version: gameVersion ?? t('source.versionUnknown') }) : t('footer.notInstalled')}</span>
|
||||
</footer>
|
||||
);
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
export const PAGES = ['home', 'copies', 'settings', 'about'] as const;
|
||||
export type PageId = (typeof PAGES)[number];
|
||||
|
||||
export const COPY_SECTIONS = ['summary', 'features'] as const;
|
||||
export const COPY_SECTIONS = ['list', 'summary', 'features'] as const;
|
||||
export type CopySection = (typeof COPY_SECTIONS)[number];
|
||||
|
||||
export const SETTINGS_SECTIONS = ['general', 'launch', 'diag', 'dev'] as const;
|
||||
@@ -18,7 +18,7 @@ export interface Route {
|
||||
readonly settings: SettingsSection;
|
||||
}
|
||||
|
||||
export const START_ROUTE: Route = { page: 'home', copies: 'summary', settings: 'general' };
|
||||
export const START_ROUTE: Route = { page: 'home', copies: 'list', settings: 'general' };
|
||||
|
||||
/** Where a link points: a page, and for pages with sections, which one. */
|
||||
export type Destination =
|
||||
|
||||
@@ -225,6 +225,66 @@
|
||||
color: var(--text-dim);
|
||||
}
|
||||
|
||||
/* ===== Copies ===== */
|
||||
.copy-card-button {
|
||||
display: block;
|
||||
min-width: 0;
|
||||
font: inherit;
|
||||
color: inherit;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.copy-card-button span {
|
||||
display: block;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.copy-picker {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
gap: 6px;
|
||||
max-height: 260px;
|
||||
margin: 0 20px 12px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.copy-picker .button {
|
||||
text-align: left;
|
||||
white-space: normal;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.copy-list {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.copy-list-card {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
padding: 12px;
|
||||
border: 1px solid var(--line);
|
||||
background: rgba(0, 0, 0, .14);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.copy-list-current {
|
||||
border-color: var(--red);
|
||||
}
|
||||
|
||||
.copy-list-heading, .copy-list-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.copy-list-add {
|
||||
min-height: 84px;
|
||||
}
|
||||
|
||||
/* ===== About ===== */
|
||||
.about-head {
|
||||
display: flex;
|
||||
|
||||
@@ -539,6 +539,13 @@
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.footer span:last-child {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.footer-separator {
|
||||
opacity: 0.5;
|
||||
}
|
||||
Reference in new issue
Block a user