Make the lock-screen warning persist based on the stored setting

- Visibility is now driven entirely by the persisted dismissedLocalWarning
  setting, loaded directly on mount (via getSetting) so the banner reflects the
  stored choice immediately when the lock screen renders — before any unlock.
- Removed the ephemeral default-true local flag that caused the banner to
  reappear on reload until the user unlocked. A warningReady guard prevents a
  one-frame flash while the value loads.
This commit is contained in:
hermes-explorigin 2026-08-27 01:33:45 +00:00
parent ae23b47a92
commit d72f41418c
2 changed files with 31 additions and 9 deletions

15
dist/index.html vendored
View File

@ -5953,10 +5953,19 @@ function LockScreen($$anchor, $$props) {
set(isSetup, !await isVaultInitialized()); set(isSetup, !await isVaultInitialized());
} }
checkVault(); checkVault();
let showLocalWarning = /* @__PURE__ */ state(true); let warningReady = /* @__PURE__ */ state(false);
async function loadWarningSetting() {
try {
settings.dismissedLocalWarning = Boolean(await getSetting("dismissedLocalWarning"));
} catch (e) {
console.warn("Failed to load warning setting:", e);
}
set(warningReady, true);
}
loadWarningSetting();
async function dismissLocalWarning() { async function dismissLocalWarning() {
settings.dismissedLocalWarning = true; settings.dismissedLocalWarning = true;
set(showLocalWarning, false); set(warningReady, true);
try { try {
await settings.save(); await settings.save();
} catch (e) { } catch (e) {
@ -6027,7 +6036,7 @@ function LockScreen($$anchor, $$props) {
append($$anchor, div_2); append($$anchor, div_2);
}; };
if_block(node, ($$render) => { if_block(node, ($$render) => {
if (get(notLocal) && get(showLocalWarning) && !settings.dismissedLocalWarning) $$render(consequent); if (get(notLocal) && get(warningReady) && !settings.dismissedLocalWarning) $$render(consequent);
}); });
var node_1 = sibling(node, 2); var node_1 = sibling(node, 2);
var consequent_1 = ($$anchor) => { var consequent_1 = ($$anchor) => {

View File

@ -1,7 +1,7 @@
<script> <script>
import { app } from '../lib/stores/app.svelte.js' import { app } from '../lib/stores/app.svelte.js'
import { deriveKey, createTestPayload, verifyPassword } from '../lib/crypto/crypto.js' import { deriveKey, createTestPayload, verifyPassword } from '../lib/crypto/crypto.js'
import { saveVaultMeta, loadVaultMeta, isVaultInitialized, ensureTrashGroup } from '../lib/storage/db.js' import { saveVaultMeta, loadVaultMeta, isVaultInitialized, ensureTrashGroup, getSetting } from '../lib/storage/db.js'
import { startAutoLock } from '../lib/stores/security.svelte.js' import { startAutoLock } from '../lib/stores/security.svelte.js'
import { settings } from '../lib/stores/settings.svelte.js' import { settings } from '../lib/stores/settings.svelte.js'
import { autofocus } from '../lib/autofocus.js' import { autofocus } from '../lib/autofocus.js'
@ -19,13 +19,26 @@
} }
checkVault() checkVault()
// Dismissed warning state loads from the settings store (which loads on // Visibility of the web-server warning is driven by the persisted setting
// unlock/setup). Track locally so the banner hides immediately on click. // (dismissedLocalWarning). It is loaded directly on mount so the banner
let showLocalWarning = $state(true) // reflects the user's stored choice immediately when the lock screen shows,
// before any unlock happens. `warningReady` avoids a one-frame flash while
// the value is read from IndexedDB.
let warningReady = $state(false)
async function loadWarningSetting() {
try {
settings.dismissedLocalWarning = Boolean(await getSetting('dismissedLocalWarning'))
} catch (e) {
console.warn('Failed to load warning setting:', e)
}
warningReady = true
}
loadWarningSetting()
async function dismissLocalWarning() { async function dismissLocalWarning() {
settings.dismissedLocalWarning = true settings.dismissedLocalWarning = true
showLocalWarning = false warningReady = true
try { await settings.save() } catch (e) { console.warn('Failed to persist warning dismissal:', e) } try { await settings.save() } catch (e) { console.warn('Failed to persist warning dismissal:', e) }
} }
@ -98,7 +111,7 @@
<h1>Password Vault</h1> <h1>Password Vault</h1>
<p class="subtitle">{isSetup ? 'Create your vault' : 'Unlock your vault'}</p> <p class="subtitle">{isSetup ? 'Create your vault' : 'Unlock your vault'}</p>
{#if notLocal && showLocalWarning && !settings.dismissedLocalWarning} {#if notLocal && warningReady && !settings.dismissedLocalWarning}
<div class="warning-banner" role="alert"> <div class="warning-banner" role="alert">
<span class="warning-text">You're viewing this from a web server. For best security, download this HTML file and open it locally on your computer instead.</span> <span class="warning-text">You're viewing this from a web server. For best security, download this HTML file and open it locally on your computer instead.</span>
<button class="warning-dismiss" onclick={dismissLocalWarning} aria-label="Dismiss warning"></button> <button class="warning-dismiss" onclick={dismissLocalWarning} aria-label="Dismiss warning"></button>