chessbaseLinux/apps/desktop/src/platform/web/mod.rs
vrubelroman f694bc768b Web version: databases read in a worker, the shelf's counts, Chrome and Edge remember chosen files
The page's reader: a Web Worker with a second instance of the program reads
a database (PGN, CBV, ZIP, 7Z) and gives back its text and index; the page
puts it together without reading it again (chess_core::PgnIndex,
PgnDatabase::into_index / from_index, serde behind a feature). A 13 MB CBV:
the longest frame 17 ms in Firefox, 67 ms in Chromium (1000 ms before).
platform::open_database is the same on both sides: away from the screen,
done when read. The shelf's cards count the games the same way (one file
at a time); the counts are kept through platform::fs.

Chrome, Edge (File System Access): a chosen file's handle is kept in the
browser's storage; at the next visit the file is read again by itself when
the browser allows it, else the card offers «Allow reading» (the browser's
own question). Files of different visits get folders of their own.

Checks: t.choose(files, open) for both browsers (in Chromium the handles of
the site's private file system stand for the dialog's); app.mjs checks the
draft, the question on leaving and the remembered file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 17:50:54 +03:00

63 lines
1.9 KiB
Rust

//! The web version: a page in a browser, without threads, processes or a file system.
//!
//! The program's folders are names in the page's own file tree ([`vfs`]): `/config`,
//! `/data` and `/cache` are kept in the browser's storage ([`idb`], loaded before the
//! interface starts, written behind it); `/examples` (the samples, built in) and
//! `/opened` (the files the user gave the page, only read: decisions «Веб-версия») live
//! for the session. Background work runs on the page's thread after the frame.
pub mod engine;
pub mod idb;
pub mod import;
pub mod page;
pub mod remembered;
pub mod storage;
pub mod vfs;
use std::path::{Path, PathBuf};
use std::sync::atomic::AtomicBool;
use chess_core::ScanProgress;
use chess_import::{ImportError, Opened};
pub fn config_dir() -> Option<PathBuf> {
Some(PathBuf::from(vfs::CONFIG))
}
pub fn data_dir() -> Option<PathBuf> {
Some(PathBuf::from(vfs::DATA))
}
pub fn cache_dir() -> Option<PathBuf> {
Some(PathBuf::from(vfs::CACHE))
}
pub fn examples_dir() -> Option<PathBuf> {
Some(PathBuf::from(vfs::EXAMPLES))
}
/// The page has no threads: the job runs on its thread once the current frame is
/// done (the screen shows the state before it, «Opening…», first).
pub fn spawn(_name: &str, job: impl FnOnce() + Send + 'static) -> std::io::Result<()> {
wasm_bindgen_futures::spawn_local(async move {
page::next_task().await;
job();
});
Ok(())
}
pub fn open_database(
path: &Path,
_progress: impl FnMut(ScanProgress) + Send + 'static,
cancel: std::sync::Arc<AtomicBool>,
done: impl FnOnce(Result<Opened, ImportError>) + Send + 'static,
) -> std::io::Result<()> {
import::open(path, move |read| {
done(if cancel.load(std::sync::atomic::Ordering::Relaxed) {
Err(ImportError::Cancelled)
} else {
read
})
});
Ok(())
}