/* 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 . */ 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(); })(), ); });