[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
+77
View File
@@ -0,0 +1,77 @@
# Keep her safe, inside the apps (G-T4)
Status: built on `feature/keep-her-safe-apps`, 2026-11-17. Closes the release blocker found in
[`tauri-platforms.md`](tauri-platforms.md) G-T4 and, if a round trip is seen, G-T5. Builds on
[`keep-her-safe.md`](keep-her-safe.md). Review:
[`feature-keep-her-safe-apps.md`](../reviews/feature-keep-her-safe-apps.md).
## 1. Why and what, in the player's terms
*Keep her safe* is how a player makes sure their rose cannot be lost, and how she moves to another
device. In the browser it tells the truth about the browser. In the Android and desktop apps it
said the same words, and they were wrong there: *This browser may clear her if the garden is not
opened for a long time* — there is no browser, and an app's own storage is not cleared for being
left alone. It offered *Ask the browser to keep her*, which always answers no in an app. And on
Android, *Save her to a file* did nothing at all (measured on the tablet). A player was told she
might be lost, and the one remedy failed without a word.
Now, in the apps:
- She says where she lives, truly and calmly: *She lives in this app, on this device, until the app
is removed. A saved file keeps her anywhere.* No button that cannot work.
- *Save her to a file* opens Android's own *save* screen; the player chooses where (the phone, a
memory card, a cloud folder they already use). When the file is written, the garden says
*She is in that file now.* If they step back, nothing is said.
- *Bring her back from a file* opens Android's own file picker, as before.
The PWA is unchanged.
## 2. Technical architecture
```mermaid
flowchart LR
ks["packages/ui<br/>KeepSafe.svelte"] -->|"wiring.saveFile(name, text)<br/>wiring.keeping.where"| app["apps/rosea<br/>App.svelte"]
app -->|"PWA / Windows: &lt;a download&gt;"| browser["browser / WebView2 download"]
app -->|"Android: window.roseaFile.save(name, text)"| bridge["apps/rosea-tauri/android/java<br/>MainActivity.kt (copied into gen/)"]
bridge -->|"ACTION_CREATE_DOCUMENT"| saf["Android's save screen<br/>(Storage Access Framework)"]
saf -->|"uri"| bridge
bridge -->|"write, then event 'rosea-file-saved' (true|false)"| app
```
| # | Decision | Why |
|:--|:--|:--|
| A1 | **The words follow where she lives**: `RoseWiring.keeping.where` is `'browser'` or `'app'`, set in `App.svelte` from `__ROSEA_SHELL__`. In an app, `KeepSafe` shows `safe.app` and never asks `persist()`. | The words state facts about the platform; the platform decides which facts are true (lessons/design.md). The package chooses among its own words; the app only says where it is. |
| A2 | **Android saves through a small Kotlin bridge**, not a Tauri plugin: `MainActivity` adds one JavaScript interface, `roseaFile.save(name, text)`, which opens `ACTION_CREATE_DOCUMENT` through Tauri's own `launchActivityForResult` and writes the text to the chosen place. | No new dependency, no download, no IPC and no capability: the shell still grants the page nothing through Tauri. The Storage Access Framework needs **no permission** on any Android version (the APK check still demands none). A plugin (dialog + fs) would bring IPC, a capability, a CSP change and two packages for one file. iOS will need its own answer (G-T1). |
| A3 | **The bridge takes only what a rose file is**: a name like `rose-2026-11-17.json` and text up to 8 MB; anything else is refused before the picker opens. One save at a time. | The interface is reachable by any script in the page; the page is our own and has no network, but the bridge stays as narrow as the job. |
| A4 | **The answer comes back as a window event** (`rosea-file-saved`, `true` or `false`), dispatched by `evaluateJavascript`; `saveFile` returns a promise of it. The garden says *She is in that file now.* only on `true`. | The player sees the system screen close; without a word they cannot know whether it worked. A cancelled save is the player's choice and is not commented on. |
| A5 | `MainActivity.kt` lives in `apps/rosea-tauri/android/java/` and is copied over the generated one by `scripts/android.ts apply`; `check` refuses an APK build without it. The bridge class carries `@Keep` so a minified release build cannot strip it. | `gen/` is never committed (D6 in tauri-platforms.md). |
| A6 | Windows keeps `<a download>`: WebView2 saves to *Downloads* and shows its own download flyout (measured in the platform review). | It works; the browser's own feedback is the confirmation there, as in the PWA. |
## 3. Risk analysis
| Risk | Answer |
|:--|:--|
| **Fear**: words that say she may be lost. | Removed in the apps (A1). The new sentence says the one true condition (removing the app) and the remedy. |
| **A broken promise**: a save that does nothing. | Fixed on Android (A2) and confirmed to the player (A4). |
| **Location in the file.** | Unchanged: the file never holds the town (keep-her-safe.md K4). |
| **Bytes leaving the device.** | Only where the player chooses in Android's save screen. If they choose a cloud folder, that app uploads it — their choice, made in the system's own screen. The game still has no `INTERNET`. |
| **A script calling the bridge.** | Only the game's own page runs in the WebView (no network, `'self'` CSP). The bridge refuses any other name or a huge text, and it can only open a screen the player must confirm. |
| **Reachability, guilt, counting.** | None: nothing new reaches anyone or counts anything. |
## 4. Gap analysis
Closes G-T4 for Android and Windows. G-T5 (bringing her back) is closed only by a round trip seen on
the device. iOS stays G-T1: WKWebView will need its own save (a share sheet or a document picker).
## 5. Verification matrix
| Case | Kind | Where |
|:--|:--|:--|
| In an app: the app sentence, no *Ask*, `persisted()` never asked | unit | `packages/ui/test/keep-safe.test.ts` |
| In a browser: the browser sentences as before | unit | same, and the existing e2e |
| `saveFile` answering `true` → *She is in that file now.*; `false` or nothing → silence | unit | same |
| The bridge's name and size rules | unit | `apps/rosea-tauri/test/android-bridge.test.ts` (reads the Kotlin source's constants) and the Kotlin itself |
| `android.ts check` refuses a project without Rosea's `MainActivity` | unit | `apps/rosea-tauri/test/android-privacy.test.ts` |
| The APK still asks for no permission | artefact | `pnpm tauri:android` → aapt2 |
| Android: save opens the system screen, a file is written, the garden says so; bring her back from that file | device | review (tablet) |
| Windows: save downloads the file | device | `e2e/apps/check-garden.ts desktop` |