mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-21 14:34:06 +01:00
PWA support (desktop & mobile) (#8012)
* 🎨 Improve return to feature of the auth page * 🎨 PWA support * Update manifest.webmanifest * 🎨 add `service-worker.js` * Update service-worker.js * Update service-worker.js * Update service-worker.js
This commit is contained in:
parent
e1d3789ced
commit
93e4bb1adf
17 changed files with 816 additions and 30 deletions
|
|
@ -46,3 +46,27 @@ export const isFileAnnotation = (text: string) => {
|
|||
export const looseJsonParse = (text: string) => {
|
||||
return Function(`"use strict";return (${text})`)();
|
||||
};
|
||||
|
||||
/* redirect to auth page */
|
||||
export const redirectToCheckAuth = (to: string = window.location.href) => {
|
||||
const url = new URL(window.location.origin);
|
||||
url.pathname = '/check-auth';
|
||||
url.searchParams.set('to', to);
|
||||
window.location.href = url.href;
|
||||
}
|
||||
|
||||
export const isSiyuanUrl = (url: string) => {
|
||||
return /^siyuan:\/\/blocks\/\d{14}-\w{7}/.test(url);
|
||||
}
|
||||
|
||||
export const isWebSiyuanUrl = (url: string) => {
|
||||
return /^web\+siyuan:\/\/blocks\/\d{14}-\w{7}/.test(url);
|
||||
}
|
||||
|
||||
export const getIdFromSiyuanUrl = (url: string) => {
|
||||
return url.substring(16, 16 + 22);
|
||||
}
|
||||
|
||||
export const getIdFromWebSiyuanUrl = (url: string) => {
|
||||
return url.substring(20, 20 + 22);
|
||||
}
|
||||
|
|
|
|||
32
app/src/util/serviceWorker.ts
Normal file
32
app/src/util/serviceWorker.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// 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");
|
||||
});
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue