chore: 更改更新机制

This commit is contained in:
haorwen
2026-04-13 23:28:46 +08:00
parent 36161c51c0
commit 8e8212c580
+13
View File
@@ -62,6 +62,15 @@ function registerValidSW(swUrl: string, config: Config) {
navigator.serviceWorker
.register(swUrl)
.then((registration) => {
// If a waiting SW already exists (e.g. user previously dismissed the toast),
// re-trigger onUpdate so the toast appears again on refresh.
if (registration.waiting && navigator.serviceWorker.controller) {
if (config && config.onUpdate) {
config.onUpdate(registration);
}
return;
}
registration.onupdatefound = () => {
const installingWorker = registration.installing;
if (installingWorker == null) {
@@ -96,6 +105,10 @@ function registerValidSW(swUrl: string, config: Config) {
}
};
};
// Force an update check on every page load/refresh,
// so new versions are discovered immediately.
registration.update().catch(() => {});
})
.catch((error) => {
console.error("Error during service worker registration:", error);