123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- const cacheName = "app-" + "08848207254ed19206a7e0901b6c869dca9004c8";
- const resourcesToCache = ["/","/app.css","/app.js","/manifest.webmanifest","/wasm_exec.js","/web/app.wasm","/web/css/docs.css","/web/css/prism.css","/web/documents/home-next.md","/web/documents/home.md","/web/documents/updates.md","/web/documents/what-is-go-app.md","/web/icon.png","/web/js/prism.js","https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500\u0026display=swap","https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1013306768105236"];
- self.addEventListener("install", (event) => {
- console.log("installing app worker 08848207254ed19206a7e0901b6c869dca9004c8");
- event.waitUntil(
- caches
- .open(cacheName)
- .then((cache) => {
- return cache.addAll(resourcesToCache);
- })
- .then(() => {
- self.skipWaiting();
- })
- );
- });
- self.addEventListener("activate", (event) => {
- event.waitUntil(
- caches.keys().then((keyList) => {
- return Promise.all(
- keyList.map((key) => {
- if (key !== cacheName) {
- return caches.delete(key);
- }
- })
- );
- })
- );
- console.log("app worker 08848207254ed19206a7e0901b6c869dca9004c8 is activated");
- });
- self.addEventListener("fetch", (event) => {
- event.respondWith(
- caches.match(event.request).then((response) => {
- return response || fetch(event.request);
- })
- );
- });
- self.addEventListener("push", (event) => {
- if (!event.data || !event.data.text()) {
- return;
- }
- const notification = JSON.parse(event.data.text());
- if (!notification) {
- return;
- }
- const title = notification.title;
- delete notification.title;
- if (!notification.data) {
- notification.data = {};
- }
- let actions = [];
- for (let i in notification.actions) {
- const action = notification.actions[i];
- actions.push({
- action: action.action,
- path: action.path,
- });
- delete action.path;
- }
- notification.data.goapp = {
- path: notification.path,
- actions: actions,
- };
- delete notification.path;
- event.waitUntil(self.registration.showNotification(title, notification));
- });
- self.addEventListener("notificationclick", (event) => {
- event.notification.close();
- const notification = event.notification;
- let path = notification.data.goapp.path;
- for (let i in notification.data.goapp.actions) {
- const action = notification.data.goapp.actions[i];
- if (action.action === event.action) {
- path = action.path;
- break;
- }
- }
- event.waitUntil(
- clients
- .matchAll({
- type: "window",
- })
- .then((clientList) => {
- for (var i = 0; i < clientList.length; i++) {
- let client = clientList[i];
- if ("focus" in client) {
- client.focus();
- client.postMessage({
- goapp: {
- type: "notification",
- path: path,
- },
- });
- return;
- }
- }
- if (clients.openWindow) {
- return clients.openWindow(path);
- }
- })
- );
- });
|