chessbaseLinux/apps/desktop/src/platform/web/mod.rs

60 lines
1.8 KiB
Rust
Raw Normal View History

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>
2026-10-30 15:09:17 +03:00
//! 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 idb;
pub mod page;
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: &mut dyn FnMut(ScanProgress),
cancel: &AtomicBool,
) -> Result<Opened, ImportError> {
let bytes = vfs::read(path).map_err(|source| ImportError::Io {
path: path.to_owned(),
source,
})?;
let name = path
.file_name()
.map(|n| n.to_string_lossy().into_owned())
.unwrap_or_default();
chess_import::open_bytes(&name, bytes, progress, cancel)
}