refactor: migrate Full Reset buttons to core_func.clear_all_storage()
+page.svelte and e_app_help_tech.svelte both had inline Full Reset implementations (SW unregister + Cache + IDB + localStorage + sessionStorage). Replaced with core_func.clear_all_storage() for consistency with the sys bar and fix-sw page. Also fixes a title mismatch in e_app_help_tech Full Reset: title omitted SW unregistration even though the code was doing it. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -54,6 +54,7 @@ import {
|
|||||||
type key_val
|
type key_val
|
||||||
} from '$lib/stores/ae_stores';
|
} from '$lib/stores/ae_stores';
|
||||||
import { api } from '$lib/ae_api/api';
|
import { api } from '$lib/ae_api/api';
|
||||||
|
import { core_func } from '$lib/ae_core/ae_core_functions';
|
||||||
|
|
||||||
if (log_lvl) {
|
if (log_lvl) {
|
||||||
console.log(`Help - technical support component loaded`);
|
console.log(`Help - technical support component loaded`);
|
||||||
@@ -514,23 +515,7 @@ class:to-90%={$ae_sess.show_help_tech} -->
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('serviceWorker' in navigator) {
|
await core_func.clear_all_storage();
|
||||||
const registrations = await navigator.serviceWorker.getRegistrations();
|
|
||||||
for (const reg of registrations) await reg.unregister();
|
|
||||||
}
|
|
||||||
const cache_keys = await caches.keys();
|
|
||||||
for (const key of cache_keys) await caches.delete(key);
|
|
||||||
|
|
||||||
// Enumerate every IDB database on this origin and delete them all.
|
|
||||||
const db_list = await indexedDB.databases();
|
|
||||||
console.log('[clear_all] IDB databases found:', db_list.map((d) => d.name));
|
|
||||||
for (const db of db_list) {
|
|
||||||
if (db.name) indexedDB.deleteDatabase(db.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
localStorage.clear();
|
|
||||||
sessionStorage.clear();
|
|
||||||
|
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}}
|
}}
|
||||||
class="
|
class="
|
||||||
@@ -541,7 +526,7 @@ class:to-90%={$ae_sess.show_help_tech} -->
|
|||||||
transition-all
|
transition-all
|
||||||
{btn_class}
|
{btn_class}
|
||||||
"
|
"
|
||||||
title="Full Reset: Enumerate and delete ALL IndexedDB databases for this origin, clear localStorage and sessionStorage, then reload.">
|
title="Full Reset: Unregister service workers, clear SW Cache Storage, delete all IndexedDB databases, clear localStorage and sessionStorage, then reload.">
|
||||||
<Trash2 size="1em" class="inline-block" />
|
<Trash2 size="1em" class="inline-block" />
|
||||||
<span class="md:inline">Full Reset</span>
|
<span class="md:inline">Full Reset</span>
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import {
|
|||||||
slct,
|
slct,
|
||||||
slct_trigger
|
slct_trigger
|
||||||
} from '$lib/stores/ae_stores';
|
} from '$lib/stores/ae_stores';
|
||||||
|
import { core_func } from '$lib/ae_core/ae_core_functions';
|
||||||
interface Props {
|
interface Props {
|
||||||
/** @type {import('./$types').PageData} */
|
/** @type {import('./$types').PageData} */
|
||||||
data: any;
|
data: any;
|
||||||
@@ -139,22 +140,7 @@ onMount(() => {
|
|||||||
|
|
||||||
// Unregister service workers and clear Cache Storage so stale
|
// Unregister service workers and clear Cache Storage so stale
|
||||||
// SW-cached assets don't survive the reset and re-serve old bundles.
|
// SW-cached assets don't survive the reset and re-serve old bundles.
|
||||||
if ('serviceWorker' in navigator) {
|
await core_func.clear_all_storage();
|
||||||
const registrations = await navigator.serviceWorker.getRegistrations();
|
|
||||||
for (const reg of registrations) await reg.unregister();
|
|
||||||
}
|
|
||||||
const cache_keys = await caches.keys();
|
|
||||||
for (const key of cache_keys) await caches.delete(key);
|
|
||||||
|
|
||||||
const db_list = await indexedDB.databases();
|
|
||||||
console.log('[clear_all] IDB databases found:', db_list.map((d) => d.name));
|
|
||||||
for (const db of db_list) {
|
|
||||||
if (db.name) indexedDB.deleteDatabase(db.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
localStorage.clear();
|
|
||||||
sessionStorage.clear();
|
|
||||||
|
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}}
|
}}
|
||||||
class="btn btn-sm
|
class="btn btn-sm
|
||||||
|
|||||||
Reference in New Issue
Block a user