Web version: databases read in a worker, the shelf's counts, Chrome and Edge remember chosen files
The page's reader: a Web Worker with a second instance of the program reads
a database (PGN, CBV, ZIP, 7Z) and gives back its text and index; the page
puts it together without reading it again (chess_core::PgnIndex,
PgnDatabase::into_index / from_index, serde behind a feature). A 13 MB CBV:
the longest frame 17 ms in Firefox, 67 ms in Chromium (1000 ms before).
platform::open_database is the same on both sides: away from the screen,
done when read. The shelf's cards count the games the same way (one file
at a time); the counts are kept through platform::fs.
Chrome, Edge (File System Access): a chosen file's handle is kept in the
browser's storage; at the next visit the file is read again by itself when
the browser allows it, else the card offers «Allow reading» (the browser's
own question). Files of different visits get folders of their own.
Checks: t.choose(files, open) for both browsers (in Chromium the handles of
the site's private file system stand for the dialog's); app.mjs checks the
draft, the question on leaving and the remembered file.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 17:50:54 +03:00
|
|
|
// The page's reader: a second instance of the program that reads the databases the user
|
|
|
|
|
// opens, so that the page does not stop while a large one is read
|
2026-10-30 20:42:18 +03:00
|
|
|
// (apps/desktop/src/platform/web/import.rs). One database at a time, in order: its files
|
|
|
|
|
// one by one (the user's are the browser's File objects, read here), then the reading.
|
|
|
|
|
import init, { reader_give, reader_read } from './chesspenguin_web.js';
|
Web version: databases read in a worker, the shelf's counts, Chrome and Edge remember chosen files
The page's reader: a Web Worker with a second instance of the program reads
a database (PGN, CBV, ZIP, 7Z) and gives back its text and index; the page
puts it together without reading it again (chess_core::PgnIndex,
PgnDatabase::into_index / from_index, serde behind a feature). A 13 MB CBV:
the longest frame 17 ms in Firefox, 67 ms in Chromium (1000 ms before).
platform::open_database is the same on both sides: away from the screen,
done when read. The shelf's cards count the games the same way (one file
at a time); the counts are kept through platform::fs.
Chrome, Edge (File System Access): a chosen file's handle is kept in the
browser's storage; at the next visit the file is read again by itself when
the browser allows it, else the card offers «Allow reading» (the browser's
own question). Files of different visits get folders of their own.
Checks: t.choose(files, open) for both browsers (in Chromium the handles of
the site's private file system stand for the dialog's); app.mjs checks the
draft, the question on leaving and the remembered file.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 17:50:54 +03:00
|
|
|
|
|
|
|
|
const ready = init();
|
|
|
|
|
|
|
|
|
|
self.onmessage = async (e) => {
|
|
|
|
|
await ready;
|
2026-10-30 20:42:18 +03:00
|
|
|
const { id, names, parts, count } = e.data;
|
|
|
|
|
let answer;
|
|
|
|
|
try {
|
|
|
|
|
for (let i = 0; i < names.length; i++) {
|
|
|
|
|
const part = parts[i];
|
|
|
|
|
const bytes = part instanceof Blob ? new Uint8Array(await part.arrayBuffer()) : part;
|
|
|
|
|
parts[i] = null;
|
|
|
|
|
reader_give(names[i], bytes);
|
|
|
|
|
}
|
|
|
|
|
answer = reader_read(count);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
// The program stopped (out of memory, most likely): this instance is spent.
|
|
|
|
|
self.postMessage({ id, crashed: String(err) });
|
|
|
|
|
self.close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
Web version: databases read in a worker, the shelf's counts, Chrome and Edge remember chosen files
The page's reader: a Web Worker with a second instance of the program reads
a database (PGN, CBV, ZIP, 7Z) and gives back its text and index; the page
puts it together without reading it again (chess_core::PgnIndex,
PgnDatabase::into_index / from_index, serde behind a feature). A 13 MB CBV:
the longest frame 17 ms in Firefox, 67 ms in Chromium (1000 ms before).
platform::open_database is the same on both sides: away from the screen,
done when read. The shelf's cards count the games the same way (one file
at a time); the counts are kept through platform::fs.
Chrome, Edge (File System Access): a chosen file's handle is kept in the
browser's storage; at the next visit the file is read again by itself when
the browser allows it, else the card offers «Allow reading» (the browser's
own question). Files of different visits get folders of their own.
Checks: t.choose(files, open) for both browsers (in Chromium the handles of
the site's private file system stand for the dialog's); app.mjs checks the
draft, the question on leaving and the remembered file.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 17:50:54 +03:00
|
|
|
answer.id = id;
|
|
|
|
|
self.postMessage(answer, answer.text ? [answer.text.buffer] : []);
|
|
|
|
|
};
|