feat(updates): verify and install launcher releases
Check the versioned release channel, verify the signed manifest and installer digest, and open the installer only after confirmation. Verified type checks, the Windows package, and an upgrade handoff from a local release fixture, including tampering and interrupted downloads.
This commit is contained in:
1 parent
31b38518f8
commit
746b74c564
24 files changed
+638
-28
No files matched your search
@@ -34,6 +34,7 @@ import { COPY_SECTIONS, navigate, SAVE_SECTIONS, SETTINGS_SECTIONS, START_ROUTE,
|
||||
import { SubNav } from './shell/SubNav.tsx';
|
||||
import { TitleBar } from './shell/TitleBar.tsx';
|
||||
import { useBackgrounds } from './shell/useBackgrounds.ts';
|
||||
import { useAppUpdate } from './shell/useAppUpdate.ts';
|
||||
import { usePatchPack } from './shell/usePatchPack.ts';
|
||||
import { useErrorMessage } from './useErrorMessage.ts';
|
||||
|
||||
@@ -64,6 +65,7 @@ export function App({ info, initialSettings, initialCopies }: AppProps) {
|
||||
const [route, setRoute] = useState<Route>(START_ROUTE);
|
||||
// The setting as the window opened: turning it on later does not check right away.
|
||||
const patchPack = usePatchPack(initialSettings.checkPatchPacksOnStart, report);
|
||||
const appUpdate = useAppUpdate(info.appUpdatesSupported, initialSettings.checkLauncherUpdatesOnStart, report);
|
||||
const supported = patchPack.active?.gameVersions ?? info.supportedGameVersions;
|
||||
|
||||
const wizard = useInstallWizard({ onInstalled: () => setRoute(START_ROUTE) });
|
||||
@@ -120,11 +122,11 @@ export function App({ info, initialSettings, initialCopies }: AppProps) {
|
||||
bar: home,
|
||||
};
|
||||
case 'about':
|
||||
return { side: homeSide, main: <AboutPage launcherVersion={info.version} supportedVersions={supported} patchPack={patchPack} />, bar: home };
|
||||
return { side: homeSide, main: <AboutPage launcherVersion={info.version} supportedVersions={supported} patchPack={patchPack} appUpdate={appUpdate} />, bar: home };
|
||||
case 'settings': {
|
||||
const sections = SETTINGS_SECTIONS.filter((section) => info.development || section !== 'dev');
|
||||
const content = {
|
||||
general: <GeneralSettings settings={settings} pictures={backgrounds.pictures} onError={report} />,
|
||||
general: <GeneralSettings settings={settings} appUpdatesSupported={info.appUpdatesSupported} pictures={backgrounds.pictures} onError={report} />,
|
||||
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} />,
|
||||
@@ -195,7 +197,8 @@ export function App({ info, initialSettings, initialCopies }: AppProps) {
|
||||
gameVersion={record?.gameVersion ?? null}
|
||||
copyName={record?.name ?? null}
|
||||
packUpdate={patchPack.check?.status === 'available' ? (patchPack.check.latest?.version ?? null) : null}
|
||||
onOpenPackUpdate={() => go({ page: 'about' })}
|
||||
appUpdate={appUpdate.check?.status === 'available' ? appUpdate.check.release.version : null}
|
||||
onOpenUpdates={() => go({ page: 'about' })}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -25,7 +25,8 @@
|
||||
"launcher": "Launcher {{version}}",
|
||||
"game": "{{name}} · Game {{version}}",
|
||||
"notInstalled": "Not installed",
|
||||
"packUpdate": "Adaptation pack {{version}} available · Update ›"
|
||||
"packUpdate": "Adaptation pack {{version}} available · Update ›",
|
||||
"appUpdate": "Launcher {{version}} available · Update ›"
|
||||
},
|
||||
"home": {
|
||||
"kicker": "Local server · AI battles",
|
||||
@@ -440,6 +441,8 @@
|
||||
"dev": "Developer",
|
||||
"diag": "Diagnostics"
|
||||
},
|
||||
"appUpdates": "Launcher updates",
|
||||
"appUpdatesToggle": "Check for launcher updates at start",
|
||||
"patchPacks": "Adaptation pack updates",
|
||||
"patchPacksHint": "After a game update, the patches for the new version are released on GitHub as an adaptation pack.",
|
||||
"patchPacksToggle": "Check for a new adaptation pack at start",
|
||||
@@ -551,6 +554,23 @@
|
||||
"up_to_date": "Up to date: there is no adaptation pack to download."
|
||||
}
|
||||
},
|
||||
"update": {
|
||||
"title": "Launcher update",
|
||||
"check": "Launcher version check",
|
||||
"checking": "Checking…",
|
||||
"current": "The launcher is up to date.",
|
||||
"available": "Version {{version}} is available. Installer size {{size}}.",
|
||||
"downloading": "Downloading the installer…",
|
||||
"download": "Download update",
|
||||
"install": "Quit and install",
|
||||
"installing": "Opening the installer…",
|
||||
"errors": {
|
||||
"network": "GitHub Releases could not be reached.",
|
||||
"contents": "The launcher release information is invalid.",
|
||||
"signature": "The launcher update signature could not be verified.",
|
||||
"no_signing_key": "The launcher update verification key is unavailable."
|
||||
}
|
||||
},
|
||||
"statement": "Project information",
|
||||
"statementBody": "WTOffline is a noncommercial hobby project independent of Gaijin. Running it requires your own War Thunder base game files."
|
||||
},
|
||||
@@ -588,6 +608,12 @@
|
||||
"L-Battle awards": "Battle awards"
|
||||
},
|
||||
"errors": {
|
||||
"app_update_unavailable": "There is no launcher update available to install.",
|
||||
"app_update_busy": "A launcher update operation is already in progress.",
|
||||
"app_update_launcher_busy": "Close the game and local server and finish any copy or save operations before updating.",
|
||||
"app_update_download_failed": "The launcher installer could not be downloaded and verified. See the launcher log.",
|
||||
"app_update_installer_invalid": "The installer failed verification. Download it again.",
|
||||
"app_update_install_failed": "The launcher installer could not be opened. See the launcher log.",
|
||||
"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.",
|
||||
|
||||
@@ -25,7 +25,8 @@
|
||||
"launcher": "启动器 {{version}}",
|
||||
"game": "{{name}} · 游戏 {{version}}",
|
||||
"notInstalled": "未安装",
|
||||
"packUpdate": "适配包 {{version}} 可用 · 更新 ›"
|
||||
"packUpdate": "适配包 {{version}} 可用 · 更新 ›",
|
||||
"appUpdate": "本体 {{version}} 可用 · 更新 ›"
|
||||
},
|
||||
"home": {
|
||||
"kicker": "本地服务器 · AI 对局",
|
||||
@@ -440,6 +441,8 @@
|
||||
"dev": "开发者",
|
||||
"diag": "诊断"
|
||||
},
|
||||
"appUpdates": "启动器本体更新",
|
||||
"appUpdatesToggle": "启动时检查本体更新",
|
||||
"patchPacks": "适配包更新",
|
||||
"patchPacksHint": "游戏更新后,新版本的补丁会以适配包的形式发布在 GitHub 上。",
|
||||
"patchPacksToggle": "启动时检查有没有新的适配包",
|
||||
@@ -551,6 +554,23 @@
|
||||
"up_to_date": "已是最新,没有需要下载的适配包。"
|
||||
}
|
||||
},
|
||||
"update": {
|
||||
"title": "本体更新",
|
||||
"check": "检查本体版本",
|
||||
"checking": "正在检查…",
|
||||
"current": "当前已是最新版本。",
|
||||
"available": "版本 {{version}} 可用,安装包 {{size}}。",
|
||||
"downloading": "正在下载安装包…",
|
||||
"download": "下载更新",
|
||||
"install": "退出并安装",
|
||||
"installing": "正在打开安装包…",
|
||||
"errors": {
|
||||
"network": "暂时无法访问 GitHub 发布页。",
|
||||
"contents": "本体更新的发布信息无效。",
|
||||
"signature": "本体更新签名校验失败。",
|
||||
"no_signing_key": "本体更新公钥不可用。"
|
||||
}
|
||||
},
|
||||
"statement": "项目信息",
|
||||
"statementBody": "WTOffline 是一个独立于 Gaijin 的非商业兴趣项目。运行需要自备战争雷霆游戏本体文件。"
|
||||
},
|
||||
@@ -588,6 +608,12 @@
|
||||
"L-Battle awards": "战斗嘉奖"
|
||||
},
|
||||
"errors": {
|
||||
"app_update_unavailable": "当前没有可安装的本体更新。",
|
||||
"app_update_busy": "本体更新操作正在进行。",
|
||||
"app_update_launcher_busy": "请在游戏退出、服务器关闭及副本和存档操作完成后安装更新。",
|
||||
"app_update_download_failed": "无法下载并验证本体安装包。请查看启动器日志。",
|
||||
"app_update_installer_invalid": "安装包校验失败。请重新下载。",
|
||||
"app_update_install_failed": "无法打开本体安装包。请查看启动器日志。",
|
||||
"internal_error": "启动器内部错误。",
|
||||
"logs_folder_open_failed": "无法打开启动器日志文件夹。",
|
||||
"diagnostics_export_failed": "无法保存诊断信息。",
|
||||
|
||||
@@ -2,16 +2,19 @@ import { useTranslation } from 'react-i18next';
|
||||
import { Notice } from '../../components/Notice.tsx';
|
||||
import { Row } from '../../components/Row.tsx';
|
||||
import { Sheet } from '../../components/Sheet.tsx';
|
||||
import type { AppUpdateState } from '../../shell/useAppUpdate.ts';
|
||||
import { AppUpdateSection } from './AppUpdateSection.tsx';
|
||||
import type { PatchPackState } from '../../shell/usePatchPack.ts';
|
||||
|
||||
interface AboutPageProps {
|
||||
readonly launcherVersion: string;
|
||||
readonly supportedVersions: readonly string[];
|
||||
readonly patchPack: PatchPackState;
|
||||
readonly appUpdate: AppUpdateState;
|
||||
}
|
||||
|
||||
/** The launcher's version, the game versions it supports, adaptation pack updates, and the project statement. */
|
||||
export function AboutPage({ launcherVersion, supportedVersions, patchPack }: AboutPageProps) {
|
||||
export function AboutPage({ launcherVersion, supportedVersions, patchPack, appUpdate }: AboutPageProps) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<Sheet title={t('nav.about')}>
|
||||
@@ -23,6 +26,7 @@ export function AboutPage({ launcherVersion, supportedVersions, patchPack }: Abo
|
||||
{t('about.supported', { versions: supportedVersions.join(', ') })}
|
||||
</div>
|
||||
</div>
|
||||
<AppUpdateSection state={appUpdate} />
|
||||
<PatchPackSection state={patchPack} />
|
||||
<h3 className="section-title section-title-spaced">{t('about.statement')}</h3>
|
||||
<p className="lead">{t('about.statementBody')}</p>
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Notice } from '../../components/Notice.tsx';
|
||||
import { ProgressBar } from '../../components/ProgressBar.tsx';
|
||||
import { Row } from '../../components/Row.tsx';
|
||||
import { formatBytes } from '../../format.ts';
|
||||
import type { AppUpdateState } from '../../shell/useAppUpdate.ts';
|
||||
|
||||
export function AppUpdateSection({ state }: { readonly state: AppUpdateState }) {
|
||||
const { t } = useTranslation();
|
||||
if (!state.supported) return null;
|
||||
const { check, busy, progress } = state;
|
||||
return (
|
||||
<>
|
||||
<h3 className="section-title">{t('about.update.title')}</h3>
|
||||
<Row label={t('about.update.check')}>
|
||||
<button type="button" className="button" disabled={busy !== null} onClick={state.checkNow}>
|
||||
{t(busy === 'checking' ? 'about.update.checking' : 'about.pack.checkButton')}
|
||||
</button>
|
||||
</Row>
|
||||
{check?.status === 'current' && busy !== 'checking' && <Notice tone="info"><p>{t('about.update.current')}</p></Notice>}
|
||||
{check?.status === 'failed' && busy !== 'checking' && <Notice tone="error"><p>{t(`about.update.errors.${check.problem}`)}</p></Notice>}
|
||||
{check?.status === 'available' && busy !== 'checking' && (
|
||||
<Notice tone="info">
|
||||
<p>{t('about.update.available', { version: check.release.version, size: formatBytes(check.release.size) })}</p>
|
||||
{check.release.notes && <p className="small update-notes">{check.release.notes}</p>}
|
||||
{busy === 'downloading' ? (
|
||||
<>
|
||||
<p>{t('about.update.downloading')}</p>
|
||||
<ProgressBar value={progress?.received ?? 0} max={progress?.total ?? null} />
|
||||
</>
|
||||
) : (
|
||||
<button
|
||||
type="button"
|
||||
className="button button-primary"
|
||||
disabled={busy !== null}
|
||||
onClick={() => {
|
||||
if (check.ready) state.install(check.release.version);
|
||||
else state.download(check.release.version);
|
||||
}}
|
||||
>
|
||||
{t(busy === 'installing' ? 'about.update.installing' : check.ready ? 'about.update.install' : 'about.update.download')}
|
||||
</button>
|
||||
)}
|
||||
</Notice>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -9,12 +9,13 @@ import { LanguageMenu } from '../../shell/LanguageMenu.tsx';
|
||||
|
||||
interface GeneralSettingsProps {
|
||||
readonly settings: Settings;
|
||||
readonly appUpdatesSupported: boolean;
|
||||
readonly pictures: readonly BackgroundPicture[];
|
||||
readonly onError: (error: unknown) => void;
|
||||
}
|
||||
|
||||
/** General launcher settings: language and background picture. */
|
||||
export function GeneralSettings({ settings, pictures, onError }: GeneralSettingsProps) {
|
||||
export function GeneralSettings({ settings, appUpdatesSupported, pictures, onError }: GeneralSettingsProps) {
|
||||
const { t } = useTranslation();
|
||||
const update = (patch: Partial<Settings>): void => {
|
||||
ipcInvoke('settings:update', patch).catch(onError);
|
||||
@@ -56,6 +57,14 @@ export function GeneralSettings({ settings, pictures, onError }: GeneralSettings
|
||||
{t('background.officialToggle')}
|
||||
</label>
|
||||
</Row>
|
||||
{appUpdatesSupported && (
|
||||
<Row label={t('settings.appUpdates')}>
|
||||
<label className="check check-inline">
|
||||
<input type="checkbox" checked={settings.checkLauncherUpdatesOnStart} onChange={(event) => update({ checkLauncherUpdatesOnStart: event.target.checked })} />
|
||||
{t('settings.appUpdatesToggle')}
|
||||
</label>
|
||||
</Row>
|
||||
)}
|
||||
<Row label={t('settings.patchPacks')} hint={t('settings.patchPacksHint')}>
|
||||
<label className="check check-inline">
|
||||
<input type="checkbox" checked={settings.checkPatchPacksOnStart} onChange={(event) => update({ checkPatchPacksOnStart: event.target.checked })} />
|
||||
|
||||
@@ -7,21 +7,31 @@ interface FooterProps {
|
||||
readonly copyName: string | null;
|
||||
/** A newer adaptation pack that this launcher can use, or null. */
|
||||
readonly packUpdate: string | null;
|
||||
readonly onOpenPackUpdate: () => void;
|
||||
readonly appUpdate: string | null;
|
||||
readonly onOpenUpdates: () => void;
|
||||
}
|
||||
|
||||
/** Launcher and game versions along the bottom edge; on the right, an available adaptation pack. */
|
||||
export function Footer({ launcherVersion, gameVersion, copyName, packUpdate, onOpenPackUpdate }: FooterProps) {
|
||||
/** Launcher and game versions along the bottom edge; on the right, available updates. */
|
||||
export function Footer({ launcherVersion, gameVersion, copyName, packUpdate, appUpdate, onOpenUpdates }: FooterProps) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<footer className="footer">
|
||||
<span>{t('footer.launcher', { version: launcherVersion })}</span>
|
||||
<span className="footer-separator">|</span>
|
||||
<span className="footer-copy">{copyName ? t('footer.game', { name: copyName, version: gameVersion ?? t('source.versionUnknown') }) : t('footer.notInstalled')}</span>
|
||||
{packUpdate && (
|
||||
<button type="button" className="footer-update" onClick={onOpenPackUpdate}>
|
||||
{t('footer.packUpdate', { version: packUpdate })}
|
||||
</button>
|
||||
{(appUpdate || packUpdate) && (
|
||||
<div className="footer-updates">
|
||||
{appUpdate && (
|
||||
<button type="button" className="footer-update" onClick={onOpenUpdates}>
|
||||
{t('footer.appUpdate', { version: appUpdate })}
|
||||
</button>
|
||||
)}
|
||||
{packUpdate && (
|
||||
<button type="button" className="footer-update" onClick={onOpenUpdates}>
|
||||
{t('footer.packUpdate', { version: packUpdate })}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</footer>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import type { AppUpdateCheck, AppUpdateProgress } from '@shared/schemas/app-update.ts';
|
||||
import { AppIpcError, ipcInvoke, ipcOn } from '../ipc.ts';
|
||||
|
||||
export function useAppUpdate(supported: boolean, checkOnStart: boolean, onError: (error: unknown) => void) {
|
||||
const [check, setCheck] = useState<AppUpdateCheck | null>(null);
|
||||
const [progress, setProgress] = useState<AppUpdateProgress | null>(null);
|
||||
const [busy, setBusy] = useState<'checking' | 'downloading' | 'installing' | null>(null);
|
||||
const started = useRef(false);
|
||||
|
||||
useEffect(() => ipcOn('event:app-update-progress', setProgress), []);
|
||||
|
||||
const checkNow = useCallback(() => {
|
||||
setBusy('checking');
|
||||
ipcInvoke('updates:check').then(setCheck).catch(onError).finally(() => setBusy(null));
|
||||
}, [onError]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!supported || !checkOnStart || started.current) return;
|
||||
started.current = true;
|
||||
checkNow();
|
||||
}, [supported, checkOnStart, checkNow]);
|
||||
|
||||
const download = (version: string): void => {
|
||||
setProgress(null);
|
||||
setBusy('downloading');
|
||||
ipcInvoke('updates:download', { version }).then(setCheck).catch(onError).finally(() => setBusy(null));
|
||||
};
|
||||
|
||||
const install = (version: string): void => {
|
||||
setBusy('installing');
|
||||
ipcInvoke('updates:install', { version }).catch((error: unknown) => {
|
||||
if (error instanceof AppIpcError && error.code === 'app_update_installer_invalid') {
|
||||
setCheck((previous) => previous?.status === 'available' ? { ...previous, ready: false } : previous);
|
||||
}
|
||||
onError(error);
|
||||
}).finally(() => setBusy(null));
|
||||
};
|
||||
|
||||
return { supported, check, progress, busy, checkNow, download, install };
|
||||
}
|
||||
|
||||
export type AppUpdateState = ReturnType<typeof useAppUpdate>;
|
||||
@@ -312,6 +312,11 @@
|
||||
}
|
||||
|
||||
/* ===== About ===== */
|
||||
.update-notes {
|
||||
white-space: pre-line;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.about-head {
|
||||
display: flex;
|
||||
gap: 18px;
|
||||
|
||||
@@ -550,10 +550,15 @@
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
/* An available adaptation pack, at the right end. */
|
||||
.footer-update {
|
||||
/* Available updates at the right end. */
|
||||
.footer-updates {
|
||||
margin-left: auto;
|
||||
display: flex;
|
||||
flex: none;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.footer-update {
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: none;
|
||||
|
||||
Reference in new issue
Block a user