mirror of
https://github.com/MathMan05/Fermi.git
synced 2026-10-23 19:22:27 +00:00
Service Worker: option to disable media cache by disabling worker outright
This commit is contained in:
1 parent
37deda8679
commit
0d0aabb8ae
3 files changed
+7
-3
No files matched your search
@@ -2493,13 +2493,13 @@ class Localuser {
|
||||
const sw = update.addSelect(
|
||||
I18n.localuser.swSettings(),
|
||||
() => {},
|
||||
(["SWOff", "SWOffline", "SWOn"] as const).map((e) => I18n.localuser[e]()),
|
||||
(["SWOff", "SWOffline", "SWOn", "SWUnregistered"] as const).map((e) => I18n.localuser[e]()),
|
||||
{
|
||||
defaultIndex: index,
|
||||
},
|
||||
);
|
||||
sw.onchange = (e) => {
|
||||
SW.setMode((["false", "offlineOnly", "true"] as const)[e]);
|
||||
SW.setMode((["false", "offlineOnly", "true", "unregistered"] as const)[e]);
|
||||
};
|
||||
update.addButtonInput("", I18n.localuser.CheckUpdate(), async () => {
|
||||
const update = await SW.checkUpdates();
|
||||
|
||||
@@ -986,6 +986,9 @@ export class SW {
|
||||
}
|
||||
static async start() {
|
||||
if (!("serviceWorker" in navigator)) return;
|
||||
|
||||
// If it's registered, it handles CDN caching regardless of settings.
|
||||
if(localStorage.getItem("SWMode") === "unregistered") return;
|
||||
return new Promise<void>((res) => {
|
||||
navigator.serviceWorker
|
||||
.register("/service.js", {
|
||||
@@ -1016,7 +1019,7 @@ export class SW {
|
||||
});
|
||||
});
|
||||
}
|
||||
static setMode(mode: "false" | "offlineOnly" | "true") {
|
||||
static setMode(mode: "false" | "offlineOnly" | "true" | "unregistered") {
|
||||
localStorage.setItem("SWMode", mode);
|
||||
if (this.worker) {
|
||||
this.worker.postMessage({data: mode, code: "setMode"});
|
||||
|
||||
@@ -516,6 +516,7 @@
|
||||
"VoiceWarning": "Are you sure you want to enable this? It's very experimental and is likely to cause issues. (this feature is for devs, please don't enable if you don't know what you're doing)",
|
||||
"updateSettings": "Update Settings",
|
||||
"swSettings": "Service Worker setting",
|
||||
"SWUnregistered": "Off (including media cache)",
|
||||
"SWOff": "Off",
|
||||
"SWOffline": "Offline only",
|
||||
"SWOn": "On",
|
||||
|
||||
Reference in new issue
Block a user