From 060a1c500e37e38506b6d41e1942ff8bcebabebf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Yingyi=20/=20=E9=A2=96=E9=80=B8?=
<49649786+Zuoqiu-Yingyi@users.noreply.github.com>
Date: Thu, 30 May 2024 22:30:50 +0800
Subject: [PATCH] :bug: Fix the request of PWA files without `Authentication`
Header (#11586)
---
app/src/assets/template/desktop/index.tpl | 2 +-
app/src/assets/template/mobile/index.tpl | 2 +-
app/src/util/serviceWorker.ts | 32 +++++++++++++++--------
3 files changed, 23 insertions(+), 13 deletions(-)
diff --git a/app/src/assets/template/desktop/index.tpl b/app/src/assets/template/desktop/index.tpl
index cbbe239bc..3a7824d87 100644
--- a/app/src/assets/template/desktop/index.tpl
+++ b/app/src/assets/template/desktop/index.tpl
@@ -6,7 +6,7 @@
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, viewport-fit=cover, user-scalable=no">
-
+
diff --git a/app/src/assets/template/mobile/index.tpl b/app/src/assets/template/mobile/index.tpl
index 830cbe107..40439b22a 100644
--- a/app/src/assets/template/mobile/index.tpl
+++ b/app/src/assets/template/mobile/index.tpl
@@ -3,7 +3,7 @@
-
+
diff --git a/app/src/util/serviceWorker.ts b/app/src/util/serviceWorker.ts
index e437249df..d7e3916bd 100644
--- a/app/src/util/serviceWorker.ts
+++ b/app/src/util/serviceWorker.ts
@@ -1,17 +1,27 @@
// https://github.com/siyuan-note/siyuan/pull/8012
-export const registerServiceWorker = (scriptURL: string, scope = "/", workerType: WorkerType = "module") => {
- if (!("serviceWorker" in navigator) || typeof (navigator.serviceWorker) === "undefined" ||
- !("caches" in window) || !("fetch" in window)) {
+export const registerServiceWorker = (
+ scriptURL: string,
+ options: RegistrationOptions = {
+ scope: "/",
+ type: "classic",
+ updateViaCache: "all",
+ },
+) => {
+
+ if (!("serviceWorker" in window.navigator)
+ || !("caches" in window)
+ || !("fetch" in window)
+ || navigator.serviceWorker == null
+ ) {
return;
}
+
// REF https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration
window.navigator.serviceWorker
- .register(scriptURL, {
- scope,
- type: workerType,
- }).then(registration => {
- registration.update();
- }).catch(e => {
- console.debug(`Registration failed with ${e}`);
- });
+ .register(scriptURL, options)
+ .then(registration => {
+ registration.update();
+ }).catch(e => {
+ console.debug(`Registration failed with ${e}`);
+ });
};