Web version, stage 1: the interface as a library over a platform layer; apps/web

apps/desktop becomes a library (chesspenguin_app: the interface) and a thin
binary; apps/web starts the same interface in a page's canvas (eframe's
WebRunner). cfg(web) (build.rs) marks WebAssembly in a browser.

The platform layer (apps/desktop/src/platform): the program's folders, files,
background work, the files the user opens or saves, the clipboard and what
the platform offers (CAPS). On a computer it is the system as before; in a
browser the program's data lives in IndexedDB behind an in-memory file tree
loaded before the start, the files the user opens are read into it for the
session (only read), background jobs run on the page's thread after the
frame, the clipboard is read through the browser's API, sounds play through
audio elements, a game is saved as a download.

What a browser does not have is not built for it: updates, the online games
window and its probe, engine processes (analysis starts a Web Worker there;
the review and preparation jobs, Rodent and the judge are native), blocking
requests (engine, Maia and Rodent downloads report no download for the
platform, translation reports that it makes no requests). The desktop
program behaves as before; its build finds unused code (the web build
compiles parts it never shows).

apps/web: the entry point, the page /app/ (device check before anything large
is loaded: phones and tablets get the page about the apps in the site's nine
languages, keys app_* in website/site/i18n), build.sh (wasm-bindgen, profile
web), a static server and headless Firefox checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
vrubelroman 2026-10-30 15:09:17 +03:00
parent a4445d2c15
commit 3e69a5d57c
61 changed files with 2628 additions and 552 deletions

View file

@ -19,6 +19,7 @@ pub enum Tab {
}
pub enum SettingsAction {
#[cfg(not(web))]
AddEngine,
/// Download the official Stockfish (decision 14).
DownloadEngine,
@ -29,10 +30,13 @@ pub enum SettingsAction {
/// The active engine (or its options) changed; a running analysis should restart.
EngineChanged,
/// Ask now whether a newer version is out.
#[cfg(not(web))]
CheckUpdates,
/// Choose the folder for new databases.
#[cfg(not(web))]
PickBaseFolder,
/// Open the update window.
#[cfg(not(web))]
OpenUpdate,
}
@ -99,35 +103,12 @@ impl SettingsWindow {
let (status, available) =
(self.update_status.clone(), self.update_available.clone());
about_tab(ui, s.language, |ui| {
// Updates, right under the version.
ui.add_space(4.0);
ui.horizontal_wrapped(|ui| {
match (&available, &status) {
(Some(v), _) => {
let label = RichText::new(trf(
"⬆ Update to {v}…",
&[("v", v)],
))
.color(ui.visuals().hyperlink_color);
if ui.button(label).clicked() {
actions.push(SettingsAction::OpenUpdate);
}
}
(None, Some(st)) => {
ui.label(RichText::new(st).weak());
}
(None, None) => {}
}
if ui.button(tr("Check now")).clicked() {
actions.push(SettingsAction::CheckUpdates);
}
});
changed |= ui
.checkbox(&mut s.check_updates, tr("Check for updates at start"))
.on_hover_text(tr(
"ChessPenguin asks its site which version is the latest; the site counts installations that run: only a random number of this installation, the version and the system are sent",
))
.changed();
// Updates, right under the version (the web version is
// always the latest: a reload brings it).
#[cfg(not(web))]
updates(ui, s, &status, &available, &mut actions, &mut changed);
#[cfg(web)]
let _ = (ui, &status, &available);
});
}
Tab::Interface => {
@ -176,16 +157,18 @@ impl SettingsWindow {
let dir =
crate::own_db::default_base_dir(s.new_database_dir.as_deref());
// Short, under the home folder; the whole path on hover.
let home = directories::UserDirs::new()
.map(|u| u.home_dir().to_path_buf());
let short = match home.as_ref().and_then(|h| dir.strip_prefix(h).ok())
{
Some(rest) => format!("~{}{}", std::path::MAIN_SEPARATOR, rest.display()),
let home =
directories::UserDirs::new().map(|u| u.home_dir().to_path_buf());
let short = match home.as_ref().and_then(|h| dir.strip_prefix(h).ok()) {
Some(rest) => {
format!("~{}{}", std::path::MAIN_SEPARATOR, rest.display())
}
None => dir.display().to_string(),
};
ui.label(RichText::new(short).weak())
.on_hover_text(dir.display().to_string());
if ui.button(tr("Change…")).clicked() {
#[cfg(not(web))]
actions.push(SettingsAction::PickBaseFolder);
}
});
@ -245,6 +228,7 @@ impl SettingsWindow {
actions.push(SettingsAction::DownloadEngine);
}
if ui.button(tr("Choose engine file…")).clicked() {
#[cfg(not(web))]
actions.push(SettingsAction::AddEngine);
}
});
@ -432,6 +416,7 @@ impl SettingsWindow {
)
.clicked()
{
#[cfg(not(web))]
actions.push(SettingsAction::AddEngine);
}
if self.checking_engine {
@ -767,3 +752,40 @@ fn sound_tab(ui: &mut Ui, s: &mut Settings, actions: &mut Vec<SettingsAction>, c
});
});
}
/// Updates in the About tab: the version out, «Check now», the check at start.
#[cfg(not(web))]
fn updates(
ui: &mut Ui,
s: &mut Settings,
status: &Option<String>,
available: &Option<String>,
actions: &mut Vec<SettingsAction>,
changed: &mut bool,
) {
ui.add_space(4.0);
ui.horizontal_wrapped(|ui| {
match (available, status) {
(Some(v), _) => {
let label = RichText::new(trf("⬆ Update to {v}…", &[("v", v)]))
.color(ui.visuals().hyperlink_color);
if ui.button(label).clicked() {
actions.push(SettingsAction::OpenUpdate);
}
}
(None, Some(st)) => {
ui.label(RichText::new(st).weak());
}
(None, None) => {}
}
if ui.button(tr("Check now")).clicked() {
actions.push(SettingsAction::CheckUpdates);
}
});
*changed |= ui
.checkbox(&mut s.check_updates, tr("Check for updates at start"))
.on_hover_text(tr(
"ChessPenguin asks its site which version is the latest; the site counts installations that run: only a random number of this installation, the version and the system are sent",
))
.changed();
}