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
43
apps/web/page/device.js
Normal file
43
apps/web/page/device.js
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
// What device opened the page (docs/design/web-version.md §3.6.1; decisions «Веб-версия»:
|
||||
// the web application is for computers only, phones and tablets get the app page).
|
||||
// Decided by the page itself before anything large is loaded: a server cannot tell an
|
||||
// iPad (it says "Macintosh") nor see the size of the screen.
|
||||
//
|
||||
// One function for the site and /app/, so that they never disagree whom to send where
|
||||
// (the site takes this file over when the web version is published).
|
||||
(function (global) {
|
||||
"use strict";
|
||||
|
||||
// "computer" | "iphone" | "ipad" | "android-phone" | "android-tablet" | "phone" | "tablet"
|
||||
function deviceClass() {
|
||||
var ua = navigator.userAgent || "";
|
||||
var uad = navigator.userAgentData;
|
||||
var plat = (uad && uad.platform) || navigator.platform || "";
|
||||
var touch = navigator.maxTouchPoints > 0;
|
||||
// CSS pixels of the whole screen, not of the window: a narrow window of a computer
|
||||
// stays a computer; min() removes the orientation.
|
||||
var short = Math.min(screen.width, screen.height);
|
||||
var coarse = matchMedia("(pointer: coarse)").matches;
|
||||
var finePresent = matchMedia("(any-pointer: fine)").matches;
|
||||
|
||||
// iPadOS (and an iPhone asking for the desktop site) says "Mac"; a Mac has no touch.
|
||||
var ios = /iPhone|iPod|iPad/.test(ua) || (/Mac/.test(plat) && navigator.maxTouchPoints > 1);
|
||||
if (ios) return short < 600 ? "iphone" : "ipad";
|
||||
if (/Android/i.test(ua)) return short < 600 ? "android-phone" : "android-tablet";
|
||||
if (uad && uad.mobile) return short < 600 ? "phone" : "tablet";
|
||||
if (/CrOS/.test(ua)) return "computer";
|
||||
// A phone or tablet asking for the desktop site (Chrome on large tablets does by
|
||||
// default): a touch screen and no fine pointer. A laptop with a touch screen has its
|
||||
// touchpad, so it stays a computer.
|
||||
if (touch && coarse && !finePresent) return short < 600 ? "phone" : "tablet";
|
||||
return "computer";
|
||||
}
|
||||
|
||||
// The Android version of an Android device (0: not said).
|
||||
function androidVersion() {
|
||||
var m = /Android (\d+)/.exec(navigator.userAgent || "");
|
||||
return m ? Number(m[1]) : 0;
|
||||
}
|
||||
|
||||
global.CPDevice = { deviceClass: deviceClass, androidVersion: androidVersion };
|
||||
})(window);
|
||||
Loading…
Add table
Add a link
Reference in a new issue