Skip to content

Commit

Permalink
update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
maxence-charriere committed Oct 2, 2024
1 parent 34ebbe9 commit 23262c7
Show file tree
Hide file tree
Showing 24 changed files with 1,559 additions and 1,587 deletions.
142 changes: 70 additions & 72 deletions docs/actions.html

Large diffs are not rendered by default.

41 changes: 27 additions & 14 deletions docs/app-worker.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,44 @@
// -----------------------------------------------------------------------------
// PWA
// -----------------------------------------------------------------------------
const cacheName = "app-" + "014798ad69974caff88fe5d7b8abad9690508a5f";
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/js/prism.js","https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1013306768105236","https://raw.githubusercontent.com/maxence-charriere/go-app/master/docs/web/icon.png"];

self.addEventListener("install", (event) => {
console.log("installing app worker 014798ad69974caff88fe5d7b8abad9690508a5f");
event.waitUntil(installWorker());
const cacheName = "app-" + "174e4030da44f4b3255aedb965beea90a03cb3dc";
const resourcesToCache = ["https://raw.githubusercontent.com/maxence-charriere/go-app/master/docs/web/icon.png","https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1013306768105236","/web/js/prism.js","/web/documents/what-is-go-app.md","/web/documents/updates.md","/web/documents/home.md","/web/documents/home-next.md","/web/css/prism.css","/web/css/docs.css","/web/app.wasm","/wasm_exec.js","/manifest.webmanifest","/app.js","/app.css","/"];

self.addEventListener("install", async (event) => {
try {
console.log("installing app worker 174e4030da44f4b3255aedb965beea90a03cb3dc");
await installWorker();
await self.skipWaiting();
} catch (error) {
console.error("error during installation:", error);
}
});

async function installWorker() {
const cache = await caches.open(cacheName);
await cache.addAll(resourcesToCache);
await self.skipWaiting(); // Use this new service worker
}

self.addEventListener("activate", (event) => {
event.waitUntil(deletePreviousCaches());
console.log("app worker 014798ad69974caff88fe5d7b8abad9690508a5f is activated");
self.addEventListener("activate", async (event) => {
try {
await deletePreviousCaches(); // Await cache cleanup
await self.clients.claim(); // Ensure the service worker takes control of the clients
console.log("app worker 174e4030da44f4b3255aedb965beea90a03cb3dc is activated");
} catch (error) {
console.error("error during activation:", error);
}
});

async function deletePreviousCaches() {
keys = await caches.keys();
keys.forEach(async (key) => {
if (key != cacheName) {
console.log("deleting", key, "cache");
await caches.delete(key);
try {
console.log("deleting", key, "cache");
await caches.delete(key);
} catch (err) {
console.error("deleting", key, "cache failed:", err);
}
}
});
}
Expand All @@ -35,11 +48,11 @@ self.addEventListener("fetch", (event) => {
});

async function fetchWithCache(request) {
cachedResponse = await caches.match(request);
const cachedResponse = await caches.match(request);
if (cachedResponse) {
return cachedResponse;
}
return fetch(request);
return await fetch(request);
}

// -----------------------------------------------------------------------------
Expand Down
31 changes: 15 additions & 16 deletions docs/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var goappOnAppInstallChange = function () {
goappAppInstallChangedBeforeWasmLoaded = true;
};

const goappEnv = {"GOAPP_INTERNAL_URLS":"null","GOAPP_ROOT_PREFIX":"/","GOAPP_STATIC_RESOURCES_URL":"/web","GOAPP_VERSION":"014798ad69974caff88fe5d7b8abad9690508a5f"};
const goappEnv = {"GOAPP_INTERNAL_URLS":"null","GOAPP_ROOT_PREFIX":"/","GOAPP_STATIC_RESOURCES_URL":"/web","GOAPP_VERSION":"174e4030da44f4b3255aedb965beea90a03cb3dc"};
const goappLoadingLabel = "go-app documentation {progress}%";
const goappWasmContentLength = "";
const goappWasmContentLengthHeader = "";
Expand All @@ -31,18 +31,16 @@ goappInitWebAssembly();
// -----------------------------------------------------------------------------
async function goappInitServiceWorker() {
if ("serviceWorker" in navigator) {
window.addEventListener("load", async () => {
try {
const registration = await navigator.serviceWorker.register(
"/app-worker.js"
);
goappServiceWorkerRegistration = registration;
goappSetupNotifyUpdate(registration);
goappSetupPushNotification();
} catch (err) {
console.error("goapp service worker registration failed: ", err);
}
});
try {
const registration = await navigator.serviceWorker.register(
"/app-worker.js"
);
goappServiceWorkerRegistration = registration;
goappSetupNotifyUpdate(registration);
goappSetupPushNotification();
} catch (err) {
console.error("goapp service worker registration failed: ", err);
}
}
}

Expand All @@ -64,10 +62,11 @@ function goappSetupNotifyUpdate(registration) {
if (!navigator.serviceWorker.controller) {
return;
}
if (newSW.state != "activated") {
return;

switch (newSW.state) {
case "installed":
goappOnUpdate();
}
goappOnUpdate();
});
});
}
Expand Down
Loading

0 comments on commit 23262c7

Please sign in to comment.