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

@ -148,11 +148,28 @@ pub struct Download {
}
impl Download {
#[cfg(not(web))]
pub fn start(ctx: &egui::Context) -> Download {
let total = asset().map_or(0, |a| a.size);
Download::spawn(ctx, total, run)
}
/// A browser downloads no engine programs: there is no download for it, as for a
/// computer without a published build.
#[cfg(web)]
pub fn start(_ctx: &egui::Context) -> Download {
Download::unsupported()
}
/// The download of a platform that has none.
#[cfg(web)]
pub fn unsupported() -> Download {
Download {
stage: Arc::new(Mutex::new(Stage::Failed(Failure::Unsupported))),
cancel: Arc::new(AtomicBool::new(false)),
}
}
/// Runs `job` (a download and what follows it) in a thread of its own; `total`: the
/// bytes expected, shown until the server says.
pub fn spawn(ctx: &egui::Context, total: u64, job: Job) -> Download {
@ -205,6 +222,7 @@ impl Drop for Download {
}
}
#[cfg(not(web))]
fn run(report: &dyn Fn(Stage), cancel: &AtomicBool) -> Result<PathBuf, Failure> {
let asset = asset().ok_or(Failure::Unsupported)?;
let dir = dir().ok_or_else(|| Failure::Disk("no data directory".into()))?;
@ -228,6 +246,7 @@ fn run(report: &dyn Fn(Stage), cancel: &AtomicBool) -> Result<PathBuf, Failure>
result
}
#[cfg(not(web))]
/// Downloads `url` into `to`, checking the size and the SHA-256 on the way. The file is
/// written beside and put in place once checked: a new file, never the old one rewritten
/// (macOS on Apple silicon kills an executable rewritten in place after it once ran: it
@ -250,6 +269,7 @@ pub fn fetch(
result
}
#[cfg(not(web))]
fn fetch_into(
url: &str,
to: &Path,
@ -328,6 +348,7 @@ pub fn already(file: &Path, asset: &Asset) -> bool {
}
/// Takes the engine executable and its license files out of the archive.
#[cfg(not(web))]
fn unpack(archive: &Path, dir: &Path, zip: bool) -> Result<PathBuf, Failure> {
let exe = dir.join(EXE);
let wanted = |name: &str| -> Option<PathBuf> {
@ -382,6 +403,7 @@ fn unpack(archive: &Path, dir: &Path, zip: bool) -> Result<PathBuf, Failure> {
Ok(exe)
}
#[cfg(not(web))]
/// Starts the engine once and waits for its name: the binary runs on this computer.
fn check_runs(exe: &Path) -> Result<(), Failure> {
let mut cmd = std::process::Command::new(exe);