Skip to content

Commit

Permalink
增加离线恢复自动刷新
Browse files Browse the repository at this point in the history
  • Loading branch information
CCKNBC committed Sep 10, 2024
1 parent df0a27f commit b3813c3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions scaffolds/workbox/workbox-sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ self.addEventListener("activate", async () => {
});
});

// 监听网络状态变化
self.addEventListener('online', () => {
console.log('网络已恢复,通知客户端刷新页面');
self.clients.matchAll().then((clients) => {
clients.forEach((client) => client.postMessage({ type: "refresh" }));
});
});

self.__WB_DISABLE_DEV_LOGS = true;

workbox.precaching.cleanupOutdatedCaches();
Expand Down Expand Up @@ -126,6 +134,7 @@ function handleEmptyReferrer(request) {
return fetch(request, { referrerPolicy: "no-referrer" });
}

// 函数用于处理主站请求
async function handleMainSiteRequest(request) {
let failedUrls = [];

Expand Down

0 comments on commit b3813c3

Please sign in to comment.