mirror of
				https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
				synced 2025-11-04 16:23:41 +08:00 
			
		
		
		
	更新serviceworker逻辑
This commit is contained in:
		@@ -7,6 +7,7 @@ self.addEventListener("activate", function (event) {
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
self.addEventListener("install", function (event) {
 | 
			
		||||
  self.skipWaiting();  // 立即启用新的版本
 | 
			
		||||
  event.waitUntil(
 | 
			
		||||
    caches.open(CHATGPT_NEXT_WEB_CACHE).then(function (cache) {
 | 
			
		||||
      return cache.addAll([]);
 | 
			
		||||
 
 | 
			
		||||
@@ -2,8 +2,15 @@ if ('serviceWorker' in navigator) {
 | 
			
		||||
  window.addEventListener('load', function () {
 | 
			
		||||
    navigator.serviceWorker.register('/serviceWorker.js').then(function (registration) {
 | 
			
		||||
      console.log('ServiceWorker registration successful with scope: ', registration.scope);
 | 
			
		||||
      registration.update().then(res => {
 | 
			
		||||
        console.log('ServiceWorker registration update: ', res);
 | 
			
		||||
      });
 | 
			
		||||
    }, function (err) {
 | 
			
		||||
      console.error('ServiceWorker registration failed: ', err);
 | 
			
		||||
    });
 | 
			
		||||
    navigator.serviceWorker.addEventListener('controllerchange', function() {
 | 
			
		||||
      console.log('ServiceWorker controllerchange ');
 | 
			
		||||
      window.location.reload(true);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user