Skip to content

Commit 2c07b8f

Browse files
feat(fileshare): warn user before navigating away mid-upload (#121)
Closes #116. Cryptify does not yet support upload resume (see #117), so navigating away during encryption/upload silently discards all progress. Attach a beforeunload listener only while encryptionState is Encrypting so the user gets the browser's built-in leave-page confirmation; detach as soon as the flow transitions to Done / Error / back to FileSelection. Co-authored-by: dobby-yivi-agent[bot] <275734547+dobby-yivi-agent[bot]@users.noreply.github.com>
1 parent 61bf4ae commit 2c07b8f

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/routes/(app)/fileshare/+page.svelte

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@
3535
3636
let EncryptState: EncryptState = $state(createDefaultEncryptState())
3737
38+
// Warn the user before they navigate away mid-upload. Cryptify does not
39+
// support resume yet, so navigating away silently aborts the upload and
40+
// discards all progress (see encryption4all/postguard-website#116,
41+
// encryption4all/postguard-website#117). The built-in browser dialog is
42+
// the only reliable cross-browser hook for this; modern browsers ignore
43+
// the returned message and show their own wording.
44+
$effect(() => {
45+
if (EncryptState.encryptionState !== EncryptionState.Encrypting) return
46+
const handler = (event: BeforeUnloadEvent) => {
47+
event.preventDefault()
48+
event.returnValue = ''
49+
}
50+
window.addEventListener('beforeunload', handler)
51+
return () => window.removeEventListener('beforeunload', handler)
52+
})
53+
3854
const fileshareJsonLd = {
3955
'@context': 'https://schema.org',
4056
'@type': 'WebApplication',

0 commit comments

Comments
 (0)