@arkade-os/sdk 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,28 +6,10 @@ async function setupServiceWorker(path) {
|
|
|
6
6
|
if (!("serviceWorker" in navigator)) {
|
|
7
7
|
throw new Error("Service workers are not supported in this browser");
|
|
8
8
|
}
|
|
9
|
-
//
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
registration = existingRegistration;
|
|
14
|
-
// Force unregister and re-register to ensure we get the latest version
|
|
15
|
-
await existingRegistration.unregister();
|
|
16
|
-
}
|
|
17
|
-
registration = await navigator.serviceWorker.register(path);
|
|
18
|
-
// Handle updates
|
|
19
|
-
registration.addEventListener("updatefound", () => {
|
|
20
|
-
const newWorker = registration.installing;
|
|
21
|
-
if (!newWorker)
|
|
22
|
-
return;
|
|
23
|
-
newWorker.addEventListener("statechange", () => {
|
|
24
|
-
if (newWorker.state === "activated" &&
|
|
25
|
-
navigator.serviceWorker.controller) {
|
|
26
|
-
console.info("Service worker activated, reloading...");
|
|
27
|
-
window.location.reload();
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
});
|
|
9
|
+
// register service worker
|
|
10
|
+
const registration = await navigator.serviceWorker.register(path);
|
|
11
|
+
// force update to ensure the service worker is active
|
|
12
|
+
registration.update();
|
|
31
13
|
const serviceWorker = registration.active || registration.waiting || registration.installing;
|
|
32
14
|
if (!serviceWorker) {
|
|
33
15
|
throw new Error("Failed to get service worker instance");
|
|
@@ -37,11 +19,7 @@ async function setupServiceWorker(path) {
|
|
|
37
19
|
await new Promise((resolve) => {
|
|
38
20
|
if (!serviceWorker)
|
|
39
21
|
return resolve();
|
|
40
|
-
serviceWorker.addEventListener("
|
|
41
|
-
if (serviceWorker.state === "activated") {
|
|
42
|
-
resolve();
|
|
43
|
-
}
|
|
44
|
-
});
|
|
22
|
+
serviceWorker.addEventListener("activate", () => resolve());
|
|
45
23
|
});
|
|
46
24
|
}
|
|
47
25
|
return serviceWorker;
|
|
@@ -3,28 +3,10 @@ export async function setupServiceWorker(path) {
|
|
|
3
3
|
if (!("serviceWorker" in navigator)) {
|
|
4
4
|
throw new Error("Service workers are not supported in this browser");
|
|
5
5
|
}
|
|
6
|
-
//
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
registration = existingRegistration;
|
|
11
|
-
// Force unregister and re-register to ensure we get the latest version
|
|
12
|
-
await existingRegistration.unregister();
|
|
13
|
-
}
|
|
14
|
-
registration = await navigator.serviceWorker.register(path);
|
|
15
|
-
// Handle updates
|
|
16
|
-
registration.addEventListener("updatefound", () => {
|
|
17
|
-
const newWorker = registration.installing;
|
|
18
|
-
if (!newWorker)
|
|
19
|
-
return;
|
|
20
|
-
newWorker.addEventListener("statechange", () => {
|
|
21
|
-
if (newWorker.state === "activated" &&
|
|
22
|
-
navigator.serviceWorker.controller) {
|
|
23
|
-
console.info("Service worker activated, reloading...");
|
|
24
|
-
window.location.reload();
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
6
|
+
// register service worker
|
|
7
|
+
const registration = await navigator.serviceWorker.register(path);
|
|
8
|
+
// force update to ensure the service worker is active
|
|
9
|
+
registration.update();
|
|
28
10
|
const serviceWorker = registration.active || registration.waiting || registration.installing;
|
|
29
11
|
if (!serviceWorker) {
|
|
30
12
|
throw new Error("Failed to get service worker instance");
|
|
@@ -34,11 +16,7 @@ export async function setupServiceWorker(path) {
|
|
|
34
16
|
await new Promise((resolve) => {
|
|
35
17
|
if (!serviceWorker)
|
|
36
18
|
return resolve();
|
|
37
|
-
serviceWorker.addEventListener("
|
|
38
|
-
if (serviceWorker.state === "activated") {
|
|
39
|
-
resolve();
|
|
40
|
-
}
|
|
41
|
-
});
|
|
19
|
+
serviceWorker.addEventListener("activate", () => resolve());
|
|
42
20
|
});
|
|
43
21
|
}
|
|
44
22
|
return serviceWorker;
|