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
23
apps/web/Cargo.toml
Normal file
23
apps/web/Cargo.toml
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
[package]
|
||||
name = "chesspenguin-web"
|
||||
description = "ChessPenguin in a browser: the entry point of the web version (the interface is apps/desktop's)"
|
||||
version.workspace = true
|
||||
authors.workspace = true
|
||||
repository.workspace = true
|
||||
homepage.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
license.workspace = true
|
||||
publish = false
|
||||
|
||||
# Built for WebAssembly only (apps/web/build.sh); elsewhere the crate is empty.
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[target.'cfg(target_family = "wasm")'.dependencies]
|
||||
chesspenguin = { path = "../desktop" }
|
||||
wasm-bindgen = "0.2.129"
|
||||
wasm-bindgen-futures = "0.4"
|
||||
web-sys = { version = "0.3", features = ["Window", "Document", "Element", "HtmlCanvasElement", "Location", "UrlSearchParams"] }
|
||||
log = "0.4"
|
||||
eframe.workspace = true
|
||||
58
apps/web/build.sh
Executable file
58
apps/web/build.sh
Executable file
|
|
@ -0,0 +1,58 @@
|
|||
#!/bin/sh
|
||||
# Builds the web version into a folder served as the site's /app/ (docs/dev/web.md):
|
||||
#
|
||||
# apps/web/build.sh [out-dir] (default: target/web/app)
|
||||
# PROFILE=release apps/web/build.sh (the default profile is `web`: small, slower to build)
|
||||
#
|
||||
# Needs: the target wasm32-unknown-unknown (rustup target add wasm32-unknown-unknown),
|
||||
# wasm-bindgen-cli of the version in Cargo.lock (cargo install wasm-bindgen-cli --version …;
|
||||
# WASM_BINDGEN= points at another binary), python3. wasm-opt (binaryen) makes the program
|
||||
# smaller when it is there.
|
||||
set -eu
|
||||
|
||||
here=$(cd "$(dirname "$0")" && pwd)
|
||||
root=$(cd "$here/../.." && pwd)
|
||||
out=${1:-$root/target/web/app}
|
||||
profile=${PROFILE:-web}
|
||||
bindgen=${WASM_BINDGEN:-wasm-bindgen}
|
||||
|
||||
want=$(awk '/^name = "wasm-bindgen"$/ { getline; gsub(/version = |"/, ""); print; exit }' "$root/Cargo.lock")
|
||||
have=$("$bindgen" --version | awk '{ print $2 }')
|
||||
if [ "$want" != "$have" ]; then
|
||||
echo "wasm-bindgen $have, but Cargo.lock has $want: cargo install wasm-bindgen-cli --version $want" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "$root"
|
||||
cargo build -p chesspenguin-web --target wasm32-unknown-unknown --profile "$profile"
|
||||
wasm="$root/target/wasm32-unknown-unknown/$profile/chesspenguin_web.wasm"
|
||||
|
||||
rm -rf "$out"
|
||||
mkdir -p "$out"
|
||||
"$bindgen" --target web --no-typescript --out-dir "$out" --out-name chesspenguin_web "$wasm"
|
||||
if command -v wasm-opt >/dev/null 2>&1; then
|
||||
wasm-opt -Os --enable-bulk-memory --enable-nontrapping-float-to-int --enable-sign-ext \
|
||||
--enable-mutable-globals --enable-reference-types \
|
||||
"$out/chesspenguin_web_bg.wasm" -o "$out/chesspenguin_web_bg.wasm"
|
||||
fi
|
||||
|
||||
cp "$here/page/device.js" "$here/page/page.js" "$out/"
|
||||
for size in 32 64 180; do
|
||||
cp "$root/website/static/img/icon-$size.png" "$out/"
|
||||
done
|
||||
# The page's texts in the site's languages: the app_* keys and the shared ones it uses.
|
||||
python3 -I - "$here/page/index.html" "$root/website/site/i18n" "$out/index.html" <<'PY'
|
||||
import json, pathlib, sys
|
||||
template, i18n, target = sys.argv[1], pathlib.Path(sys.argv[2]), sys.argv[3]
|
||||
shared = ["btn_android", "and_light_title", "and_full_title", "and_requires", "next_android",
|
||||
"copy_link", "link_copied", "email", "language"]
|
||||
texts = {}
|
||||
for f in sorted(i18n.glob("*.json")):
|
||||
d = json.loads(f.read_text(encoding="utf-8"))
|
||||
texts[f.stem] = {k: v for k, v in d.items() if k.startswith("app_") or k in shared}
|
||||
page = pathlib.Path(template).read_text(encoding="utf-8")
|
||||
blob = json.dumps(texts, ensure_ascii=False, separators=(",", ":")).replace("</", "<\\/")
|
||||
pathlib.Path(target).write_text(page.replace("{{TEXTS}}", blob), encoding="utf-8")
|
||||
PY
|
||||
echo "built $out"
|
||||
du -sh "$out"/chesspenguin_web_bg.wasm
|
||||
37
apps/web/check/serve.py
Normal file
37
apps/web/check/serve.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
"""The site's layout for the web version, locally: the built program at /app/ and the
|
||||
site's static files at /static/ (screenshots of the device page). Only for checks:
|
||||
the site itself serves /app/ when the web version is published (docs/dev/web.md).
|
||||
|
||||
python3 -I apps/web/check/serve.py <app-dir> <website-static-dir> [port]
|
||||
"""
|
||||
|
||||
import functools
|
||||
import http.server
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
APP, STATIC = pathlib.Path(sys.argv[1]).resolve(), pathlib.Path(sys.argv[2]).resolve()
|
||||
PORT = int(sys.argv[3]) if len(sys.argv) > 3 else 18765
|
||||
|
||||
|
||||
class Handler(http.server.SimpleHTTPRequestHandler):
|
||||
extensions_map = {
|
||||
**http.server.SimpleHTTPRequestHandler.extensions_map,
|
||||
".wasm": "application/wasm",
|
||||
".js": "text/javascript",
|
||||
}
|
||||
|
||||
def translate_path(self, path):
|
||||
path = path.split("?", 1)[0].split("#", 1)[0]
|
||||
for prefix, base in (("/app/", APP), ("/static/", STATIC)):
|
||||
if path.startswith(prefix):
|
||||
target = (base / path[len(prefix):]).resolve()
|
||||
if target == base or base in target.parents:
|
||||
return str(target / "index.html" if target.is_dir() else target)
|
||||
return str(APP / "__missing__")
|
||||
|
||||
def log_message(self, *args):
|
||||
pass
|
||||
|
||||
|
||||
http.server.ThreadingHTTPServer(("127.0.0.1", PORT), Handler).serve_forever()
|
||||
18
apps/web/check/shot.mjs
Normal file
18
apps/web/check/shot.mjs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
// A screenshot of a page of the web version in headless Firefox, with its console:
|
||||
//
|
||||
// node apps/web/check/shot.mjs <url> <out.png> [wait-ms] [width] [height]
|
||||
import { writeFileSync } from 'node:fs';
|
||||
import { launch } from './firefox.mjs';
|
||||
import { sleep, tab } from './bidi.mjs';
|
||||
|
||||
const [url, out, wait = '6000', width = '1400', height = '860'] = process.argv.slice(2);
|
||||
const ff = await launch();
|
||||
try {
|
||||
const t = await tab(ff.browser, Number(width), Number(height));
|
||||
await t.navigate(url);
|
||||
await sleep(Number(wait));
|
||||
writeFileSync(out, await t.screenshot());
|
||||
console.log('saved', out);
|
||||
} finally {
|
||||
await ff.stop();
|
||||
}
|
||||
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);
|
||||
58
apps/web/page/index.html
Normal file
58
apps/web/page/index.html
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>ChessPenguin</title>
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="icon-32.png">
|
||||
<link rel="apple-touch-icon" href="icon-180.png">
|
||||
<meta name="color-scheme" content="dark light">
|
||||
<style>
|
||||
:root { --bg: #1b1b1b; --fg: #e6e6e6; --weak: #9a9a9a; --accent: #4f8fe6; --card: #262626; --line: #3a3a3a; }
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root { --bg: #f7f7f7; --fg: #1d1d1d; --weak: #666; --accent: #1f6fd1; --card: #fff; --line: #ddd; }
|
||||
}
|
||||
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
|
||||
font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
|
||||
/* The program: the whole page is its canvas. */
|
||||
#cp-app { position: fixed; inset: 0; }
|
||||
#cp-canvas { width: 100%; height: 100%; display: block; outline: none; }
|
||||
#cp-status { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
|
||||
padding: 16px; text-align: center; color: var(--weak); }
|
||||
#cp-status.failed { color: var(--fg); }
|
||||
[hidden] { display: none !important; }
|
||||
/* The page for phones and tablets. */
|
||||
#cp-device { max-width: 560px; margin: 0 auto; padding: 16px; box-sizing: border-box; }
|
||||
#cp-device header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
|
||||
#cp-device .brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
|
||||
#cp-device .brand img { width: 28px; height: 28px; }
|
||||
#cp-device h1 { font-size: 24px; line-height: 1.25; margin: 24px 0 12px; }
|
||||
#cp-device .lead { font-size: 20px; margin: 0 0 12px; }
|
||||
#cp-device p { margin: 0 0 12px; }
|
||||
#cp-device .btn { display: block; box-sizing: border-box; width: 100%; padding: 14px 16px;
|
||||
border-radius: 10px; background: var(--accent); color: #fff; text-decoration: none;
|
||||
font-weight: 600; text-align: center; border: 0; font-size: 17px; cursor: pointer; }
|
||||
#cp-device .btn small { display: block; font-weight: 400; opacity: .85; font-size: 14px; }
|
||||
#cp-device .link { color: var(--accent); }
|
||||
#cp-device .weak { color: var(--weak); font-size: 14px; }
|
||||
#cp-device .shots { display: flex; gap: 8px; overflow-x: auto; margin: 16px 0; }
|
||||
#cp-device .shots img { height: 300px; border-radius: 8px; border: 1px solid var(--line); }
|
||||
#cp-device .contacts { display: flex; gap: 16px; margin-bottom: 12px; }
|
||||
#cp-device hr { border: 0; border-top: 1px solid var(--line); margin: 24px 0 12px; }
|
||||
#cp-device .anyway { background: none; border: 0; padding: 0; font: inherit; color: var(--weak);
|
||||
text-decoration: underline; cursor: pointer; }
|
||||
#cp-device select { font: inherit; background: var(--card); color: var(--fg); border: 1px solid var(--line);
|
||||
border-radius: 6px; padding: 4px 6px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<noscript><p style="padding:16px">ChessPenguin needs JavaScript. · Для ChessPenguin нужен JavaScript.</p></noscript>
|
||||
<div id="cp-app" hidden><canvas id="cp-canvas"></canvas></div>
|
||||
<div id="cp-status" hidden></div>
|
||||
<main id="cp-device" hidden></main>
|
||||
<!-- The page's texts in the site's nine languages (website/site/i18n/*.json, put in by build.sh). -->
|
||||
<script>window.CP_TEXTS = {{TEXTS}};</script>
|
||||
<script src="device.js"></script>
|
||||
<script src="page.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
208
apps/web/page/page.js
Normal file
208
apps/web/page/page.js
Normal file
|
|
@ -0,0 +1,208 @@
|
|||
// The page /app/: a computer gets ChessPenguin (the WebAssembly program, loaded only
|
||||
// then); a phone or a tablet gets the page about the apps (docs/design/web-version.md
|
||||
// §3.6, decisions «Веб-версия»), with a quiet way to open the web version anyway.
|
||||
//
|
||||
// ?phone=1 the device page on any device (checks, screenshots of the site)
|
||||
// ?phone=0 the program on any device
|
||||
// ?lang=xx the language (also of the program)
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
var LANGS = [
|
||||
["en", "English"], ["ru", "Русский"], ["fr", "Français"], ["de", "Deutsch"], ["es", "Español"],
|
||||
["it", "Italiano"], ["pt", "Português"], ["uz", "Oʻzbekcha"], ["kk", "Қазақша"],
|
||||
];
|
||||
// The engine the web version downloads for analysis (Stockfish 19, brotli).
|
||||
var ENGINE_MB = 78;
|
||||
var ANYWAY_KEY = "cp.web.phoneAnyway";
|
||||
var SITE = "https://chess.vrubel.xyz";
|
||||
|
||||
var params = new URLSearchParams(location.search);
|
||||
var texts = window.CP_TEXTS || {};
|
||||
|
||||
function pickLang() {
|
||||
var asked = (params.get("lang") || "").toLowerCase();
|
||||
if (texts[asked]) return asked;
|
||||
var prefs = navigator.languages || [navigator.language || ""];
|
||||
for (var i = 0; i < prefs.length; i++) {
|
||||
var code = String(prefs[i]).split(/[-_]/)[0].toLowerCase();
|
||||
if (texts[code]) return code;
|
||||
}
|
||||
return "en";
|
||||
}
|
||||
var lang = pickLang();
|
||||
|
||||
function t(key, vars) {
|
||||
var s = (texts[lang] && texts[lang][key]) || (texts.en && texts.en[key]) || key;
|
||||
for (var k in vars || {}) s = s.split("{" + k + "}").join(vars[k]);
|
||||
return s;
|
||||
}
|
||||
|
||||
function el(tag, attrs, children) {
|
||||
var e = document.createElement(tag);
|
||||
for (var a in attrs || {}) {
|
||||
if (a === "text") e.textContent = attrs[a];
|
||||
else if (a === "onclick") e.addEventListener("click", attrs[a]);
|
||||
else e.setAttribute(a, attrs[a]);
|
||||
}
|
||||
(children || []).forEach(function (c) { if (c) e.appendChild(c); });
|
||||
return e;
|
||||
}
|
||||
|
||||
function storage(get, value) {
|
||||
try {
|
||||
if (get) return localStorage.getItem(ANYWAY_KEY);
|
||||
if (value === null) localStorage.removeItem(ANYWAY_KEY);
|
||||
else localStorage.setItem(ANYWAY_KEY, value);
|
||||
} catch (e) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
// ----- the program --------------------------------------------------------------
|
||||
|
||||
function startApp() {
|
||||
document.documentElement.lang = lang;
|
||||
document.title = t("app_title");
|
||||
document.getElementById("cp-device").hidden = true;
|
||||
var status = document.getElementById("cp-status");
|
||||
status.textContent = t("app_loading");
|
||||
status.hidden = false;
|
||||
var failed = function (e) {
|
||||
console.error("ChessPenguin did not start:", e);
|
||||
document.getElementById("cp-app").hidden = true;
|
||||
status.textContent = t("app_failed");
|
||||
status.className = "failed";
|
||||
status.hidden = false;
|
||||
};
|
||||
import("./chesspenguin_web.js")
|
||||
.then(function (m) { return m.default().then(function () { return m; }); })
|
||||
.then(function (m) {
|
||||
document.getElementById("cp-app").hidden = false;
|
||||
return m.start("cp-canvas");
|
||||
})
|
||||
.then(function () {
|
||||
status.hidden = true;
|
||||
document.getElementById("cp-canvas").focus();
|
||||
})
|
||||
.catch(failed);
|
||||
}
|
||||
|
||||
// ----- the page for phones and tablets ---------------------------------------------
|
||||
|
||||
function shots(names) {
|
||||
return el("div", { class: "shots" }, names.map(function (n) {
|
||||
return el("img", { src: "../static/screenshots/" + n, alt: "", loading: "lazy" });
|
||||
}));
|
||||
}
|
||||
|
||||
function shareButton() {
|
||||
var url = SITE + "/app/?lang=" + lang;
|
||||
var label = navigator.share ? t("app_send_link") : t("copy_link");
|
||||
var b = el("button", { class: "btn", type: "button", text: "⇪ " + label });
|
||||
b.addEventListener("click", function () {
|
||||
if (navigator.share) {
|
||||
navigator.share({ title: "ChessPenguin", url: url }).catch(function () {});
|
||||
} else if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(url).then(function () { b.textContent = t("link_copied"); });
|
||||
}
|
||||
});
|
||||
return b;
|
||||
}
|
||||
|
||||
function anyway() {
|
||||
var size = ENGINE_MB + (lang === "ru" || lang === "kk" ? " МБ" : " MB");
|
||||
return el("div", null, [
|
||||
el("hr"),
|
||||
el("button", {
|
||||
class: "anyway", type: "button", text: t("app_open_anyway"),
|
||||
onclick: function () { storage(false, "1"); startApp(); },
|
||||
}),
|
||||
el("p", { class: "weak", text: t("app_open_anyway_note", { size: size }) }),
|
||||
]);
|
||||
}
|
||||
|
||||
function androidPart() {
|
||||
var v = CPDevice.androidVersion();
|
||||
if (v && v < 12) {
|
||||
return [el("p", { text: t("app_and_old", { version: String(v) }) }), shareButton()];
|
||||
}
|
||||
var hint = el("p", { class: "weak", text: t("next_android"), hidden: "" });
|
||||
var show = function () { hint.hidden = false; };
|
||||
return [
|
||||
el("a", { class: "btn", href: "/download/android-noengine", rel: "nofollow", onclick: show }, [
|
||||
document.createTextNode(t("btn_android")),
|
||||
el("small", { text: t("and_light_title") }),
|
||||
]),
|
||||
el("p", null, [
|
||||
el("a", { class: "link", href: "/download/android", rel: "nofollow", onclick: show, text: t("and_full_title") + " ›" }),
|
||||
]),
|
||||
el("p", { class: "weak", text: t("and_requires") }),
|
||||
hint,
|
||||
shots(["phone/01-home-360.webp", "phone/03-game-360.webp", "phone/04-engine-360.webp", "phone/08-review-360.webp"]),
|
||||
el("p", null, [el("a", { class: "link", href: "/" + (lang === "en" ? "" : lang + "/") + "#download-android", text: t("app_and_more") + " ›" })]),
|
||||
];
|
||||
}
|
||||
|
||||
function iosPart() {
|
||||
return [
|
||||
el("p", { class: "lead", text: t("app_ios_lead") }),
|
||||
el("p", { text: t("app_ios_now") }),
|
||||
shareButton(),
|
||||
el("p", { style: "margin-top:16px", text: t("app_ios_notify") }),
|
||||
el("div", { class: "contacts" }, [
|
||||
el("a", { class: "link", href: "mailto:vrubelroman@gmail.com?subject=ChessPenguin", text: "✉ " + t("email") }),
|
||||
el("a", { class: "link", href: "https://t.me/vrubelr", rel: "noopener", text: "✈ Telegram" }),
|
||||
]),
|
||||
shots(["01-game-640.webp", "04-review-640.webp"]),
|
||||
];
|
||||
}
|
||||
|
||||
function showDevicePage(kind) {
|
||||
document.documentElement.lang = lang;
|
||||
document.title = t("app_phone_title");
|
||||
var page = document.getElementById("cp-device");
|
||||
page.textContent = "";
|
||||
var select = el("select", { "aria-label": t("language") }, LANGS.map(function (l) {
|
||||
var o = el("option", { value: l[0], text: l[1] });
|
||||
if (l[0] === lang) o.selected = true;
|
||||
return o;
|
||||
}));
|
||||
select.addEventListener("change", function () {
|
||||
lang = select.value;
|
||||
showDevicePage(kind);
|
||||
});
|
||||
page.appendChild(el("header", null, [
|
||||
el("span", { class: "brand" }, [el("img", { src: "icon-64.png", alt: "" }), document.createTextNode("ChessPenguin")]),
|
||||
select,
|
||||
]));
|
||||
page.appendChild(el("h1", { text: t("app_phone_title") }));
|
||||
var body;
|
||||
if (kind === "android-phone" || kind === "android-tablet") {
|
||||
body = [el("p", { text: t("app_and_lead") })].concat(androidPart());
|
||||
} else if (kind === "iphone" || kind === "ipad") {
|
||||
body = iosPart();
|
||||
} else {
|
||||
body = [
|
||||
el("p", { text: t("app_phone_generic") }),
|
||||
el("a", { class: "btn", href: "/download/android-noengine", rel: "nofollow", text: t("btn_android") }),
|
||||
el("p"),
|
||||
shareButton(),
|
||||
];
|
||||
}
|
||||
body.forEach(function (n) { page.appendChild(n); });
|
||||
page.appendChild(anyway());
|
||||
page.hidden = false;
|
||||
}
|
||||
|
||||
// ----- which one --------------------------------------------------------------------
|
||||
|
||||
var asked = params.get("phone");
|
||||
var kind = CPDevice.deviceClass();
|
||||
if (asked === "1") {
|
||||
showDevicePage(kind === "computer" ? "phone" : kind);
|
||||
} else if (asked === "0" || kind === "computer" || storage(true) === "1") {
|
||||
startApp();
|
||||
} else {
|
||||
showDevicePage(kind);
|
||||
}
|
||||
})();
|
||||
24
apps/web/src/lib.rs
Normal file
24
apps/web/src/lib.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
//! ChessPenguin in a browser: the entry point the page (`page/index.html`) calls once it
|
||||
//! has decided the device is a computer. The interface is the desktop program's
|
||||
//! (`chesspenguin_app`), with the web platform under it (`docs/dev/web.md`).
|
||||
#![cfg(target_family = "wasm")]
|
||||
|
||||
use wasm_bindgen::JsCast;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
/// Starts ChessPenguin in the page's canvas `canvas_id`. Resolves once the interface
|
||||
/// runs; an error says why it could not start (no WebGL, …).
|
||||
#[wasm_bindgen]
|
||||
pub async fn start(canvas_id: String) -> Result<(), JsValue> {
|
||||
// The program's log and its panics go to the browser's console.
|
||||
let _ = eframe::WebLogger::init(log::LevelFilter::Info);
|
||||
let window = web_sys::window().ok_or("no window")?;
|
||||
let canvas = window
|
||||
.document()
|
||||
.ok_or("no document")?
|
||||
.get_element_by_id(&canvas_id)
|
||||
.ok_or("no canvas")?
|
||||
.dyn_into::<web_sys::HtmlCanvasElement>()?;
|
||||
let lang = web_sys::UrlSearchParams::new_with_str(&window.location().search()?)?.get("lang");
|
||||
chesspenguin_app::start_web(canvas, lang).await
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue