service worker fixes
This commit is contained in:
parent
262659d4fe
commit
85e2cceca5
5 changed files with 137 additions and 59 deletions
|
@ -532,31 +532,54 @@ if(document.getElementById("form")){
|
|||
}
|
||||
}
|
||||
//this currently does not work, and need to be implemented better at some time.
|
||||
/*
|
||||
if ("serviceWorker" in navigator){
|
||||
if(!localStorage.getItem("SWMode")){
|
||||
localStorage.setItem("SWMode","true");
|
||||
}
|
||||
class SW{
|
||||
static worker:undefined|ServiceWorker;
|
||||
static setMode(mode:"false"|"offlineOnly"|"true"){
|
||||
if(this.worker){
|
||||
this.worker.postMessage({data:mode,code:"setMode"});
|
||||
}
|
||||
}
|
||||
static checkUpdate(){
|
||||
if(this.worker){
|
||||
this.worker.postMessage({code:"CheckUpdate"});
|
||||
}
|
||||
}
|
||||
static forceClear(){
|
||||
if(this.worker){
|
||||
this.worker.postMessage({code:"ForceClear"});
|
||||
}
|
||||
}
|
||||
}
|
||||
export {SW};
|
||||
if ("serviceWorker" in navigator){
|
||||
navigator.serviceWorker.register("/service.js", {
|
||||
scope: "/",
|
||||
}).then((registration) => {
|
||||
let serviceWorker:ServiceWorker;
|
||||
if (registration.installing) {
|
||||
serviceWorker = registration.installing;
|
||||
console.log("installing");
|
||||
} else if (registration.waiting) {
|
||||
serviceWorker = registration.waiting;
|
||||
console.log("waiting");
|
||||
} else if (registration.active) {
|
||||
serviceWorker = registration.active;
|
||||
console.log("active");
|
||||
}
|
||||
if (serviceWorker) {
|
||||
console.log(serviceWorker.state);
|
||||
serviceWorker.addEventListener("statechange", (e) => {
|
||||
console.log(serviceWorker.state);
|
||||
});
|
||||
}
|
||||
let serviceWorker:ServiceWorker|undefined;
|
||||
if (registration.installing) {
|
||||
serviceWorker = registration.installing;
|
||||
console.log("installing");
|
||||
} else if (registration.waiting) {
|
||||
serviceWorker = registration.waiting;
|
||||
console.log("waiting");
|
||||
} else if (registration.active) {
|
||||
serviceWorker = registration.active;
|
||||
console.log("active");
|
||||
}
|
||||
SW.worker=serviceWorker;
|
||||
SW.setMode(localStorage.getItem("SWMode") as "false"|"offlineOnly"|"true");
|
||||
if (serviceWorker) {
|
||||
console.log(serviceWorker.state);
|
||||
serviceWorker.addEventListener("statechange", (_) => {
|
||||
console.log(serviceWorker.state);
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
const switchurl = document.getElementById("switch") as HTMLAreaElement;
|
||||
if(switchurl){
|
||||
switchurl.href += window.location.search;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue