[tauri] KeepHerSafeApps: App words for Keep her safe, and Android's own save screen through a narrow bridge

This commit is contained in:
2026-11-17 20:31:35 +01:00
parent 0b72ae05a2
commit 3c4463dbdd
9 changed files with 341 additions and 13 deletions
+36 -5
View File
@@ -54,15 +54,17 @@
}
// --- Keeping her (keep-her-safe.md) -------------------------------------
// The Android, iOS and desktop apps are installed by being apps (tauri-platforms.md D9):
// they ask to keep the garden after the first care, as an installed PWA does, and never
// show the hint to add the page to the home screen. Keep her safe speaks of the app, not a
// browser (keep-her-safe-apps.md A1).
const inApp = __ROSEA_SHELL__ === 'tauri';
const browserStorage = typeof navigator !== 'undefined' ? navigator.storage : undefined;
const keeping: RoseWiring['keeping'] = {
where: inApp ? 'app' : 'browser',
persisted: async () => (browserStorage?.persisted ? browserStorage.persisted() : null),
persist: async () => (browserStorage?.persist ? browserStorage.persist() : null)
};
// The Android, iOS and desktop apps are installed by being apps (tauri-platforms.md D9):
// they ask to keep the garden after the first care, as an installed PWA does, and never
// show the hint to add the page to the home screen.
const inApp = __ROSEA_SHELL__ === 'tauri';
const installed = (): boolean =>
inApp ||
matchMedia('(display-mode: standalone)').matches ||
@@ -76,7 +78,36 @@
keeping.persist().catch((error: unknown) => console.error('keep: asking the browser to keep the garden failed', error));
}
function saveFile(name: string, text: string): void {
/**
* Android's save screen, through the app's own bridge (keep-her-safe-apps.md A2): present
* only in the Android app, where `<a download>` does nothing. It answers with a window event,
* true when the file was written, false when the player stepped back (A4).
*/
const androidFile = inApp ? (window as Window & { roseaFile?: { save(name: string, text: string): void } }).roseaFile : undefined;
let saving: Promise<boolean> | undefined;
function saveFile(name: string, text: string): void | Promise<boolean> {
if (androidFile) {
// One save at a time: a second tap while the screen is open waits for the first answer.
if (saving) return saving;
saving = new Promise<boolean>((resolve) => {
const answer = (event: Event): void => {
window.removeEventListener('rosea-file-saved', answer);
saving = undefined;
resolve((event as CustomEvent<unknown>).detail === true);
};
window.addEventListener('rosea-file-saved', answer);
try {
androidFile.save(name, text);
} catch (error) {
console.error('keep: the app could not open the save screen', error);
window.removeEventListener('rosea-file-saved', answer);
saving = undefined;
resolve(false);
}
});
return saving;
}
// A file made here and handed over; nothing is sent anywhere.
const url = URL.createObjectURL(new Blob([text], { type: 'application/json' }));
const a = Object.assign(document.createElement('a'), { href: url, download: name });