feat(launcher): show official gallery and local game wallpapers

The window background now comes from two sources, served to the window
over a wto-art:// scheme from the launcher's cache:

- Website wallpapers: the newest entries of the public wallpaper gallery
  on warthunder.com (two pages), list refreshed at most daily, each
  1920x1080 picture downloaded when first shown and kept in the cache.
  No cookies, no sign-in; a setting turns it off. Without a connection
  the pictures downloaded before stay available.
- Game pictures: the nation pictures the game's own launcher keeps in
  launcherr.dat next to the game, extracted from the installed copy
  (fflate) once per archive version.

Without either, the window keeps its drawn background. The settings
choose a random picture per start or a fixed one (thumbnail grid); the
home page shows the picture's name with previous / next.

Checked: launcher typecheck, electron-vite build. Ran the window from a
scratch user data folder with a fake copy holding a copy of the real
launcherr.dat: 18 website wallpapers and 9 game pictures listed, both
sizes and the game pictures load through wto-art://, an unknown picture
is refused, stepping saves the choice, turning wallpapers off leaves
the game pictures, no console errors.
This commit is contained in:
N0VAN0M4LY committed 2026-11-29 07:45:26 +08:00
1 parent 81c900a61d
commit d82f9856f6
21 files changed
+693 -8

No files matched your search

+1 -1
View File
@@ -2,7 +2,7 @@
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:" />
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: wto-art:" />
<title>WTOffline</title>
</head>
<body>
+16 -3
View File
@@ -9,6 +9,7 @@ import { ipcOn } from './ipc.ts';
import { AboutPage } from './pages/about/AboutPage.tsx';
import { CopySummary } from './pages/copies/CopySummary.tsx';
import { FeatureStatus } from './pages/copies/FeatureStatus.tsx';
import { BackgroundSwitch } from './pages/home/BackgroundSwitch.tsx';
import { HomeMain } from './pages/home/HomeMain.tsx';
import { HomeSide } from './pages/home/HomeSide.tsx';
import { homeBar } from './pages/home/home-bar.ts';
@@ -24,6 +25,7 @@ import { Footer } from './shell/Footer.tsx';
import { COPY_SECTIONS, navigate, SETTINGS_SECTIONS, START_ROUTE, type Destination, type Route } from './shell/navigation.ts';
import { SubNav } from './shell/SubNav.tsx';
import { TitleBar } from './shell/TitleBar.tsx';
import { useBackgrounds } from './shell/useBackgrounds.ts';
import { useErrorMessage } from './useErrorMessage.ts';
interface AppProps {
@@ -60,6 +62,8 @@ export function App({ info, initialSettings, initialRecord, defaultDataPath }: A
},
});
const backgrounds = useBackgrounds(record?.copyPath ?? null, settings, report);
useEffect(() => ipcOn('event:settings-changed', setSettings), []);
useEffect(() => applyLanguage(resolveLanguage(settings.language, info.systemLocale)), [settings.language, info.systemLocale]);
@@ -73,13 +77,22 @@ export function App({ info, initialSettings, initialRecord, defaultDataPath }: A
const homeSide = <HomeSide record={record} supportedVersions={supported} onNavigate={go} />;
switch (route.page) {
case 'home':
return { side: homeSide, main: <HomeMain record={record} />, bar: home };
return {
side: homeSide,
main: (
<>
<BackgroundSwitch pictures={backgrounds.pictures} shown={backgrounds.shown} onError={report} />
<HomeMain record={record} />
</>
),
bar: home,
};
case 'about':
return { side: homeSide, main: <AboutPage launcherVersion={info.version} supportedVersions={supported} />, bar: home };
case 'settings':
return {
side: <SubNav sections={SETTINGS_SECTIONS} active={route.settings} label={(section) => t(`settings.sections.${section}`)} onSelect={(section) => go({ page: 'settings', section })} />,
main: <GeneralSettings settings={settings} onError={report} />,
main: <GeneralSettings settings={settings} pictures={backgrounds.pictures} onError={report} />,
bar: home,
};
case 'copies': {
@@ -114,7 +127,7 @@ export function App({ info, initialSettings, initialRecord, defaultDataPath }: A
const paged = wizard.active || route.page !== 'home';
return (
<div className={paged ? 'shell shell-paged' : 'shell'}>
<Background artUrl={null} />
<Background artUrl={backgrounds.shown?.url ?? null} />
<TitleBar page={route.page} navigationEnabled={!wizard.active} language={settings.language} onNavigate={(page) => go({ page })} onError={report} />
<aside className="side">{view.side}</aside>
<main className="main">
@@ -213,6 +213,32 @@
"language": "Language",
"languageHint": "Display language of the launcher"
},
"background": {
"title": "Background",
"hint": "Website wallpapers come from the public wallpaper gallery of the War Thunder website; game pictures are read from the current copy. The launcher itself contains no game pictures.",
"official": "Website wallpapers",
"officialHint": "Requires a network connection. Only public pictures are downloaded; no sign-in and no account information is sent. Downloaded wallpapers remain available offline.",
"officialToggle": "Get wallpapers from the War Thunder website",
"officialItem": "Website · {{name}}",
"random": "Random",
"none": "No background pictures are available. Install a copy to use the game pictures, or turn on website wallpapers.",
"current": "Background: {{name}}",
"previous": "Previous",
"next": "Next",
"nations": {
"default": "General",
"usa": "USA",
"germany": "Germany",
"ussr": "USSR",
"uk": "Great Britain",
"japan": "Japan",
"china": "China",
"italy": "Italy",
"france": "France",
"sweden": "Sweden",
"israel": "Israel"
}
},
"about": {
"launcher": "Launcher {{version}}",
"supported": "Supported game versions: {{versions}}",
@@ -213,6 +213,32 @@
"language": "语言",
"languageHint": "启动器界面的显示语言"
},
"background": {
"title": "背景图",
"hint": "官网壁纸取自战争雷霆官网的公开壁纸库,游戏图片读取自当前副本。启动器本身不包含任何游戏图片。",
"official": "官网壁纸",
"officialHint": "需要联网。仅下载公开图片,不登录,不发送任何账号信息。已下载的壁纸离线时仍可使用。",
"officialToggle": "从战争雷霆官网获取壁纸",
"officialItem": "官网壁纸 · {{name}}",
"random": "随机",
"none": "暂无可用的背景图。安装后可使用游戏图片,或开启官网壁纸。",
"current": "背景:{{name}}",
"previous": "上一张",
"next": "下一张",
"nations": {
"default": "通用",
"usa": "美国",
"germany": "德国",
"ussr": "苏联",
"uk": "英国",
"japan": "日本",
"china": "中国",
"italy": "意大利",
"france": "法国",
"sweden": "瑞典",
"israel": "以色列"
}
},
"about": {
"launcher": "启动器 {{version}}",
"supported": "支持的游戏版本:{{versions}}",
@@ -0,0 +1,28 @@
import { useTranslation } from 'react-i18next';
import type { BackgroundPicture } from '@shared/schemas/background.ts';
import { ipcInvoke } from '../../ipc.ts';
import { backgroundLabel } from '../../shell/background-label.ts';
import { neighbourPicture } from '../../shell/useBackgrounds.ts';
interface BackgroundSwitchProps {
readonly pictures: readonly BackgroundPicture[];
readonly shown: BackgroundPicture | null;
readonly onError: (error: unknown) => void;
}
/** The picture's name and previous / next, at the top right of the home page; a choice is kept in the settings. */
export function BackgroundSwitch({ pictures, shown, onError }: BackgroundSwitchProps) {
const { t } = useTranslation();
if (!shown || pictures.length === 0) return null;
const step = (direction: number): void => {
const next = neighbourPicture(pictures, shown, direction);
if (next) ipcInvoke('settings:update', { background: next.key }).catch(onError);
};
return (
<div className="background-switch">
<span className="background-switch-label" title={backgroundLabel(t, shown)}>{t('background.current', { name: backgroundLabel(t, shown) })}</span>
<button type="button" title={t('background.previous')} onClick={() => step(-1)}>‹</button>
<button type="button" title={t('background.next')} onClick={() => step(1)}>›</button>
</div>
);
}
@@ -1,17 +1,66 @@
import { useTranslation } from 'react-i18next';
import { BACKGROUND_RANDOM, type BackgroundPicture } from '@shared/schemas/background.ts';
import type { Settings } from '@shared/schemas/settings.ts';
import { Row } from '../../components/Row.tsx';
import { Sheet } from '../../components/Sheet.tsx';
import { ipcInvoke } from '../../ipc.ts';
import { backgroundLabel } from '../../shell/background-label.ts';
import { LanguageMenu } from '../../shell/LanguageMenu.tsx';
/** General launcher settings. */
export function GeneralSettings({ settings, onError }: { readonly settings: Settings; readonly onError: (error: unknown) => void }) {
interface GeneralSettingsProps {
readonly settings: Settings;
readonly pictures: readonly BackgroundPicture[];
readonly onError: (error: unknown) => void;
}
/** General launcher settings: language and background picture. */
export function GeneralSettings({ settings, pictures, onError }: GeneralSettingsProps) {
const { t } = useTranslation();
const update = (patch: Partial<Settings>): void => {
ipcInvoke('settings:update', patch).catch(onError);
};
const official = pictures.filter((picture) => picture.source === 'official');
const game = pictures.filter((picture) => picture.source === 'game');
const thumb = (picture: BackgroundPicture) => (
<button
key={picture.key}
type="button"
className={settings.background === picture.key ? 'thumb thumb-selected' : 'thumb'}
style={{ backgroundImage: `url("${picture.thumbnailUrl}")` }}
title={backgroundLabel(t, picture)}
onClick={() => update({ background: picture.key })}
>
<span>{backgroundLabel(t, picture)}</span>
</button>
);
return (
<Sheet title={t('settings.sections.general')}>
<Row label={t('settings.language')} hint={t('settings.languageHint')}>
<LanguageMenu value={settings.language} onError={onError} plain />
</Row>
<Row label={t('background.official')} hint={t('background.officialHint')}>
<label className="check check-inline">
<input type="checkbox" checked={settings.officialWallpapers} onChange={(event) => update({ officialWallpapers: event.target.checked })} />
{t('background.officialToggle')}
</label>
</Row>
<h3 className="section-title section-title-spaced">{t('background.title')}</h3>
<p className="small">{t('background.hint')}</p>
{pictures.length === 0 ? (
<p className="lead">{t('background.none')}</p>
) : (
<div className="thumbs">
<button
type="button"
className={settings.background === BACKGROUND_RANDOM ? 'thumb thumb-random thumb-selected' : 'thumb thumb-random'}
onClick={() => update({ background: BACKGROUND_RANDOM })}
>
{t('background.random')}
</button>
{official.map(thumb)}
{game.map(thumb)}
</div>
)}
</Sheet>
);
}
@@ -0,0 +1,8 @@
import type { TFunction } from 'i18next';
import type { BackgroundPicture } from '@shared/schemas/background.ts';
/** "Website · ztz 96b" for a wallpaper, the nation for a picture of the game copy. */
export function backgroundLabel(t: TFunction, picture: BackgroundPicture): string {
if (picture.source === 'official') return t('background.officialItem', { name: picture.label });
return t(`background.nations.${picture.label}`, { defaultValue: picture.label });
}
@@ -0,0 +1,42 @@
import { useEffect, useMemo, useState } from 'react';
import type { BackgroundPicture } from '@shared/schemas/background.ts';
import type { Settings } from '@shared/schemas/settings.ts';
import { ipcInvoke } from '../ipc.ts';
/**
* The background pictures available and the one to show. The list is read again when the copy
* changes (an installation) or when the website wallpapers are turned on or off. With the random
* choice, one picture is drawn per list, so it stays the same until the launcher starts again.
*/
export function useBackgrounds(copyPath: string | null, settings: Settings, onError: (error: unknown) => void) {
const [pictures, setPictures] = useState<BackgroundPicture[]>([]);
const [randomKey, setRandomKey] = useState<string | null>(null);
useEffect(() => {
let current = true;
ipcInvoke('app:listBackgrounds')
.then((list) => {
if (!current) return;
setPictures(list);
setRandomKey(list[Math.floor(Math.random() * list.length)]?.key ?? null);
})
.catch((error: unknown) => current && onError(error));
return () => {
current = false;
};
}, [copyPath, settings.officialWallpapers, onError]);
const shown = useMemo(
() => pictures.find((picture) => picture.key === settings.background) ?? pictures.find((picture) => picture.key === randomKey) ?? null,
[pictures, settings.background, randomKey],
);
return { pictures, shown };
}
/** The picture next to `current` in the list (`step` 1 or -1), wrapping around. */
export function neighbourPicture(pictures: readonly BackgroundPicture[], current: BackgroundPicture | null, step: number): BackgroundPicture | null {
if (pictures.length === 0) return null;
const index = current ? pictures.findIndex((picture) => picture.key === current.key) : -1;
return pictures[(index + step + pictures.length) % pictures.length] ?? null;
}
@@ -59,6 +59,105 @@
color: var(--white);
}
.background-switch {
position: absolute;
top: 14px;
right: 16px;
max-width: 60%;
display: flex;
align-items: center;
gap: 8px;
padding: 4px 6px 4px 10px;
font-size: 12px;
color: rgba(255, 255, 255, 0.75);
background: rgba(10, 14, 16, 0.55);
border: 1px solid var(--line);
border-radius: var(--radius);
}
.background-switch-label {
min-width: 0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
text-transform: capitalize;
}
.background-switch button {
width: 22px;
height: 22px;
flex: none;
color: inherit;
background: none;
border: 0;
border-radius: 2px;
cursor: pointer;
}
.background-switch button:hover {
color: var(--white);
background: rgba(255, 255, 255, 0.12);
}
/* ===== Settings: background pictures ===== */
.section-title-spaced {
margin-top: 22px;
}
.check-inline {
margin-top: 0;
}
.thumbs {
display: grid;
grid-template-columns: repeat(5, minmax(0, 1fr));
gap: 8px;
margin-top: 10px;
}
.thumb {
position: relative;
aspect-ratio: 16 / 10;
padding: 0;
overflow: hidden;
cursor: pointer;
background-color: var(--surface);
background-size: cover;
background-position: 60% 45%;
border: 2px solid transparent;
border-radius: var(--radius);
}
.thumb:hover {
border-color: var(--line-strong);
}
.thumb span {
position: absolute;
left: 0;
right: 0;
bottom: 0;
padding: 2px 6px;
font-size: 11px;
text-align: left;
text-transform: capitalize;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
color: var(--white);
background: rgba(0, 0, 0, 0.6);
}
.thumb-random {
font: 500 14px var(--font-display);
color: var(--text);
}
.thumb-selected,
.thumb-selected:hover {
border-color: var(--red);
}
/* ===== Feature status ===== */
.feature-group {
margin-bottom: 14px;