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:
N0VAN0M4LY committed 2026-11-29 15:14:41 +08:00
1 parent e41b73aaa3
commit 7d68dc0548
24 files changed
+408 -97

No files matched your search

@@ -19,6 +19,7 @@ interface LaunchJob {
readonly stop: AbortController;
readonly report: (state: LaunchState) => void;
done: Promise<void>;
copyId?: string;
}
let active: LaunchJob | null = null;
@@ -30,7 +31,7 @@ export function getLaunchState(): LaunchState {
export function startLaunch(report: LaunchJob['report']): LaunchState {
if (active) throw new AppError('launch_busy');
const job = { stop: new AbortController(), report, done: Promise.resolve() };
const job: LaunchJob = { stop: new AbortController(), report, done: Promise.resolve() };
active = job;
update(job, { phase: 'checking' });
job.done = launch(job).catch((error: unknown) => {
@@ -75,14 +76,15 @@ export async function openServerStatus(): Promise<void> {
}
function update(job: LaunchJob, next: LaunchState): void {
state = next;
job.report(next);
state = job.copyId ? { ...next, copyId: job.copyId } : next;
job.report(state);
}
async function launch(job: LaunchJob): Promise<void> {
const signal = job.stop.signal;
const [record, settings] = await Promise.all([readInstallRecord(), getSettings()]);
if (!record) throw new AppError('launch_no_copy');
job.copyId = record.id;
if (!settings.developerMode) throw new AppError('launch_lab_required');
if (isInSteamLibrary(record.copyPath)) throw new AppError('launch_copy_in_steam');
const currentVersion = await readVersion(record.copyPath, signal);