Web version, stage 2: Stockfish 19 in workers, live analysis, game review on N workers, My games, files, keys

game-review: what the job does for one target (the full search, the second
best without the move played, the shallow ones) becomes a machine without I/O
(job/work.rs), driven by the engine processes on a computer (job/engines.rs,
the same searches as before) and by Web Workers in a browser
(job/workers.rs: a dispatcher polled from the frames, never blocking). The
analysis cache goes through a CacheStore (a folder, or the program's files of
the platform).

The browser's engine: Stockfish.js 19.0.1 (npm stockfish, GPL-3.0), its
single-threaded build served beside /app/ (engine/, build.sh checks the
package's sha512), its 99 MB wasm downloaded only through the engine offer,
checked against its SHA-256 and kept in Cache Storage; workers get it as a
blob: address. Live analysis (lines, arrows, the bar) and the review run on it;
the review uses one worker per logical CPU, at most 8.

My games (the web version): a PGN in the browser's storage, always on the
shelf; Ctrl+S puts a game there (its own record, or a new one); deleting with
undo. chess-core's store gives the bytes of append/replace/remove/restore, so
the platform writes them into the browser's files; on a computer the files
are written as before. Settings: Browser data (used and free space, keeping
the data for good, Download all as PGN, deleting the engine).

Files: a file of the last visit offers Choose the file again; Keep a copy in
the browser (refused with the room it needs when the browser gives too
little); files over 1 GB are not opened, with a word on why. No reference tab
and no search by position in the web version. Keys: Alt+Left, plain 1-6,
Ctrl+C, N in the library (the browser keeps Ctrl+W/N/1-6/Shift+C).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
vrubelroman 2026-10-30 16:35:16 +03:00
parent 4ccf8099a5
commit 61ccd763bc
34 changed files with 2063 additions and 253 deletions

View file

@ -15,10 +15,19 @@ pub enum Tab {
Sound,
Interface,
Translation,
/// What the web version keeps in the browser.
#[cfg(web)]
BrowserData,
About,
}
pub enum SettingsAction {
/// All of «My games» as a downloaded PGN.
#[cfg(web)]
DownloadMyGames,
/// Ask the browser to keep the site's data for good.
#[cfg(web)]
KeepData,
#[cfg(not(web))]
AddEngine,
/// Download the official Stockfish (decision 14).
@ -93,6 +102,8 @@ impl SettingsWindow {
if crate::platform::CAPS.translation {
ui.selectable_value(&mut self.tab, Tab::Translation, tr("Translation"));
}
#[cfg(web)]
ui.selectable_value(&mut self.tab, Tab::BrowserData, tr("Browser data"));
ui.selectable_value(&mut self.tab, Tab::About, tr("About"));
});
ui.separator();
@ -100,6 +111,8 @@ impl SettingsWindow {
Tab::Engines => self.engines(ui, s, &mut actions, &mut changed),
Tab::Board => board_tab(ui, s, &mut changed),
Tab::Translation => changed |= translation.settings_tab(ui, s),
#[cfg(web)]
Tab::BrowserData => browser_data(ui, &mut actions),
Tab::Sound => sound_tab(ui, s, &mut actions, &mut changed),
Tab::About => {
let (status, available) =
@ -791,3 +804,67 @@ fn updates(
))
.changed();
}
/// Settings → Browser data (docs/design/web-version.md §2.3): what is kept only in this
/// browser, how much room it takes and is left, and the way to take «My games» along.
#[cfg(web)]
fn browser_data(ui: &mut Ui, actions: &mut Vec<SettingsAction>) {
use crate::platform::{size_text, web};
ui.label(tr(
"Everything below is stored only here, on this device. Files on disk are not changed.",
));
ui.add_space(6.0);
if let Some((used, quota)) = web::storage::usage() {
ui.label(trf(
"Used {used} · free for the site {free}",
&[
("used", &size_text(used)),
("free", &size_text(quota.saturating_sub(used))),
],
));
}
ui.horizontal(|ui| match web::storage::persisted() {
Some(true) => {
ui.label(tr("Persistent storage: on"));
}
_ => {
ui.label(
RichText::new(tr("Persistent storage: not allowed by the browser"))
.color(ui.visuals().warn_fg_color),
);
if ui.button(tr("Ask the browser")).clicked() {
actions.push(SettingsAction::KeepData);
}
}
});
ui.add_space(8.0);
egui::Grid::new("browser data")
.num_columns(3)
.spacing([16.0, 6.0])
.show(ui, |ui| {
ui.label(trf(
"My games · {n}",
&[("n", &crate::i18n::games(crate::my_games::count()))],
));
ui.label(size_text(crate::my_games::size()));
if ui.button(tr("Download all as PGN")).clicked() {
actions.push(SettingsAction::DownloadMyGames);
}
ui.end_row();
if web::engine::ready() {
ui.label(tr("Stockfish 19 engine"));
ui.label(size_text(web::engine::WASM_BYTES));
if ui.button(tr("Delete")).clicked() {
actions.push(SettingsAction::RemoveDownloaded);
}
ui.end_row();
}
});
ui.add_space(8.0);
ui.label(
RichText::new(tr(
"If you clear the site's data in the browser, all of this is lost. Download your games as PGN to keep them.",
))
.weak(),
);
}