- a RPC framework is added for further use - fix an error that the service worker is not registered until the settings opened - added theme-color - settings: added a item to indicate the offline availablity
This commit is contained in:
parent
eb461d3708
commit
46e7f1aaea
11 changed files with 341 additions and 19 deletions
35
src/serviceworker/main.ts
Normal file
35
src/serviceworker/main.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
import { cleanupOutdatedCaches, precacheAndRoute } from "workbox-precaching";
|
||||
import { clientsClaim } from "workbox-core";
|
||||
import type { AnyCall } from "./services";
|
||||
|
||||
function checkServiceWorker(
|
||||
self: WorkerGlobalScope,
|
||||
): self is ServiceWorkerGlobalScope {
|
||||
return !!(self as unknown as ServiceWorkerGlobalScope).registration;
|
||||
}
|
||||
|
||||
if (checkServiceWorker(self)) {
|
||||
cleanupOutdatedCaches();
|
||||
precacheAndRoute(self.__WB_MANIFEST, {
|
||||
cleanURLs: false
|
||||
});
|
||||
|
||||
// auto update
|
||||
self.skipWaiting();
|
||||
clientsClaim();
|
||||
} else {
|
||||
throw new TypeError("This entry point must be run in a service worker");
|
||||
}
|
||||
|
||||
self.addEventListener("message", (event: MessageEvent<AnyCall>) => {
|
||||
if (event.data.method === "ping") {
|
||||
event.source.postMessage({id: event.data.id, jsonrpc: "2.0", result: undefined})
|
||||
} else {
|
||||
event.source.postMessage({
|
||||
error: {
|
||||
code: -32601,
|
||||
message: "Method not found"
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue