feat(launcher): add maintenance for installed game copies

This commit is contained in:
N0VAN0M4LY committed 2026-11-29 15:24:21 +08:00
1 parent 7d68dc0548
commit ef3648cb13
17 files changed
+672 -24

No files matched your search

+4
View File
@@ -8,6 +8,7 @@ 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 { CopyMaintenance } from './pages/copies/CopyMaintenance.tsx';
import { CopyList } from './pages/copies/CopyList.tsx';
import { CopySummary } from './pages/copies/CopySummary.tsx';
import { FeatureStatus } from './pages/copies/FeatureStatus.tsx';
@@ -145,6 +146,9 @@ export function App({ info, initialSettings, initialCopies }: AppProps) {
bar: home,
};
}
if (route.copies === 'maintain') {
return { side, main: <CopyMaintenance key={record.id} record={record} onError={report} />, bar: home };
}
const main = route.copies === 'features'
? <FeatureStatus record={record} supportedVersions={supported} onError={report} />
: <CopySummary record={record} supportedVersions={supported} onShowFeatures={() => go({ page: 'copies', section: 'features' })} onError={report} />;
@@ -166,11 +166,43 @@
"sections": {
"list": "All copies",
"summary": "Copy details",
"features": "Feature status"
"features": "Feature status",
"maintain": "Maintenance"
},
"add": "Add a copy",
"list": { "current": "Current", "select": "Set as current" },
"none": "The offline edition is not installed yet.",
"maintenance": {
"update": "Update from official installation",
"updateAction": "Update copy",
"newVersion": "Version {{version}} is available from the installation source.",
"currentVersion": "Installation source version {{version}}",
"noSource": "Installation source unavailable",
"check": "Recheck patches",
"checkHint": "Check the original file backup.",
"lastCheck": "Last checked {{date}}",
"repair": "Repair copy",
"repairAction": "Repair",
"repairHint": "Restore the original files from the backup. Game files will be generated again at launch.",
"delete": "Delete copy",
"deleteAction": "Delete…",
"deleteHint": "The data folder is kept by default.",
"deleteLocation": "Delete the game copy at {{path}}?",
"deleteData": "Also delete the data folder at {{path}}",
"confirm": "Confirm deletion",
"phase": {
"checking": "Checking the copy",
"copying": "Copying changed files",
"applying": "Applying changes"
},
"result": {
"check": "Patch check complete.",
"repair": "Original files restored.",
"update": "Copy updated.",
"delete": "Copy deleted.",
"cancelled": "Update cancelled."
}
},
"summary": {
"name": "Copy name",
"rename": "Rename",
@@ -334,6 +366,12 @@
"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.",
"maintenance_busy": "Maintenance requires the game, local server and other copy operations to be stopped.",
"maintenance_location": "The operation would affect files outside the registered copy or data folder.",
"maintenance_no_update": "A newer version is unavailable at the installation source.",
"maintenance_cancelled": "The copy update was cancelled.",
"maintenance_failed": "Copy maintenance failed. See the launcher log.",
"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_lab_required": "Enable developer mode to launch through the isolated lab.",
@@ -166,11 +166,43 @@
"sections": {
"list": "全部副本",
"summary": "副本详情",
"features": "功能状态"
"features": "功能状态",
"maintain": "维护"
},
"add": "添加副本",
"list": { "current": "当前", "select": "设为当前" },
"none": "尚未安装离线版。",
"maintenance": {
"update": "从正版更新",
"updateAction": "更新副本",
"newVersion": "安装来源已更新至 {{version}}。",
"currentVersion": "安装来源版本 {{version}}",
"noSource": "安装来源不可用",
"check": "重新检查补丁",
"checkHint": "核对原版文件备份。",
"lastCheck": "上次检查 {{date}}",
"repair": "修复副本",
"repairAction": "修复",
"repairHint": "从原版文件备份还原文件。下次启动时重新生成游戏文件。",
"delete": "删除副本",
"deleteAction": "删除…",
"deleteHint": "默认保留数据目录。",
"deleteLocation": "确认删除 {{path}} 中的游戏副本?",
"deleteData": "同时删除 {{path}} 中的数据",
"confirm": "确认删除",
"phase": {
"checking": "正在检查副本",
"copying": "正在复制有变化的文件",
"applying": "正在应用更改"
},
"result": {
"check": "补丁检查已完成。",
"repair": "原版文件已还原。",
"update": "副本已更新。",
"delete": "副本已删除。",
"cancelled": "更新已取消。"
}
},
"summary": {
"name": "副本名称",
"rename": "重命名",
@@ -334,6 +366,12 @@
"copy_not_found": "所选副本已不可用。",
"copies_write_failed": "无法保存副本记录。",
"copy_location_in_use": "副本位置或数据目录与已有副本重叠。",
"maintenance_busy": "维护前需结束游戏、本地服务器和其他副本操作。",
"maintenance_location": "操作会影响登记的副本或数据目录之外的文件。",
"maintenance_no_update": "安装来源没有可用的新版本。",
"maintenance_cancelled": "副本更新已取消。",
"maintenance_failed": "副本维护失败。请查看启动器日志。",
"maintenance_source_changed": "安装来源在更新过程中发生变化。请在正版更新完成后重试。",
"launch_no_copy": "启动前需要安装游戏副本。",
"launch_busy": "启动流程正在运行。",
"launch_lab_required": "请启用开发模式以通过隔离实验副本启动。",
@@ -0,0 +1,113 @@
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import type { InstallRecord } from '@shared/schemas/install.ts';
import type { MaintenanceInfo, MaintenanceProgress, MaintenanceRequest } from '@shared/schemas/maintenance.ts';
import { ProgressBar } from '../../components/ProgressBar.tsx';
import { Row } from '../../components/Row.tsx';
import { Sheet } from '../../components/Sheet.tsx';
import { formatBytes } from '../../format.ts';
import { AppIpcError, ipcInvoke, ipcOn } from '../../ipc.ts';
interface CopyMaintenanceProps {
readonly record: InstallRecord;
readonly onError: (error: unknown) => void;
}
type Operation = MaintenanceRequest['operation'];
export function CopyMaintenance({ record, onError }: CopyMaintenanceProps) {
const { t, i18n } = useTranslation();
const [info, setInfo] = useState<MaintenanceInfo | null>(null);
const [working, setWorking] = useState<Operation | null>(null);
const [progress, setProgress] = useState<MaintenanceProgress | null>(null);
const [confirming, setConfirming] = useState(false);
const [deleteData, setDeleteData] = useState(false);
const [result, setResult] = useState<Operation | 'cancelled' | null>(null);
useEffect(() => {
let mounted = true;
ipcInvoke('copies:maintenanceInfo', { id: record.id }).then((value) => {
if (mounted) setInfo(value);
}).catch(onError);
return () => { mounted = false; };
}, [record.id, record.gameVersion, onError]);
useEffect(() => ipcOn('event:copy-maintenance', (event) => {
if (event.id === record.id) setProgress(event);
}), [record.id]);
const run = (operation: Operation): void => {
setResult(null);
setWorking(operation);
setProgress(null);
ipcInvoke('copies:maintain', { id: record.id, operation, deleteData: operation === 'delete' && deleteData })
.then(() => {
setResult(operation);
setConfirming(false);
})
.catch((error: unknown) => {
if (error instanceof AppIpcError && error.code === 'maintenance_cancelled') setResult('cancelled');
else onError(error);
})
.finally(() => setWorking(null));
};
return (
<Sheet title={t('copies.sections.maintain')} aside={record.name}>
<Row label={t('copies.maintenance.update')} hint={info?.sourceVersion
? t(info.updateAvailable ? 'copies.maintenance.newVersion' : 'copies.maintenance.currentVersion', { version: info.sourceVersion })
: t('copies.maintenance.noSource')}>
<button type="button" className={info?.updateAvailable ? 'button button-primary' : 'button'}
disabled={working !== null || !info?.updateAvailable} onClick={() => run('update')}>
{t('copies.maintenance.updateAction')}
</button>
</Row>
<Row label={t('copies.maintenance.check')} hint={record.lastCheckedAt
? t('copies.maintenance.lastCheck', { date: new Date(record.lastCheckedAt).toLocaleString(i18n.language) })
: t('copies.maintenance.checkHint')}>
<button type="button" className="button" disabled={working !== null} onClick={() => run('check')}>
{t('copies.maintenance.check')}
</button>
</Row>
<Row label={t('copies.maintenance.repair')} hint={t('copies.maintenance.repairHint')}>
<button type="button" className="button" disabled={working !== null} onClick={() => run('repair')}>
{t('copies.maintenance.repairAction')}
</button>
</Row>
<Row label={t('copies.maintenance.delete')} hint={t('copies.maintenance.deleteHint')}>
<button type="button" className="button" disabled={working !== null} onClick={() => {
setConfirming(true);
setDeleteData(false);
}}>{t('copies.maintenance.deleteAction')}</button>
</Row>
{confirming && (
<section className="maintenance-confirm" role="group" aria-label={t('copies.maintenance.confirm')}>
<p>{t('copies.maintenance.deleteLocation', { path: record.copyPath })}</p>
<label className="check">
<input type="checkbox" checked={deleteData} disabled={working !== null} onChange={(event) => setDeleteData(event.target.checked)} />
{t('copies.maintenance.deleteData', { path: record.dataPath })}
</label>
<div className="copy-list-actions">
<button type="button" className="button" disabled={working !== null} onClick={() => setConfirming(false)}>{t('wizard.cancel')}</button>
<button type="button" className="button button-primary" disabled={working !== null} onClick={() => run('delete')}>
{t('copies.maintenance.confirm')}
</button>
</div>
</section>
)}
{working && (
<div className="maintenance-progress" role="status">
<p>{t(`copies.maintenance.phase.${progress?.phase ?? 'checking'}`)}</p>
<ProgressBar value={progress?.doneBytes ?? 0} max={progress?.totalBytes || null} />
{progress?.totalBytes ? <p className="small">{formatBytes(progress.doneBytes)} / {formatBytes(progress.totalBytes)}</p> : null}
{working === 'update' && progress?.phase !== 'applying' && (
<button type="button" className="button" onClick={() => ipcInvoke('copies:cancelMaintenance').catch(onError)}>
{t('wizard.cancel')}
</button>
)}
</div>
)}
{result && <p className="small" role="status">{t(`copies.maintenance.result.${result}`)}</p>}
</Sheet>
);
}
@@ -6,7 +6,7 @@
export const PAGES = ['home', 'copies', 'settings', 'about'] as const;
export type PageId = (typeof PAGES)[number];
export const COPY_SECTIONS = ['list', 'summary', 'features'] as const;
export const COPY_SECTIONS = ['list', 'summary', 'features', 'maintain'] as const;
export type CopySection = (typeof COPY_SECTIONS)[number];
export const SETTINGS_SECTIONS = ['general', 'launch', 'diag', 'dev'] as const;
@@ -285,6 +285,24 @@
min-height: 84px;
}
.maintenance-confirm,
.maintenance-progress {
margin-top: 14px;
padding: 12px;
border: 1px solid var(--line);
overflow-wrap: anywhere;
}
.maintenance-confirm p,
.maintenance-progress p {
margin: 0 0 8px;
}
.maintenance-confirm .copy-list-actions,
.maintenance-progress button {
margin-top: 10px;
}
/* ===== About ===== */
.about-head {
display: flex;