Fall back to download when Chrome refuses createWritable (Refs #20)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -38,6 +38,7 @@ After sealing, `data/seed.json` is still plaintext. Delete it (and see
|
||||
1. Open `final-wishes.html` from the drive, unlock, click **Edit**.
|
||||
2. Change things, **Done editing**, **Save** (or Ctrl/Cmd+S).
|
||||
- Chrome/Edge: pick the drive file once; later saves overwrite silently.
|
||||
- If Chrome refuses to write to the place you picked (a protected folder such as Downloads, Documents or your home folder), Save downloads the file instead and says so. Delete the empty file it left behind. Pick a subfolder you made, or the thumbdrive, to save in place.
|
||||
- Firefox/Safari: a new `final-wishes.html` downloads. Copy it over the
|
||||
old one on the drive.
|
||||
- **Cancel** (next to Save, edit mode only) throws away the unsaved
|
||||
|
||||
17
src/app.js
17
src/app.js
@@ -703,10 +703,19 @@
|
||||
if (!state.handle) {
|
||||
state.handle = await window.showSaveFilePicker({ suggestedName: 'final-wishes.html', types: [{ description: 'Final Wishes', accept: { 'text/html': ['.html'] } }] });
|
||||
}
|
||||
const w = await state.handle.createWritable();
|
||||
await w.write(html);
|
||||
await w.close();
|
||||
state.status = 'Saved to ' + state.handle.name + '.';
|
||||
try {
|
||||
const w = await state.handle.createWritable();
|
||||
await w.write(html);
|
||||
await w.close();
|
||||
state.status = 'Saved to ' + state.handle.name + '.';
|
||||
} catch (e) {
|
||||
if (!e || (e.name !== 'NotAllowedError' && e.name !== 'SecurityError')) throw e;
|
||||
// Chrome created the (empty) file but refuses to write it, e.g. a protected folder.
|
||||
// Forget the handle so the next Save asks again, and hand over a download instead.
|
||||
state.handle = null;
|
||||
downloadFile(html, 'final-wishes.html');
|
||||
state.status = 'Chrome would not let this page write to the chosen location, so final-wishes.html was downloaded instead. Delete the empty file it left behind and replace your old copy with the download.';
|
||||
}
|
||||
state.dirty = false;
|
||||
snapshot();
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user