Compare commits

...

12 Commits

Author SHA1 Message Date
filifa
4e5e59f6aa add icon type 2025-12-15 23:25:12 -05:00
filifa
b240278e91 remove trailing comma 2025-12-15 23:19:26 -05:00
filifa
ab346408c9 mark icon as maskable 2025-12-15 23:17:37 -05:00
filifa
0ab61c3007 set svg size to any 2025-12-15 23:14:05 -05:00
filifa
5f5555eb50 fix indentation and move registration 2025-12-15 22:37:25 -05:00
filifa
2e9c4f1dc7 add service worker for offline access 2025-12-15 22:28:20 -05:00
filifa
85053cbf97 add sizes 2025-12-15 21:57:41 -05:00
filifa
a6e3ea3737 try changing start_url 2025-12-15 21:52:27 -05:00
filifa
432566354b add scope and id 2025-12-15 21:48:44 -05:00
filifa
d84800138d add short name 2025-12-15 21:38:49 -05:00
filifa
5f5f9aaed9 fix path 2025-12-15 21:28:05 -05:00
filifa
729588d37c fix link 2025-12-15 21:18:12 -05:00
4 changed files with 82 additions and 3 deletions

View File

@@ -85,7 +85,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
<footer> <footer>
<a href="https://scm.dairydemon.net/filifa/mcalc">source</a> <a href="https://scm.dairydemon.net/filifa/mcalc">source</a>
<a href="/legal.html">legal</a> <a href="./legal.html">legal</a>
</footer> </footer>
<script type="module" src="main.js"></script> <script type="module" src="main.js"></script>

13
main.js
View File

@@ -149,3 +149,16 @@ document.querySelector("#clear").addEventListener("click", clear);
document.querySelector("#enter").addEventListener("click", evaluate); document.querySelector("#enter").addEventListener("click", evaluate);
document.querySelector("#backspace").addEventListener("click", backspace); document.querySelector("#backspace").addEventListener("click", backspace);
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("workers/service.js").then(
(registration) => {
console.log("Service worker registration successful:", registration);
},
(error) => {
console.error(`Service worker registration failed: ${error}`);
},
);
} else {
console.error("Service workers are not supported.");
}

View File

@@ -1,10 +1,16 @@
{ {
"short_name": "mcalc",
"name": "mcalc", "name": "mcalc",
"scope": "/mcalc",
"id": "/mcalc",
"icons": [ "icons": [
{ {
"src": "icon.svg" "src": "icon.svg",
"sizes": "any",
"purpose": "maskable",
"type": "image/svg+xml"
} }
], ],
"start_url": "/index.html", "start_url": "/mcalc/index.html",
"display": "standalone" "display": "standalone"
} }

60
workers/service.js Normal file
View File

@@ -0,0 +1,60 @@
/*
Copyright (C) 2025 filifa
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const VERSION = "v1";
const CACHE_NAME = `mcalc-${VERSION}`;
const APP_STATIC_RESOURCES = [
"../index.html",
"../legal.html",
"../styles.css",
"../main.js",
"evaluate.js",
"lexer.js",
"math.js",
"parser.js",
"../icon.svg"
];
// On install, cache the static resources
self.addEventListener("install", (event) => {
event.waitUntil(
(async () => {
const cache = await caches.open(CACHE_NAME);
cache.addAll(APP_STATIC_RESOURCES);
})(),
);
});
// delete old caches on activate
self.addEventListener("activate", (event) => {
event.waitUntil(
(async () => {
const names = await caches.keys();
await Promise.all(
names.map((name) => {
if (name !== CACHE_NAME) {
return caches.delete(name);
}
return undefined;
}),
);
await clients.claim();
})(),
);
});