mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-16 12:08:07 +01:00
This commit is contained in:
parent
8c19d17946
commit
e67b2d911e
4 changed files with 57 additions and 606 deletions
|
|
@ -33,14 +33,9 @@ import {initPluginSystem} from "siyuan-petal";
|
|||
|
||||
class App {
|
||||
constructor() {
|
||||
// TODO
|
||||
/// #if BROWSER
|
||||
registerServiceWorker(`${Constants.SERVICE_WORKER_PATH}?v=${Constants.SIYUAN_VERSION}`);
|
||||
/// #endif
|
||||
/// #if MOBILE
|
||||
registerServiceWorker(`${Constants.SERVICE_WORKER_PATH}?v=${Constants.SIYUAN_VERSION}`);
|
||||
/// #endif
|
||||
|
||||
addScriptSync(`${Constants.PROTYLE_CDN}/js/lute/lute.min.js?v=${Constants.SIYUAN_VERSION}`, "protyleLuteScript");
|
||||
addScript(`${Constants.PROTYLE_CDN}/js/protyle-html.js?v=${Constants.SIYUAN_VERSION}`, "protyleWcHtmlScript");
|
||||
addBaseURL();
|
||||
|
|
|
|||
|
|
@ -21,9 +21,13 @@ import {openMobileFileById} from "./editor";
|
|||
import {getSearch} from "../util/functions";
|
||||
import {initRightMenu} from "./menu";
|
||||
import {openChangelog} from "../boot/openChangelog";
|
||||
import {registerServiceWorker} from "../util/serviceWorker";
|
||||
|
||||
class App {
|
||||
constructor() {
|
||||
if (!window.webkit?.messageHandlers && !window.JSAndroid) {
|
||||
registerServiceWorker(`${Constants.SERVICE_WORKER_PATH}?v=${Constants.SIYUAN_VERSION}`);
|
||||
}
|
||||
addScriptSync(`${Constants.PROTYLE_CDN}/js/lute/lute.min.js?v=${Constants.SIYUAN_VERSION}`, "protyleLuteScript");
|
||||
addScript(`${Constants.PROTYLE_CDN}/js/protyle-html.js?v=${Constants.SIYUAN_VERSION}`, "protyleWcHtmlScript");
|
||||
addBaseURL();
|
||||
|
|
|
|||
|
|
@ -1,32 +1,17 @@
|
|||
// https://github.com/siyuan-note/siyuan/pull/8012
|
||||
export const registerServiceWorker = (scriptURL: string) => {
|
||||
if (window.navigator.serviceWorker) {
|
||||
// REF https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration
|
||||
window.navigator.serviceWorker
|
||||
.register(scriptURL, {
|
||||
scope: "./",
|
||||
type: "module",
|
||||
}).then(registration => {
|
||||
if (registration.installing) {
|
||||
console.debug("Service worker installing");
|
||||
} else if (registration.waiting) {
|
||||
console.debug("Service worker installed");
|
||||
} else if (registration.active) {
|
||||
console.debug("Service worker active");
|
||||
}
|
||||
registration.update();
|
||||
}).catch(e => {
|
||||
console.debug(`Registration failed with ${e}`);
|
||||
});
|
||||
|
||||
// REF https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/message_event
|
||||
window.navigator.serviceWorker.addEventListener("message", event => {
|
||||
// event is a MessageEvent object
|
||||
console.debug("client: onmessage", event);
|
||||
});
|
||||
|
||||
window.navigator.serviceWorker.ready.then(registration => {
|
||||
registration.active.postMessage("client: post message");
|
||||
});
|
||||
if (!'serviceWorker' in navigator || typeof (navigator.serviceWorker) === 'undefined' ||
|
||||
!'caches' in window || !'fetch' in window) {
|
||||
return
|
||||
}
|
||||
// REF https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration
|
||||
window.navigator.serviceWorker
|
||||
.register(scriptURL, {
|
||||
scope: "./",
|
||||
type: "module",
|
||||
}).then(registration => {
|
||||
registration.update();
|
||||
}).catch(e => {
|
||||
console.debug(`Registration failed with ${e}`);
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue