Spaces:
Running
Running
; | |
const MANIFEST = 'flutter-app-manifest'; | |
const TEMP = 'flutter-temp-cache'; | |
const CACHE_NAME = 'flutter-app-cache'; | |
const RESOURCES = {"version.json": "80cac6649f47b150f61efe24c3a82cad", | |
"index.html": "4c2556e0541474ea6758b89010ecdd8d", | |
"/": "4c2556e0541474ea6758b89010ecdd8d", | |
"main.dart.js": "aaf6761add9213822fbc9e3cedc6d848", | |
"flutter.js": "7d69e653079438abfbb24b82a655b0a4", | |
"favicon.png": "b082b977a6ec6a6f56885698891a0093", | |
"icons/Icon-192.png": "617139673ad33ff0eee2fbd929fe7022", | |
"icons/favicon.png": "b082b977a6ec6a6f56885698891a0093", | |
"icons/Icon-512.png": "2489a77c43e8ab9caa4b1a4b75cda9b4", | |
"manifest.json": "14f13168b6732e3ce9fd2d436bb68a43", | |
"assets/AssetManifest.json": "531895ef9612c3c53ee29e8ca2e04abe", | |
"assets/NOTICES": "5eebd2ef30a7cbb814538f135db87d1d", | |
"assets/FontManifest.json": "3b4e68a4a536ece546b8c4d0ffd717d4", | |
"assets/AssetManifest.bin.json": "6a7911591928ff4e7340f8dc921838a1", | |
"assets/packages/ui/assets/images/dark_plainbagel_logo.png": "c7d8991c9d2c54872d1fb01ef5c2c636", | |
"assets/packages/ui/assets/images/plainbagel_logo.png": "7e053f59fcac285e2cb55fce8d03f572", | |
"assets/packages/ui/assets/fonts/NotoSans-Medium.ttf": "f2197cc8a55ba75995cd38d00e8be599", | |
"assets/packages/ui/assets/fonts/NotoSans-Bold.ttf": "8ac165243fb633296963b149f206a377", | |
"assets/shaders/ink_sparkle.frag": "4096b5150bac93c41cbc9b45276bd90f", | |
"assets/AssetManifest.bin": "60454a8b2daf04bdcd5fc66b7d1a6df8", | |
"assets/fonts/MaterialIcons-Regular.otf": "c664e3aee8809104d93daa0b501f48db", | |
"canvaskit/skwasm.js": "87063acf45c5e1ab9565dcf06b0c18b8", | |
"canvaskit/skwasm.wasm": "2fc47c0a0c3c7af8542b601634fe9674", | |
"canvaskit/chromium/canvaskit.js": "0ae8bbcc58155679458a0f7a00f66873", | |
"canvaskit/chromium/canvaskit.wasm": "143af6ff368f9cd21c863bfa4274c406", | |
"canvaskit/canvaskit.js": "eb8797020acdbdf96a12fb0405582c1b", | |
"canvaskit/canvaskit.wasm": "73584c1a3367e3eaf757647a8f5c5989", | |
"canvaskit/skwasm.worker.js": "bfb704a6c714a75da9ef320991e88b03"}; | |
// The application shell files that are downloaded before a service worker can | |
// start. | |
const CORE = ["main.dart.js", | |
"index.html", | |
"assets/AssetManifest.json", | |
"assets/FontManifest.json"]; | |
// During install, the TEMP cache is populated with the application shell files. | |
self.addEventListener("install", (event) => { | |
self.skipWaiting(); | |
return event.waitUntil( | |
caches.open(TEMP).then((cache) => { | |
return cache.addAll( | |
CORE.map((value) => new Request(value, {'cache': 'reload'}))); | |
}) | |
); | |
}); | |
// During activate, the cache is populated with the temp files downloaded in | |
// install. If this service worker is upgrading from one with a saved | |
// MANIFEST, then use this to retain unchanged resource files. | |
self.addEventListener("activate", function(event) { | |
return event.waitUntil(async function() { | |
try { | |
var contentCache = await caches.open(CACHE_NAME); | |
var tempCache = await caches.open(TEMP); | |
var manifestCache = await caches.open(MANIFEST); | |
var manifest = await manifestCache.match('manifest'); | |
// When there is no prior manifest, clear the entire cache. | |
if (!manifest) { | |
await caches.delete(CACHE_NAME); | |
contentCache = await caches.open(CACHE_NAME); | |
for (var request of await tempCache.keys()) { | |
var response = await tempCache.match(request); | |
await contentCache.put(request, response); | |
} | |
await caches.delete(TEMP); | |
// Save the manifest to make future upgrades efficient. | |
await manifestCache.put('manifest', new Response(JSON.stringify(RESOURCES))); | |
// Claim client to enable caching on first launch | |
self.clients.claim(); | |
return; | |
} | |
var oldManifest = await manifest.json(); | |
var origin = self.location.origin; | |
for (var request of await contentCache.keys()) { | |
var key = request.url.substring(origin.length + 1); | |
if (key == "") { | |
key = "/"; | |
} | |
// If a resource from the old manifest is not in the new cache, or if | |
// the MD5 sum has changed, delete it. Otherwise the resource is left | |
// in the cache and can be reused by the new service worker. | |
if (!RESOURCES[key] || RESOURCES[key] != oldManifest[key]) { | |
await contentCache.delete(request); | |
} | |
} | |
// Populate the cache with the app shell TEMP files, potentially overwriting | |
// cache files preserved above. | |
for (var request of await tempCache.keys()) { | |
var response = await tempCache.match(request); | |
await contentCache.put(request, response); | |
} | |
await caches.delete(TEMP); | |
// Save the manifest to make future upgrades efficient. | |
await manifestCache.put('manifest', new Response(JSON.stringify(RESOURCES))); | |
// Claim client to enable caching on first launch | |
self.clients.claim(); | |
return; | |
} catch (err) { | |
// On an unhandled exception the state of the cache cannot be guaranteed. | |
console.error('Failed to upgrade service worker: ' + err); | |
await caches.delete(CACHE_NAME); | |
await caches.delete(TEMP); | |
await caches.delete(MANIFEST); | |
} | |
}()); | |
}); | |
// The fetch handler redirects requests for RESOURCE files to the service | |
// worker cache. | |
self.addEventListener("fetch", (event) => { | |
if (event.request.method !== 'GET') { | |
return; | |
} | |
var origin = self.location.origin; | |
var key = event.request.url.substring(origin.length + 1); | |
// Redirect URLs to the index.html | |
if (key.indexOf('?v=') != -1) { | |
key = key.split('?v=')[0]; | |
} | |
if (event.request.url == origin || event.request.url.startsWith(origin + '/#') || key == '') { | |
key = '/'; | |
} | |
// If the URL is not the RESOURCE list then return to signal that the | |
// browser should take over. | |
if (!RESOURCES[key]) { | |
return; | |
} | |
// If the URL is the index.html, perform an online-first request. | |
if (key == '/') { | |
return onlineFirst(event); | |
} | |
event.respondWith(caches.open(CACHE_NAME) | |
.then((cache) => { | |
return cache.match(event.request).then((response) => { | |
// Either respond with the cached resource, or perform a fetch and | |
// lazily populate the cache only if the resource was successfully fetched. | |
return response || fetch(event.request).then((response) => { | |
if (response && Boolean(response.ok)) { | |
cache.put(event.request, response.clone()); | |
} | |
return response; | |
}); | |
}) | |
}) | |
); | |
}); | |
self.addEventListener('message', (event) => { | |
// SkipWaiting can be used to immediately activate a waiting service worker. | |
// This will also require a page refresh triggered by the main worker. | |
if (event.data === 'skipWaiting') { | |
self.skipWaiting(); | |
return; | |
} | |
if (event.data === 'downloadOffline') { | |
downloadOffline(); | |
return; | |
} | |
}); | |
// Download offline will check the RESOURCES for all files not in the cache | |
// and populate them. | |
async function downloadOffline() { | |
var resources = []; | |
var contentCache = await caches.open(CACHE_NAME); | |
var currentContent = {}; | |
for (var request of await contentCache.keys()) { | |
var key = request.url.substring(origin.length + 1); | |
if (key == "") { | |
key = "/"; | |
} | |
currentContent[key] = true; | |
} | |
for (var resourceKey of Object.keys(RESOURCES)) { | |
if (!currentContent[resourceKey]) { | |
resources.push(resourceKey); | |
} | |
} | |
return contentCache.addAll(resources); | |
} | |
// Attempt to download the resource online before falling back to | |
// the offline cache. | |
function onlineFirst(event) { | |
return event.respondWith( | |
fetch(event.request).then((response) => { | |
return caches.open(CACHE_NAME).then((cache) => { | |
cache.put(event.request, response.clone()); | |
return response; | |
}); | |
}).catch((error) => { | |
return caches.open(CACHE_NAME).then((cache) => { | |
return cache.match(event.request).then((response) => { | |
if (response != null) { | |
return response; | |
} | |
throw error; | |
}); | |
}); | |
}) | |
); | |
} | |