[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
+4
View File
@@ -83,7 +83,11 @@ export const en = {
ask: 'Ask the browser to keep her',
refused: 'The browser did not promise. A saved file keeps her for sure.',
install: 'On an iPhone or iPad, add the garden to your Home Screen to keep her.',
/** In the Android, iOS and desktop apps (keep-her-safe-apps.md A1): no browser, and nothing clears her for being left alone. */
app: 'She lives in this app, on this device, until the app is removed. A saved file keeps her anywhere.',
save: 'Save her to a file',
/** Said only when the app knows the file was written (A4); a cancelled save is not commented on. */
saved: 'She is in that file now.',
fileNote: 'The file holds her care and when it was given. It never holds your town.',
bringBack: 'Bring her back from a file',
broughtBack: (n: number): string =>
+12 -4
View File
@@ -14,7 +14,11 @@
let refused = $state(false);
let said = $state('');
const inApp = $derived(wiring.keeping.where === 'app');
$effect(() => {
// In an app there is no browser to ask, and the answer would always be no (A1).
if (inApp) return;
wiring.keeping.persisted().then(
(p) => (persisted = p),
(error: unknown) => {
@@ -38,7 +42,9 @@
async function save(): Promise<void> {
try {
const file = await wiring.exportRose(currentKey);
wiring.saveFile(`rose-${today}.json`, JSON.stringify(file, null, 1));
said = '';
const written = await wiring.saveFile(`rose-${today}.json`, JSON.stringify(file, null, 1));
if (written === true) said = en.rose.safe.saved;
} catch (error) {
console.error('keep: the rose could not be saved to a file', error);
}
@@ -64,13 +70,15 @@
<section class="safe" aria-labelledby="{uid}-title">
<h3 id="{uid}-title">{en.rose.safe.title}</h3>
{#if persisted !== undefined}
{#if inApp}
<p>{en.rose.safe.app}</p>
{:else if persisted !== undefined}
<p>{refused ? en.rose.safe.refused : persisted === true ? en.rose.safe.kept : persisted === false ? en.rose.safe.mayClear : en.rose.safe.unknown}</p>
{/if}
{#if persisted === false && !refused}
{#if !inApp && persisted === false && !refused}
<button type="button" class="quiet" onclick={ask}>{en.rose.safe.ask}</button>
{/if}
{#if wiring.installHint}
{#if !inApp && wiring.installHint}
<p>{en.rose.safe.install}</p>
{/if}
+12 -2
View File
@@ -30,10 +30,20 @@ export interface RoseWiring {
};
/** Hears care, a petal or a rose brought back in another tab (two-tabs.md); returns the way to stop. */
readonly changes?: (listener: () => void) => () => void;
/** Hands the player a file to keep. */
readonly saveFile: (name: string, text: string) => void;
/**
* Hands the player a file to keep. Where the app learns the outcome (Android's save screen,
* keep-her-safe-apps.md A4) it answers true when written and false when the player stepped back;
* where it cannot know (a browser download) it answers nothing.
*/
readonly saveFile: (name: string, text: string) => void | Promise<boolean>;
/** The browser's promise to keep the garden: true, false, or null when it cannot say. */
readonly keeping: {
/**
* Where she lives (keep-her-safe-apps.md A1): `'browser'` (the default) or `'app'`, the
* Android, iOS and desktop apps, where there is no browser to ask and nothing clears her
* for being left alone.
*/
readonly where?: 'browser' | 'app';
readonly persisted: () => Promise<boolean | null>;
readonly persist: () => Promise<boolean | null>;
};
+43
View File
@@ -229,6 +229,49 @@ describe('keep her safe (keep-her-safe.md)', () => {
await waitFor(() => expect(document.getElementById('rose-numbers')?.textContent).toContain(`${en.rose.daysOfCare}1`));
});
it('in an app, says where she lives and asks no browser, which is not there (keep-her-safe-apps.md A1)', async () => {
const persisted = vi.fn(async () => false);
const persist = vi.fn(async () => false);
render(Rose, { wiring: wiring({ keeping: { where: 'app', persisted, persist }, installHint: true }), timeZone: ZONE });
await open();
expect(await screen.findByText(en.rose.safe.app)).toBeTruthy();
for (const said of [en.rose.safe.mayClear, en.rose.safe.unknown, en.rose.safe.kept, en.rose.safe.install]) {
expect(screen.queryByText(said)).toBeNull();
}
expect(screen.queryByRole('button', { name: en.rose.safe.ask })).toBeNull();
expect(screen.getByRole('button', { name: en.rose.safe.save })).toBeTruthy();
expect(screen.getByLabelText(en.rose.safe.bringBack)).toBeTruthy();
expect(persisted).not.toHaveBeenCalled();
expect(persist).not.toHaveBeenCalled();
});
it('the app words never speak of a browser', () => {
expect(en.rose.safe.app).not.toMatch(/browser/i);
expect(en.rose.safe.saved).not.toMatch(/browser/i);
});
it('says she is in the file only when the app knows it was written (A4)', async () => {
let answer = true;
render(Rose, { wiring: wiring({ saveFile: async () => answer }), timeZone: ZONE });
await open();
const save = screen.getByRole('button', { name: en.rose.safe.save });
await fireEvent.click(save);
expect(await screen.findByText(en.rose.safe.saved)).toBeTruthy();
// A second save the player steps back from: the earlier word goes, and nothing is said.
answer = false;
await fireEvent.click(save);
await waitFor(() => expect(screen.queryByText(en.rose.safe.saved)).toBeNull());
});
it('a browser download says nothing of its own: the browser shows it', async () => {
const w = wiring();
render(Rose, { wiring: w, timeZone: ZONE });
await open();
await fireEvent.click(screen.getByRole('button', { name: en.rose.safe.save }));
await waitFor(() => expect(w.saved).toHaveLength(1));
expect(screen.queryByText(en.rose.safe.saved)).toBeNull();
});
it('a file that is not a rose is said calmly, and nothing changes', async () => {
const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
render(Rose, { wiring: wiring({ importRose: () => Promise.reject(new TypeError('storage: this file does not hold a rose')) }), timeZone: ZONE });