mirror of
https://github.com/misode/misode.github.io.git
synced 2026-05-02 21:52:54 +00:00
Catch errors when opening cache
This commit is contained in:
+3
-3
@@ -75,12 +75,12 @@ export const App = {
|
|||||||
}
|
}
|
||||||
console.debug(`[App] LocalStorage=${'localStorage' in window} Caches=${'caches' in window}`)
|
console.debug(`[App] LocalStorage=${'localStorage' in window} Caches=${'caches' in window}`)
|
||||||
|
|
||||||
App.version.watch(async (value) => {
|
App.version.watchRun(async (value) => {
|
||||||
console.debug(`[App.version.watch] ${value}`)
|
console.debug(`[App.version.watchRun] ${value}`)
|
||||||
App.schemasLoaded.set(false)
|
App.schemasLoaded.set(false)
|
||||||
await updateSchemas(value)
|
await updateSchemas(value)
|
||||||
App.schemasLoaded.set(true)
|
App.schemasLoaded.set(true)
|
||||||
console.debug(`[App.version.watch] Done! ${value}`)
|
console.debug(`[App.version.watchRun] Done! ${value}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
App.theme.watchRun((value) => {
|
App.theme.watchRun((value) => {
|
||||||
|
|||||||
+10
-3
@@ -176,15 +176,22 @@ async function getData<T = any>(url: string, fn: (v: any) => T = (v: any) => v):
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function deleteMatching(matches: (url: string) => boolean) {
|
async function deleteMatching(matches: (url: string) => boolean) {
|
||||||
const cache = await caches.open(CACHE_NAME)
|
console.debug(`[deleteMatching] Open cache ${CACHE_NAME}`)
|
||||||
|
let cache: Cache
|
||||||
|
try {
|
||||||
|
cache = await caches.open(CACHE_NAME)
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`[deleteMatching] Failed to open cache ${CACHE_NAME}: ${e.message}`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
console.debug(`[deleteMatching] Opened cache! ${CACHE_NAME}`)
|
||||||
const promises: Promise<boolean>[] = []
|
const promises: Promise<boolean>[] = []
|
||||||
console.debug(`[deleteMatching] ${CACHE_NAME} ${cache}`)
|
|
||||||
|
|
||||||
for (const request of await cache.keys()) {
|
for (const request of await cache.keys()) {
|
||||||
if (matches(request.url)) {
|
if (matches(request.url)) {
|
||||||
promises.push(cache.delete(request))
|
promises.push(cache.delete(request))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.debug(`[deleteMatching] ${CACHE_NAME} ${promises.length}`)
|
console.debug(`[deleteMatching] Removing ${promises.length} cache objects...`)
|
||||||
return (await Promise.all(promises)).length > 0
|
return (await Promise.all(promises)).length > 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ window.addEventListener("popstate", router);
|
|||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
console.debug(`[DOMContentLoaded] LocalStorage=${'localStorage' in window} Caches=${'caches' in window}`)
|
console.debug(`[DOMContentLoaded] LocalStorage=${'localStorage' in window} Caches=${'caches' in window}`)
|
||||||
App.version.trigger()
|
|
||||||
document.body.addEventListener("click", e => {
|
document.body.addEventListener("click", e => {
|
||||||
if (e.target instanceof Element
|
if (e.target instanceof Element
|
||||||
&& e.target.hasAttribute('data-link')
|
&& e.target.hasAttribute('data-link')
|
||||||
|
|||||||
@@ -37,8 +37,4 @@ export class Property<T> {
|
|||||||
}
|
}
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
trigger() {
|
|
||||||
this.watchers.forEach(w => w.watcher(this.value, null))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user