Web version: «Allow reading» checked, a kept copy lets the handle go, dropped files told apart in Chrome; docs: §9, the checks in Chromium

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
vrubelroman 2026-10-30 17:58:01 +03:00
parent f694bc768b
commit bda92c5675
8 changed files with 117 additions and 14 deletions

View file

@ -2884,6 +2884,7 @@ impl App {
*d = copy.clone();
}
self.library.forget(&path);
crate::platform::files::forget(&path);
self.library.select_db(&copy, ctx);
self.settings_dirty = true;
let ctx2 = ctx.clone();

View file

@ -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 ---
[
"A dropped file is not remembered: after a reload, choose the file again or keep a copy in the browser.",
"Перетащенный файл не запоминается: после перезагрузки выберите его снова или сохраните копию в браузере.",
"Un fichier déposé n'est pas mémorisé : après un rechargement, choisissez-le à nouveau ou gardez-en une copie dans le navigateur.",
"Eine hineingezogene Datei wird nicht gemerkt: Wählen Sie sie nach dem Neuladen erneut oder behalten Sie eine Kopie im Browser.",
"Un archivo arrastrado no se recuerda: tras recargar, elíjalo de nuevo o guarde una copia en el navegador.",
"Un file trascinato non viene ricordato: dopo il ricaricamento sceglilo di nuovo o conserva una copia nel browser.",
"Um arquivo arrastado não é lembrado: após recarregar, escolha-o novamente ou guarde uma cópia no navegador.",
"Sudrab tashlangan fayl eslab qolinmaydi: qayta yuklangandan keyin uni yana tanlang yoki brauzerda nusxasini saqlang.",
"Сүйреп әкелінген файл есте сақталмайды: қайта жүктегеннен кейін оны қайта таңдаңыз немесе браузерде көшірмесін сақтаңыз.",
],
[
"🔒 Allow reading",
"🔒 Разрешить чтение",

View file

@ -1304,7 +1304,12 @@ impl Library {
// A browser keeps no way back to a file the user chose (Firefox, Safari).
ui.vertical_centered(|ui| {
ui.add_space(40.0);
ui.label(tr("This browser doesn't remember files: after a reload, choose the file again or keep a copy in the browser."));
// Chrome and Edge remember chosen files, not dropped ones.
ui.label(if crate::platform::files::remembers_chosen() {
tr("A dropped file is not remembered: after a reload, choose the file again or keep a copy in the browser.")
} else {
tr("This browser doesn't remember files: after a reload, choose the file again or keep a copy in the browser.")
});
ui.add_space(8.0);
ui.horizontal(|ui| {
if ui.button(tr("↻ Choose the file again")).clicked() {

View file

@ -113,6 +113,15 @@ pub fn pick_databases(then: impl FnOnce(Picked) + Send + 'static) {
}
}
/// The browser remembers the files chosen in its dialog for the next visit (Chrome,
/// Edge); the others, and a computer, have no need or no way.
pub fn remembers_chosen() -> bool {
#[cfg(web)]
return super::web::remembered::supported();
#[cfg(not(web))]
false
}
/// The browser remembers the file `path` of an earlier visit and asks the user before
/// the page reads it again ([`allow_reading`]). Never on a computer.
pub fn waiting_to_read(path: &std::path::Path) -> bool {

View file

@ -181,6 +181,7 @@ pub fn allow(path: &Path, then: impl FnOnce(bool) + 'static) {
};
let back = bytes.is_some();
if let Some(bytes) = bytes {
log::info!("remembered file allowed again: {}", path.display());
WAITING.with_borrow_mut(|w| w.remove(&path));
super::vfs::put_opened(&path, bytes);
}

View file

@ -22,6 +22,10 @@ const check = (ok, what) => {
const DOWNLOAD = [Number(process.env.DOWNLOAD_X || 1263), Number(process.env.DOWNLOAD_Y || 24)];
const E2 = [519, 703];
const E4 = [519, 505];
// The card of «Test games» on the shelf after a reload (the draft's strip above it) and
// «Allow reading» on its pane.
const TEST_CARD = [300, 88];
const ALLOW = [70, 232];
const s = await session(appDir, 18766);
const { t } = s;
@ -131,6 +135,20 @@ try {
if (await t.evaluate(`typeof window.showOpenFilePicker === 'function'`)) {
// Chrome, Edge: the file chosen before the reload is read again by itself.
check(s.logs.some((l) => /remembered file read again: .*Test games\.pgn/.test(l)), 'the chosen file is remembered (File System Access)');
// When the browser asks first (its permission not kept): the card offers «Allow
// reading», the browser's question is answered «Allow», the file is read.
await t.beforeLoad(`FileSystemHandle.prototype.queryPermission = async () => 'prompt';
FileSystemHandle.prototype.requestPermission = async () => 'granted';`);
await t.navigate(`${s.base}?lang=en`);
await started();
await sleep(2500);
await t.click(...TEST_CARD);
await sleep(1500);
await shot('web-10-allow.png');
await t.click(...ALLOW);
await sleep(2500);
await shot('web-11-allowed.png');
check(s.logs.some((l) => /remembered file allowed again: .*Test games\.pgn/.test(l)), '«Allow reading» reads the remembered file again');
}
} finally {
await s.stop();

View file

@ -7,6 +7,7 @@
// t.navigate(url) · t.evaluate(js) · t.waitFor(js, ms) · t.screenshot()
// t.click(x, y, {double, right}) · t.key(key, mods, times) · t.setFiles(inputId, paths)
// t.choose(paths, open): the user chooses the files in the dialog open() brings up
// t.beforeLoad(js): js runs in every page loaded later, before its scripts
import { spawn } from 'node:child_process';
import { mkdirSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
@ -67,6 +68,8 @@ async function firefox(port) {
waitFor: waitFor(evaluate),
navigate: t.navigate,
screenshot: t.screenshot,
// `js` runs in every page loaded from now on, before the page's own scripts.
beforeLoad: (js) => ff.browser.send('script.addPreloadScript', { functionDeclaration: `() => { ${js} }`, contexts: [t.context] }),
click: async (x, y, { double = false, right = false } = {}) => {
const acts = [{ type: 'pointerMove', x, y }];
for (let i = 0; i < (double ? 2 : 1); i++) {
@ -181,6 +184,7 @@ async function chromium(port) {
send: s,
evaluate,
waitFor: waitFor(evaluate),
beforeLoad: (js) => s('Page.addScriptToEvaluateOnNewDocument', { source: js }),
navigate: async (url) => {
await s('Page.navigate', { url });
await waitFor(evaluate)(`document.readyState === 'complete'`, 30000);