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:
parent
a4445d2c15
commit
3e69a5d57c
61 changed files with 2628 additions and 552 deletions
124
apps/desktop/src/platform/mod.rs
Normal file
124
apps/desktop/src/platform/mod.rs
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
//! What differs between the desktop program and the web version (`docs/dev/web.md`).
|
||||
//!
|
||||
//! The interface asks this module, never the system, for: where the program keeps its
|
||||
//! data ([`config_dir`] and the others), files ([`fs`]), background work ([`spawn`]),
|
||||
//! the files the user opens or saves ([`files`]), the clipboard ([`clipboard`]) and
|
||||
//! what the platform offers at all ([`CAPS`]). On a computer it is the system's
|
||||
//! (`native.rs`); in a browser (`cfg(web)`) the page's (`web/`): the program's data in
|
||||
//! the browser's storage (IndexedDB), the files the user opened in memory, background
|
||||
//! work between frames.
|
||||
#![cfg_attr(web, warn(unused))]
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[cfg(not(web))]
|
||||
mod native;
|
||||
#[cfg(not(web))]
|
||||
use native as imp;
|
||||
#[cfg(web)]
|
||||
pub mod web;
|
||||
#[cfg(web)]
|
||||
use web as imp;
|
||||
|
||||
pub mod clipboard;
|
||||
pub mod files;
|
||||
pub mod fs;
|
||||
|
||||
/// What the platform offers the interface: a feature it lacks is not shown.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Caps {
|
||||
/// Checking for a new version and installing it (the web version is always the
|
||||
/// latest: a reload brings it).
|
||||
pub updates: bool,
|
||||
/// Downloading games from Lichess and Chess.com.
|
||||
pub online_games: bool,
|
||||
/// Games against the computer (Maia, Rodent).
|
||||
pub play: bool,
|
||||
/// Preparing against an opponent.
|
||||
pub prep: bool,
|
||||
/// Machine translation of comments.
|
||||
pub translation: bool,
|
||||
/// The user's own PGN databases on the disk: new ones, games added and replaced.
|
||||
pub own_databases: bool,
|
||||
/// Engines as programs on the disk: chosen, downloaded, started.
|
||||
pub engine_programs: bool,
|
||||
/// The opening trainer.
|
||||
pub training: bool,
|
||||
/// Saving a game is a download of its PGN (the browser's files are not written).
|
||||
pub download_pgn: bool,
|
||||
}
|
||||
|
||||
/// The features of this platform.
|
||||
#[cfg(not(web))]
|
||||
pub const CAPS: Caps = Caps {
|
||||
updates: true,
|
||||
online_games: true,
|
||||
play: true,
|
||||
prep: true,
|
||||
translation: true,
|
||||
own_databases: true,
|
||||
engine_programs: true,
|
||||
training: true,
|
||||
download_pgn: false,
|
||||
};
|
||||
|
||||
/// The features of this platform: the light web version (`docs/decisions.md`, «Веб-версия»).
|
||||
#[cfg(web)]
|
||||
pub const CAPS: Caps = Caps {
|
||||
updates: false,
|
||||
online_games: false,
|
||||
play: false,
|
||||
prep: false,
|
||||
translation: false,
|
||||
own_databases: false,
|
||||
engine_programs: false,
|
||||
training: false,
|
||||
download_pgn: true,
|
||||
};
|
||||
|
||||
/// The program's settings (`~/.config/chesspenguin`; in a browser, its storage).
|
||||
pub fn config_dir() -> Option<PathBuf> {
|
||||
imp::config_dir()
|
||||
}
|
||||
|
||||
/// The program's data kept for good (`~/.local/share/chesspenguin`).
|
||||
pub fn data_dir() -> Option<PathBuf> {
|
||||
imp::data_dir()
|
||||
}
|
||||
|
||||
/// Data the program can make again (`~/.cache/chesspenguin`).
|
||||
pub fn cache_dir() -> Option<PathBuf> {
|
||||
imp::cache_dir()
|
||||
}
|
||||
|
||||
/// The sample databases: files of the program, written at the first start on a
|
||||
/// computer; built in and only read in a browser.
|
||||
pub fn examples_dir() -> Option<PathBuf> {
|
||||
imp::examples_dir()
|
||||
}
|
||||
|
||||
/// Runs `job` in the background and returns at once: on a thread of its own named
|
||||
/// `name` on a computer; in a browser (which gives a page no threads) on the page's
|
||||
/// thread after the current frame, so a job there is one finite piece of work, never a
|
||||
/// loop that waits. The error: the job could not be started.
|
||||
pub fn spawn(name: &str, job: impl FnOnce() + Send + 'static) -> std::io::Result<()> {
|
||||
imp::spawn(name, job)
|
||||
}
|
||||
|
||||
/// A line for the program's log (`chesspenguin.log`; in a browser its console).
|
||||
pub fn log(line: &str) {
|
||||
#[cfg(not(web))]
|
||||
crate::graphics::log(line);
|
||||
#[cfg(web)]
|
||||
log::info!("{line}");
|
||||
}
|
||||
|
||||
/// Opens a database the library shows: its file on the disk, or in a browser the file
|
||||
/// the user gave the page (or a sample built in).
|
||||
pub fn open_database(
|
||||
path: &std::path::Path,
|
||||
progress: &mut dyn FnMut(chess_core::ScanProgress),
|
||||
cancel: &std::sync::atomic::AtomicBool,
|
||||
) -> Result<chess_import::Opened, chess_import::ImportError> {
|
||||
imp::open_database(path, progress, cancel)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue