Web version: what the browser lacks is not offered, files dropped on the window, checks, docs
The interface hides what the platform does not have (platform::CAPS): play, new databases, adding to a database, preparation, translation, their shortcuts and the Translation tab. Files dropped on the window open like chosen ones (in a browser; the desktop program takes no drops, as before), with «Release to open» while they are dragged over it. /app/: ?phone=android and ?phone=ios show those variants of the device page. apps/web/check: device.test.mjs (14 devices: computer, iPhone, iPad as a Mac, Android phone and tablet, desktop-site modes, Chromebook, touch laptop) and app.mjs (headless Firefox: the device page in three languages without the program, the program, a PGN opened by Ctrl+O and the file chooser, a dropped PGN, a game of the classics, moves, «Download PGN», e2-e4 on the board, the settings after a reload). All pass. docs/dev/web.md: the architecture, the platform layer, what is not built for a browser, the build and the checks, what comes next; docs/dev/uci.md and desktop.md updated, web/README.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3e69a5d57c
commit
30eac472ff
13 changed files with 501 additions and 32 deletions
|
|
@ -2730,6 +2730,35 @@ impl App {
|
|||
}
|
||||
}
|
||||
|
||||
/// Files dropped on the window open as databases, like chosen ones; while files are
|
||||
/// dragged over it, the window says so.
|
||||
fn dropped_files(&mut self, ctx: &egui::Context) {
|
||||
let (tx, waker) = (self.tx.clone(), ctx.clone());
|
||||
crate::platform::files::take_dropped(ctx, move |paths| {
|
||||
if !paths.is_empty() {
|
||||
let _ = tx.send(Async::DatabasesPicked(paths));
|
||||
}
|
||||
waker.request_repaint();
|
||||
});
|
||||
if crate::platform::files::dragging(ctx) {
|
||||
let rect = ctx.content_rect();
|
||||
let painter = ctx.layer_painter(egui::LayerId::new(
|
||||
egui::Order::Foreground,
|
||||
egui::Id::new("dropping files"),
|
||||
));
|
||||
let visuals = ctx.global_style().visuals.clone();
|
||||
let accent = visuals.selection.bg_fill;
|
||||
painter.rect_filled(rect, 0.0, accent.gamma_multiply(0.12));
|
||||
painter.text(
|
||||
rect.center(),
|
||||
egui::Align2::CENTER_CENTER,
|
||||
tr("Release to open"),
|
||||
egui::FontId::proportional(22.0),
|
||||
visuals.strong_text_color(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The open game's PGN, downloaded as a file named after the game.
|
||||
#[cfg(web)]
|
||||
fn download_pgn(&mut self, ctx: &egui::Context) {
|
||||
|
|
@ -3065,6 +3094,7 @@ impl eframe::App for App {
|
|||
ctx.send_viewport_cmd(egui::ViewportCommand::CancelClose);
|
||||
self.confirm_close = Some(CloseIntent::QuitApp);
|
||||
}
|
||||
self.dropped_files(&ctx);
|
||||
self.handle_async(&ctx);
|
||||
// Dev hook (screenshots): the engine offer as on pressing L without an engine.
|
||||
if std::env::var("CP_ENGINE_OFFER").is_ok() && !self.offer_hook_done {
|
||||
|
|
@ -3091,13 +3121,17 @@ impl eframe::App for App {
|
|||
Key::N,
|
||||
))
|
||||
}) && self.game.is_none()
|
||||
&& crate::platform::CAPS.own_databases
|
||||
{
|
||||
self.own.then_close = None;
|
||||
self.new_base_dialog(own_db::AfterCreate::Shelf);
|
||||
}
|
||||
// In the library a game from the start; on a game's screen the game plays on
|
||||
// from its position (the game view takes Ctrl+G there).
|
||||
if self.game.is_none() && ctx.input_mut(|i| i.consume_shortcut(&ctrl(Key::G))) {
|
||||
if self.game.is_none()
|
||||
&& crate::platform::CAPS.play
|
||||
&& ctx.input_mut(|i| i.consume_shortcut(&ctrl(Key::G)))
|
||||
{
|
||||
self.play_new(&ctx, PlayNext::Dialog(None));
|
||||
}
|
||||
if ctx.input_mut(|i| i.consume_shortcut(&ctrl(Key::N))) && self.game.is_none() {
|
||||
|
|
|
|||
|
|
@ -1959,7 +1959,9 @@ impl GameView {
|
|||
actions.push(GameAction::Save);
|
||||
ui.close();
|
||||
}
|
||||
if ui.button(tr("Add to database… (Ctrl+Shift+S)")).clicked() {
|
||||
if crate::platform::CAPS.own_databases
|
||||
&& ui.button(tr("Add to database… (Ctrl+Shift+S)")).clicked()
|
||||
{
|
||||
actions.push(GameAction::AddToDatabase);
|
||||
ui.close();
|
||||
}
|
||||
|
|
@ -1987,7 +1989,7 @@ impl GameView {
|
|||
self.paste_clipboard(ui.ctx());
|
||||
ui.close();
|
||||
}
|
||||
if self.play.is_none() {
|
||||
if self.play.is_none() && crate::platform::CAPS.play {
|
||||
ui.separator();
|
||||
if ui.button(tr("Play on from here… (Ctrl+G)")).clicked() {
|
||||
let at = self.cursor;
|
||||
|
|
@ -2017,7 +2019,9 @@ impl GameView {
|
|||
ui.close();
|
||||
}
|
||||
ui.separator();
|
||||
if self.translation.can_translate() && ui.button(tr("Translate comments")).clicked()
|
||||
if crate::platform::CAPS.translation
|
||||
&& self.translation.can_translate()
|
||||
&& ui.button(tr("Translate comments")).clicked()
|
||||
{
|
||||
self.translate_now = true;
|
||||
self.side_tab = SideTab::Notation;
|
||||
|
|
@ -4832,11 +4836,13 @@ impl GameView {
|
|||
}
|
||||
"copy" => actions.push(self.copy_pgn()),
|
||||
"save" => actions.push(GameAction::Save),
|
||||
"play_from" => {
|
||||
"play_from" if crate::platform::CAPS.play => {
|
||||
let at = self.cursor;
|
||||
self.play_from(at, actions);
|
||||
}
|
||||
"add_to_db" => actions.push(GameAction::AddToDatabase),
|
||||
"add_to_db" if crate::platform::CAPS.own_databases => {
|
||||
actions.push(GameAction::AddToDatabase)
|
||||
}
|
||||
"game_data" => actions.push(GameAction::EditGameData),
|
||||
"back" => actions.push(GameAction::BackKey),
|
||||
"find" if self.search_line().is_some() => {
|
||||
|
|
@ -4864,7 +4870,7 @@ impl GameView {
|
|||
self.goto(end);
|
||||
}
|
||||
"flip" => self.flipped = !self.flipped,
|
||||
"translate" => {
|
||||
"translate" if crate::platform::CAPS.translation => {
|
||||
if self.translation.has_translation() {
|
||||
self.translation.toggle();
|
||||
} else if self.translation.can_translate() {
|
||||
|
|
|
|||
|
|
@ -217,6 +217,17 @@ pub fn trf(key: &'static str, args: &[(&str, &dyn Display)]) -> String {
|
|||
// Uzbek o‘ and g‘ are written with ‘ (U+2018): the interface font has no U+02BB.
|
||||
const ROWS: &[[&str; 9]] = &[
|
||||
// --- the web version ---
|
||||
[
|
||||
"Release to open",
|
||||
"Отпустите, чтобы открыть",
|
||||
"Relâchez pour ouvrir",
|
||||
"Zum Öffnen loslassen",
|
||||
"Suelta para abrir",
|
||||
"Rilascia per aprire",
|
||||
"Solte para abrir",
|
||||
"Ochish uchun qo‘yib yuboring",
|
||||
"Ашу үшін жіберіңіз",
|
||||
],
|
||||
[
|
||||
"⇩ Download PGN",
|
||||
"⇩ Скачать PGN",
|
||||
|
|
|
|||
|
|
@ -136,9 +136,14 @@ fn shelf_buttons_w(ui: &Ui, update: Option<&str>, icons: bool) -> f32 {
|
|||
tr("♞ Play"),
|
||||
]
|
||||
};
|
||||
texts.iter().map(|t| button_w(ui, t)).sum::<f32>()
|
||||
let play = crate::platform::CAPS.play;
|
||||
let groups = if play { 2.0 } else { 1.0 };
|
||||
texts[..if play { 4 } else { 3 }]
|
||||
.iter()
|
||||
.map(|t| button_w(ui, t))
|
||||
.sum::<f32>()
|
||||
+ update.map_or(0.0, |v| button_w(ui, v))
|
||||
+ 2.0 * GROUP_GAP
|
||||
+ groups * GROUP_GAP
|
||||
}
|
||||
|
||||
/// A shelf button's tooltip: with icons only, its name first.
|
||||
|
|
@ -636,6 +641,7 @@ impl Library {
|
|||
if let Some(path) = self.selected_db.clone()
|
||||
&& let Some(view) = self.large.get_mut(&path)
|
||||
&& let Some(entry) = view.prepare.take()
|
||||
&& crate::platform::CAPS.prep
|
||||
{
|
||||
actions.push(LibraryAction::PrepareAgainst { path, entry });
|
||||
}
|
||||
|
|
@ -771,8 +777,10 @@ impl Library {
|
|||
self.shelf_actions(ui, folded, actions);
|
||||
ui.separator();
|
||||
self.game_buttons(ui, icons, actions);
|
||||
ui.separator();
|
||||
self.play_button(ui, icons, actions);
|
||||
if crate::platform::CAPS.play {
|
||||
ui.separator();
|
||||
self.play_button(ui, icons, actions);
|
||||
}
|
||||
}
|
||||
|
||||
/// "♞ Play": a game against Maia, a group of its own.
|
||||
|
|
@ -933,10 +941,11 @@ impl Library {
|
|||
actions.push(LibraryAction::AddDatabases);
|
||||
ui.close();
|
||||
}
|
||||
if ui
|
||||
.button(tr("New database…"))
|
||||
.on_hover_text(new_hint)
|
||||
.clicked()
|
||||
if crate::platform::CAPS.own_databases
|
||||
&& ui
|
||||
.button(tr("New database…"))
|
||||
.on_hover_text(new_hint)
|
||||
.clicked()
|
||||
{
|
||||
actions.push(LibraryAction::NewDatabase);
|
||||
ui.close();
|
||||
|
|
@ -950,10 +959,11 @@ impl Library {
|
|||
{
|
||||
actions.push(LibraryAction::AddDatabases);
|
||||
}
|
||||
if ui
|
||||
.button(tr("✚ New database"))
|
||||
.on_hover_text(new_hint)
|
||||
.clicked()
|
||||
if crate::platform::CAPS.own_databases
|
||||
&& ui
|
||||
.button(tr("✚ New database"))
|
||||
.on_hover_text(new_hint)
|
||||
.clicked()
|
||||
{
|
||||
actions.push(LibraryAction::NewDatabase);
|
||||
}
|
||||
|
|
@ -1027,9 +1037,10 @@ impl Library {
|
|||
{
|
||||
actions.push(LibraryAction::AddDatabases);
|
||||
}
|
||||
if card(ui, new_w, tr("✚ New database"), None)
|
||||
.on_hover_text(tr("An empty PGN file for your own games (Ctrl+Shift+N)"))
|
||||
.clicked()
|
||||
if crate::platform::CAPS.own_databases
|
||||
&& card(ui, new_w, tr("✚ New database"), None)
|
||||
.on_hover_text(tr("An empty PGN file for your own games (Ctrl+Shift+N)"))
|
||||
.clicked()
|
||||
{
|
||||
actions.push(LibraryAction::NewDatabase);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -445,6 +445,10 @@ fn handle_move_response(
|
|||
out.context = Some((id, NotationCommand::Delete));
|
||||
ui.close();
|
||||
}
|
||||
// Games against the computer and the trainer: not in every version.
|
||||
if !crate::platform::CAPS.play {
|
||||
return;
|
||||
}
|
||||
ui.separator();
|
||||
// A finished position has nothing to play.
|
||||
let over = n.game.position(id).and_then(|p| {
|
||||
|
|
|
|||
|
|
@ -90,7 +90,9 @@ impl SettingsWindow {
|
|||
ui.selectable_value(&mut self.tab, Tab::Board, tr("Board & pieces"));
|
||||
ui.selectable_value(&mut self.tab, Tab::Sound, tr("Sound"));
|
||||
ui.selectable_value(&mut self.tab, Tab::Interface, tr("Interface"));
|
||||
ui.selectable_value(&mut self.tab, Tab::Translation, tr("Translation"));
|
||||
if crate::platform::CAPS.translation {
|
||||
ui.selectable_value(&mut self.tab, Tab::Translation, tr("Translation"));
|
||||
}
|
||||
ui.selectable_value(&mut self.tab, Tab::About, tr("About"));
|
||||
});
|
||||
ui.separator();
|
||||
|
|
|
|||
160
apps/web/check/app.mjs
Normal file
160
apps/web/check/app.mjs
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
// The web version in headless Firefox: the page for phones, the program, opening a PGN
|
||||
// by its button (Ctrl+O) and by dropping it, a game from the classics, moves, a
|
||||
// download of the PGN. Screenshots go to <out-dir>; what is checked is printed.
|
||||
//
|
||||
// node apps/web/check/app.mjs <app-dir> <out-dir> (app-dir: apps/web/build.sh's)
|
||||
import { spawn } from 'node:child_process';
|
||||
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
||||
import { join, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { launch } from './firefox.mjs';
|
||||
import { sleep, tab } from './bidi.mjs';
|
||||
|
||||
const [appDir, outDir] = process.argv.slice(2).map((p) => resolve(p));
|
||||
const root = fileURLToPath(new URL('../../..', import.meta.url));
|
||||
mkdirSync(outDir, { recursive: true });
|
||||
const port = 18766;
|
||||
const server = spawn('python3', ['-I', join(root, 'apps/web/check/serve.py'), appDir, join(root, 'website/static'), String(port)], { stdio: 'ignore' });
|
||||
const base = `http://127.0.0.1:${port}/app/`;
|
||||
|
||||
let failures = 0;
|
||||
const check = (ok, what) => {
|
||||
console.log(`${ok ? 'ok ' : 'FAIL'} ${what}`);
|
||||
if (!ok) failures++;
|
||||
};
|
||||
const errors = [];
|
||||
const log = (line) => {
|
||||
if (/panicked|RuntimeError|did not start|\[error\]/.test(line)) errors.push(line);
|
||||
};
|
||||
|
||||
const ff = await launch(19223);
|
||||
const shot = async (t, name) => writeFileSync(join(outDir, name), await t.screenshot());
|
||||
const key = (value, mods = []) => {
|
||||
const down = mods.map((m) => ({ type: 'keyDown', value: m }));
|
||||
const up = mods.map((m) => ({ type: 'keyUp', value: m })).reverse();
|
||||
return [...down, { type: 'keyDown', value }, { type: 'keyUp', value }, ...up, { type: 'pause', duration: 80 }];
|
||||
};
|
||||
const CTRL = '';
|
||||
const RIGHT = '';
|
||||
const click = (x, y, count = 1) => {
|
||||
const acts = [{ type: 'pointerMove', x, y }];
|
||||
for (let i = 0; i < count; i++) acts.push({ type: 'pointerDown', button: 0 }, { type: 'pointerUp', button: 0 });
|
||||
return [{ type: 'pointer', id: 'mouse', parameters: { pointerType: 'mouse' }, actions: acts }];
|
||||
};
|
||||
const started = (t) => t.waitFor(`document.getElementById('cp-status').hidden && !document.getElementById('cp-app').hidden`, 30000);
|
||||
|
||||
try {
|
||||
// ----- the page for phones and tablets, without the program ------------------------------
|
||||
{
|
||||
const t = await tab(ff.browser, 390, 844, log);
|
||||
await t.navigate(`${base}?phone=1&lang=ru`);
|
||||
await sleep(800);
|
||||
const text = await t.evaluate(`document.getElementById('cp-device').innerText`);
|
||||
check(/ChessPenguin на телефоне и планшете/.test(text), 'the device page in Russian');
|
||||
check(/Всё равно открыть веб-версию/.test(text), 'with «open the web version anyway»');
|
||||
const wasm = await t.evaluate(`performance.getEntriesByType('resource').some(e => e.name.endsWith('.wasm'))`);
|
||||
check(!wasm, 'the program is not downloaded on it');
|
||||
await shot(t, 'web-phone-ru.png');
|
||||
await t.navigate(`${base}?phone=1&lang=de`);
|
||||
await sleep(500);
|
||||
check(/auf Handy und Tablet/.test(await t.evaluate(`document.getElementById('cp-device').innerText`)), 'the device page in German');
|
||||
await t.navigate(`${base}?phone=android&lang=ru`);
|
||||
await sleep(800);
|
||||
check(/Скачать для Android/.test(await t.evaluate(`document.getElementById('cp-device').innerText`)), 'the Android variant');
|
||||
await shot(t, 'web-phone-android-ru.png');
|
||||
await t.navigate(`${base}?phone=ios&lang=en`);
|
||||
await sleep(800);
|
||||
check(/iPhone and iPad app is coming soon/.test(await t.evaluate(`document.getElementById('cp-device').innerText`)), 'the iPhone and iPad variant');
|
||||
await shot(t, 'web-phone-ios-en.png');
|
||||
}
|
||||
|
||||
// ----- the program -------------------------------------------------------------------------
|
||||
const t = await tab(ff.browser, 1400, 860, log);
|
||||
await t.navigate(`${base}?lang=en`);
|
||||
await started(t);
|
||||
await sleep(2500);
|
||||
check(true, 'the program started (WebGL canvas, no error)');
|
||||
await shot(t, 'web-1-library.png');
|
||||
|
||||
// Open a PGN by the button's shortcut: the browser's file chooser gets the file.
|
||||
const pgn = join(ff.profile, 'Test games.pgn');
|
||||
copyFileSync(join(root, 'examples/alekhine.pgn'), pgn);
|
||||
await t.actions([{ type: 'key', id: 'kb', actions: key('o', [CTRL]) }]);
|
||||
await t.waitFor(`!!document.getElementById('cp-open-files')`, 5000);
|
||||
const input = await ff.browser.send('script.evaluate', {
|
||||
expression: `document.getElementById('cp-open-files')`,
|
||||
target: { context: t.context },
|
||||
awaitPromise: false,
|
||||
});
|
||||
await ff.browser.send('input.setFiles', { context: t.context, element: { sharedId: input.result.sharedId }, files: [pgn] });
|
||||
await sleep(2500);
|
||||
await shot(t, 'web-2-opened.png');
|
||||
|
||||
// Drop a file on the window.
|
||||
const dropped = readFileSync(join(root, 'examples/classics.pgn'), 'utf8');
|
||||
await t.evaluate(`(() => {
|
||||
const dt = new DataTransfer();
|
||||
dt.items.add(new File([${JSON.stringify(dropped)}], 'Dropped classics.pgn', { type: 'application/x-chess-pgn' }));
|
||||
const c = document.getElementById('cp-canvas');
|
||||
for (const type of ['dragenter', 'dragover', 'drop'])
|
||||
c.dispatchEvent(new DragEvent(type, { dataTransfer: dt, bubbles: true, cancelable: true, clientX: 700, clientY: 400 }));
|
||||
return true;
|
||||
})()`);
|
||||
await sleep(2500);
|
||||
await shot(t, 'web-3-dropped.png');
|
||||
|
||||
// The classics: a game opens from the table (double click), its moves on the board.
|
||||
await t.actions(click(Number(process.env.CLASSICS_X || 100), Number(process.env.CLASSICS_Y || 70)));
|
||||
await sleep(1500);
|
||||
await t.actions(click(300, Number(process.env.ROW_Y || 322), 2));
|
||||
await sleep(1500);
|
||||
await shot(t, 'web-4-game.png');
|
||||
const steps = [];
|
||||
for (let i = 0; i < 12; i++) steps.push(...key(RIGHT));
|
||||
await t.actions([{ type: 'key', id: 'kb', actions: steps }]);
|
||||
await sleep(800);
|
||||
await shot(t, 'web-5-moves.png');
|
||||
|
||||
// Download the PGN of the game (the header's button).
|
||||
await t.actions(click(Number(process.env.DOWNLOAD_X || 1180), Number(process.env.DOWNLOAD_Y || 22)));
|
||||
await sleep(2000);
|
||||
const files = existsSync(ff.downloads) ? readdirSync(ff.downloads).filter((f) => f.endsWith('.pgn')) : [];
|
||||
check(files.length === 1, `a PGN downloaded: ${files.join(', ') || 'none'}`);
|
||||
if (files.length) {
|
||||
const text = readFileSync(join(ff.downloads, files[0]), 'utf8');
|
||||
check(/\[White "/.test(text) && /1\. /.test(text), 'the download is the game in PGN');
|
||||
writeFileSync(join(outDir, 'web-download.pgn'), text);
|
||||
}
|
||||
await shot(t, 'web-6-downloaded.png');
|
||||
|
||||
// A move on the board of a new game (Ctrl+N): e2–e4 by two clicks.
|
||||
await t.actions([{ type: 'key', id: 'kb', actions: key('') }]);
|
||||
await sleep(500);
|
||||
await t.actions([{ type: 'key', id: 'kb', actions: key('') }]);
|
||||
await sleep(800);
|
||||
await t.actions([{ type: 'key', id: 'kb', actions: key('n', [CTRL]) }]);
|
||||
await sleep(1200);
|
||||
await shot(t, 'web-7-new-game.png');
|
||||
if (process.env.E2 && process.env.E4) {
|
||||
const [x2, y2] = process.env.E2.split(',').map(Number);
|
||||
const [x4, y4] = process.env.E4.split(',').map(Number);
|
||||
await t.actions(click(x2, y2));
|
||||
await sleep(300);
|
||||
await t.actions(click(x4, y4));
|
||||
await sleep(1000);
|
||||
await shot(t, 'web-8-e4.png');
|
||||
}
|
||||
|
||||
// The settings and the marks survive a reload (the browser's storage).
|
||||
await t.navigate(`${base}?lang=en`);
|
||||
await started(t);
|
||||
await sleep(2500);
|
||||
await shot(t, 'web-9-reloaded.png');
|
||||
} finally {
|
||||
await ff.stop();
|
||||
server.kill();
|
||||
}
|
||||
for (const e of errors) console.log('console:', e);
|
||||
check(errors.length === 0, 'no panic or error in the console');
|
||||
console.log(failures ? `${failures} failed` : 'all ok');
|
||||
process.exit(failures ? 1 : 0);
|
||||
49
apps/web/check/device.test.mjs
Normal file
49
apps/web/check/device.test.mjs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
// Which devices get the program and which the page about the apps (page/device.js):
|
||||
//
|
||||
// node apps/web/check/device.test.mjs
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import vm from 'node:vm';
|
||||
|
||||
const source = readFileSync(fileURLToPath(new URL('../page/device.js', import.meta.url)), 'utf8');
|
||||
|
||||
// device.js in a window that looks like `d`.
|
||||
function classOf(d) {
|
||||
const media = { '(pointer: coarse)': d.coarse, '(any-pointer: fine)': d.fine };
|
||||
const window = {
|
||||
navigator: { userAgent: d.ua, platform: d.platform || '', maxTouchPoints: d.touch || 0, userAgentData: d.uad },
|
||||
screen: { width: d.screen[0], height: d.screen[1] },
|
||||
matchMedia: (q) => ({ matches: !!media[q] }),
|
||||
};
|
||||
window.window = window;
|
||||
vm.runInNewContext(source, window);
|
||||
return window.CPDevice.deviceClass();
|
||||
}
|
||||
|
||||
const MAC = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Safari/605.1.15';
|
||||
const cases = [
|
||||
['Windows laptop', { ua: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Firefox/159.0', screen: [1920, 1080], fine: true }, 'computer'],
|
||||
['Mac', { ua: MAC, platform: 'MacIntel', screen: [1512, 982], fine: true }, 'computer'],
|
||||
['laptop with a touch screen', { ua: 'Mozilla/5.0 (X11; Linux x86_64) Chrome/140.0', screen: [1366, 768], touch: 10, coarse: false, fine: true }, 'computer'],
|
||||
['Chromebook', { ua: 'Mozilla/5.0 (X11; CrOS x86_64 15000.0.0) Chrome/140.0', screen: [1366, 768], touch: 5, coarse: true }, 'computer'],
|
||||
['iPhone', { ua: 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_0 like Mac OS X) Mobile/15E148', screen: [390, 844], touch: 5, coarse: true }, 'iphone'],
|
||||
['iPhone asking for the desktop site', { ua: MAC, platform: 'MacIntel', screen: [390, 844], touch: 5, coarse: true }, 'iphone'],
|
||||
['iPad (says it is a Mac)', { ua: MAC, platform: 'MacIntel', screen: [820, 1180], touch: 5, coarse: true }, 'ipad'],
|
||||
['iPad mini', { ua: MAC, platform: 'MacIntel', screen: [744, 1133], touch: 5, coarse: true }, 'ipad'],
|
||||
['Android phone', { ua: 'Mozilla/5.0 (Linux; Android 14; Pixel 8) Chrome/140.0 Mobile', screen: [412, 915], touch: 5, coarse: true }, 'android-phone'],
|
||||
['Android tablet', { ua: 'Mozilla/5.0 (Linux; Android 14; SM-X710) Chrome/140.0', screen: [800, 1280], touch: 10, coarse: true }, 'android-tablet'],
|
||||
['Galaxy Fold folded', { ua: 'Mozilla/5.0 (Linux; Android 14; SM-F946B) Chrome/140.0 Mobile', screen: [344, 882], touch: 5, coarse: true }, 'android-phone'],
|
||||
['tablet asking for the desktop site', { ua: 'Mozilla/5.0 (X11; Linux x86_64) Chrome/140.0', screen: [800, 1280], touch: 10, coarse: true, fine: false }, 'tablet'],
|
||||
['phone asking for the desktop site', { ua: 'Mozilla/5.0 (X11; Linux x86_64) Chrome/140.0', screen: [412, 915], touch: 5, coarse: true, fine: false }, 'phone'],
|
||||
['a mobile Chromium by its client hints', { ua: 'Mozilla/5.0 (X11; Linux x86_64) Chrome/140.0', uad: { mobile: true, platform: 'Linux' }, screen: [412, 915], touch: 5, coarse: true }, 'phone'],
|
||||
];
|
||||
|
||||
let failed = 0;
|
||||
for (const [name, device, want] of cases) {
|
||||
const got = classOf(device);
|
||||
const ok = got === want;
|
||||
if (!ok) failed++;
|
||||
console.log(`${ok ? 'ok ' : 'FAIL'} ${name}: ${got}${ok ? '' : ` (want ${want})`}`);
|
||||
}
|
||||
console.log(failed ? `${failed} of ${cases.length} failed` : `all ${cases.length} ok`);
|
||||
process.exit(failed ? 1 : 0);
|
||||
|
|
@ -2,7 +2,8 @@
|
|||
// 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=1 the device page on any device (checks, screenshots of the site);
|
||||
// ?phone=android, ?phone=ios: that variant of it
|
||||
// ?phone=0 the program on any device
|
||||
// ?lang=xx the language (also of the program)
|
||||
(function () {
|
||||
|
|
@ -200,6 +201,8 @@
|
|||
var kind = CPDevice.deviceClass();
|
||||
if (asked === "1") {
|
||||
showDevicePage(kind === "computer" ? "phone" : kind);
|
||||
} else if (asked === "android" || asked === "ios") {
|
||||
showDevicePage(asked === "android" ? "android-phone" : "iphone");
|
||||
} else if (asked === "0" || kind === "computer" || storage(true) === "1") {
|
||||
startApp();
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue