From 3d1f26800383640718647074f6977bbf83cfb18d Mon Sep 17 00:00:00 2001 From: Azgaar Date: Fri, 20 Sep 2024 13:04:47 +0200 Subject: [PATCH] feat: use StaleWhileRevalidate for scripts poloicy; v1.104.2 --- index.html | 4 ++-- main.js | 5 +---- modules/ui/options.js | 6 ------ sw.js | 9 +++++--- versioning.js | 49 +++++++++++++++++++++---------------------- 5 files changed, 33 insertions(+), 40 deletions(-) diff --git a/index.html b/index.html index 6fcaf3c5..1fd06ef8 100644 --- a/index.html +++ b/index.html @@ -1990,8 +1990,8 @@ diff --git a/main.js b/main.js index 41710975..ca6f1ca1 100644 --- a/main.js +++ b/main.js @@ -666,10 +666,7 @@ async function generate(options) { title: "Generation error", width: "32em", buttons: { - "Clear data": function () { - localStorage.clear(); - localStorage.setItem("version", VERSION); - }, + "Cleanup data": cleanupData, Regenerate: function () { regenerateMap("generation error"); $(this).dialog("close"); diff --git a/modules/ui/options.js b/modules/ui/options.js index b7b643a1..f10cf6fd 100644 --- a/modules/ui/options.js +++ b/modules/ui/options.js @@ -703,12 +703,6 @@ async function openTemplateSelectionDialog() { HeightmapSelectionDialog.open(); } -// remove all saved data from LocalStorage and reload the page -function restoreDefaultOptions() { - localStorage.clear(); - location.reload(); -} - // Sticked menu Options listeners byId("sticked").addEventListener("click", function (event) { const id = event.target.id; diff --git a/sw.js b/sw.js index 0b59c217..ac7690ed 100644 --- a/sw.js +++ b/sw.js @@ -1,7 +1,7 @@ importScripts("https://storage.googleapis.com/workbox-cdn/releases/6.2.0/workbox-sw.js"); const {Route, registerRoute} = workbox.routing; -const {CacheFirst, NetworkFirst} = workbox.strategies; +const {CacheFirst, NetworkFirst, StaleWhileRevalidate} = workbox.strategies; const {CacheableResponsePlugin} = workbox.cacheableResponse; const {ExpirationPlugin} = workbox.expiration; @@ -18,8 +18,11 @@ registerRoute( registerRoute( ({request, url}) => - request.destination === "script" && !url.pathname.endsWith("min.js") && !url.pathname.includes("versioning.js"), - new CacheFirst({ + request.destination === "script" && + !url.pathname.endsWith("min.js") && + !url.pathname.includes("versioning.js") && + !url.contains("google"), + new StaleWhileRevalidate({ cacheName: "fmg-scripts", plugins: [ new CacheableResponsePlugin({statuses: [0, 200]}), diff --git a/versioning.js b/versioning.js index 99c4eacb..52036ad1 100644 --- a/versioning.js +++ b/versioning.js @@ -12,7 +12,7 @@ * * Example: 1.102.2 -> Major version 1, Minor version 102, Patch version 2 */ -const VERSION = "1.104.1"; +const VERSION = "1.104.2"; if (parseMapVersion(VERSION) !== VERSION) alert("versioning.js: Invalid format or parsing function"); { @@ -21,7 +21,9 @@ if (parseMapVersion(VERSION) !== VERSION) alert("versioning.js: Invalid format o if (loadingScreenVersion) loadingScreenVersion.innerText = `v${VERSION}`; const storedVersion = localStorage.getItem("version"); - if (compareVersions(storedVersion, VERSION, {patch: false}).isOlder) setTimeout(showUpdateWindow, 6000); + if (compareVersions(storedVersion, VERSION, {major: true, minor: true, patch: false}).isOlder) { + setTimeout(showUpdateWindow, 6000); + } function showUpdateWindow() { const changelog = "https://github.com/Azgaar/Fantasy-Map-Generator/wiki/Changelog"; @@ -34,7 +36,7 @@ if (parseMapVersion(VERSION) !== VERSION) alert("versioning.js: Invalid format o

Join our Discord server and Reddit community to ask questions, share maps, discuss the Generator and Worlbuilding, report bugs and propose new features.

Thanks for all supporters on Patreon!`; - const buttons = { - Ok: function () { - $(this).dialog("close"); - localStorage.setItem("version", VERSION); - } - }; - - if (storedVersion) { - buttons.Cleanup = () => { - clearCache(); - localStorage.clear(); - localStorage.setItem("version", VERSION); - location.reload(); - }; - } - $("#alert").dialog({ resizable: false, title: "Fantasy Map Generator update", width: "28em", position: {my: "center center-4em", at: "center", of: "svg"}, - buttons + buttons: { + "Cleanup data": () => cleanupData(), + "Don't show again": function () { + $(this).dialog("close"); + localStorage.setItem("version", VERSION); + } + } }); } +} - async function clearCache() { - const cacheNames = await caches.keys(); - return Promise.all(cacheNames.map(cacheName => caches.delete(cacheName))); - } +async function cleanupData() { + await clearCache(); + localStorage.clear(); + localStorage.setItem("version", VERSION); + localStorage.setItem("disable_click_arrow_tooltip", "true"); + location.reload(); +} + +async function clearCache() { + const cacheNames = await caches.keys(); + return Promise.all(cacheNames.map(cacheName => caches.delete(cacheName))); } function parseMapVersion(version) {