|
1 | | -'use strict'; |
2 | | -const MANIFEST = 'flutter-app-manifest'; |
3 | | -const TEMP = 'flutter-temp-cache'; |
4 | | -const CACHE_NAME = 'flutter-app-cache'; |
5 | | - |
6 | | -const RESOURCES = {"assets/AssetManifest.bin": "5ebd9da438bc0e237ea2f6864a262879", |
7 | | -"assets/AssetManifest.bin.json": "92fb8d3519dc0a31348ba2537af31ad0", |
8 | | -"assets/AssetManifest.json": "a6213f46f134e18ca257e181b6e1dd6e", |
9 | | -"assets/assets/doc.md": "135b62bb49e238a144ee449c3081bb56", |
10 | | -"assets/FontManifest.json": "dc3d03800ccca4601324923c0b1d6d57", |
11 | | -"assets/fonts/MaterialIcons-Regular.otf": "797d9e7902b489369304c88132bdd8f0", |
12 | | -"assets/NOTICES": "e78b579326051df88b0cb9b28a272102", |
13 | | -"assets/packages/cupertino_icons/assets/CupertinoIcons.ttf": "89ed8f4e49bcdfc0b5bfc9b24591e347", |
14 | | -"assets/shaders/ink_sparkle.frag": "ecc85a2e95f5e9f53123dcaf8cb9b6ce", |
15 | | -"canvaskit/canvaskit.js": "738255d00768497e86aa4ca510cce1e1", |
16 | | -"canvaskit/canvaskit.js.symbols": "74a84c23f5ada42fe063514c587968c6", |
17 | | -"canvaskit/canvaskit.wasm": "9251bb81ae8464c4df3b072f84aa969b", |
18 | | -"canvaskit/chromium/canvaskit.js": "901bb9e28fac643b7da75ecfd3339f3f", |
19 | | -"canvaskit/chromium/canvaskit.js.symbols": "ee7e331f7f5bbf5ec937737542112372", |
20 | | -"canvaskit/chromium/canvaskit.wasm": "399e2344480862e2dfa26f12fa5891d7", |
21 | | -"canvaskit/skwasm.js": "5d4f9263ec93efeb022bb14a3881d240", |
22 | | -"canvaskit/skwasm.js.symbols": "c3c05bd50bdf59da8626bbe446ce65a3", |
23 | | -"canvaskit/skwasm.wasm": "4051bfc27ba29bf420d17aa0c3a98bce", |
24 | | -"canvaskit/skwasm.worker.js": "bfb704a6c714a75da9ef320991e88b03", |
25 | | -"favicon.png": "5dcef449791fa27946b3d35ad8803796", |
26 | | -"flutter.js": "383e55f7f3cce5be08fcf1f3881f585c", |
27 | | -"flutter_bootstrap.js": "ee44b187a46bad7ce7e5f0bbf7fd4b32", |
28 | | -"icons/Icon-192.png": "ac9a721a12bbc803b44f645561ecb1e1", |
29 | | -"icons/Icon-512.png": "96e752610906ba2a93c65f8abe1645f1", |
30 | | -"icons/Icon-maskable-192.png": "c457ef57daa1d16f64b27b786ec2ea3c", |
31 | | -"icons/Icon-maskable-512.png": "301a7604d45b3e739efc881eb04896ea", |
32 | | -"index.html": "38001665daa4297cddb589e7ca472753", |
33 | | -"/": "38001665daa4297cddb589e7ca472753", |
34 | | -"main.dart.js": "c19368528a49b2413fde0569884fa577", |
35 | | -"manifest.json": "4c01b8e80fe2dd8fd129827e69e14d35", |
36 | | -"version.json": "e36fe75f7dd3435164eba1bdd629b2c0"}; |
37 | | -// The application shell files that are downloaded before a service worker can |
38 | | -// start. |
39 | | -const CORE = ["main.dart.js", |
40 | | -"index.html", |
41 | | -"flutter_bootstrap.js", |
42 | | -"assets/AssetManifest.bin.json", |
43 | | -"assets/FontManifest.json"]; |
44 | | - |
45 | | -// During install, the TEMP cache is populated with the application shell files. |
46 | | -self.addEventListener("install", (event) => { |
47 | | - self.skipWaiting(); |
48 | | - return event.waitUntil( |
49 | | - caches.open(TEMP).then((cache) => { |
50 | | - return cache.addAll( |
51 | | - CORE.map((value) => new Request(value, {'cache': 'reload'}))); |
52 | | - }) |
53 | | - ); |
54 | | -}); |
55 | | -// During activate, the cache is populated with the temp files downloaded in |
56 | | -// install. If this service worker is upgrading from one with a saved |
57 | | -// MANIFEST, then use this to retain unchanged resource files. |
58 | | -self.addEventListener("activate", function(event) { |
59 | | - return event.waitUntil(async function() { |
60 | | - try { |
61 | | - var contentCache = await caches.open(CACHE_NAME); |
62 | | - var tempCache = await caches.open(TEMP); |
63 | | - var manifestCache = await caches.open(MANIFEST); |
64 | | - var manifest = await manifestCache.match('manifest'); |
65 | | - // When there is no prior manifest, clear the entire cache. |
66 | | - if (!manifest) { |
67 | | - await caches.delete(CACHE_NAME); |
68 | | - contentCache = await caches.open(CACHE_NAME); |
69 | | - for (var request of await tempCache.keys()) { |
70 | | - var response = await tempCache.match(request); |
71 | | - await contentCache.put(request, response); |
72 | | - } |
73 | | - await caches.delete(TEMP); |
74 | | - // Save the manifest to make future upgrades efficient. |
75 | | - await manifestCache.put('manifest', new Response(JSON.stringify(RESOURCES))); |
76 | | - // Claim client to enable caching on first launch |
77 | | - self.clients.claim(); |
78 | | - return; |
79 | | - } |
80 | | - var oldManifest = await manifest.json(); |
81 | | - var origin = self.location.origin; |
82 | | - for (var request of await contentCache.keys()) { |
83 | | - var key = request.url.substring(origin.length + 1); |
84 | | - if (key == "") { |
85 | | - key = "/"; |
86 | | - } |
87 | | - // If a resource from the old manifest is not in the new cache, or if |
88 | | - // the MD5 sum has changed, delete it. Otherwise the resource is left |
89 | | - // in the cache and can be reused by the new service worker. |
90 | | - if (!RESOURCES[key] || RESOURCES[key] != oldManifest[key]) { |
91 | | - await contentCache.delete(request); |
92 | | - } |
93 | | - } |
94 | | - // Populate the cache with the app shell TEMP files, potentially overwriting |
95 | | - // cache files preserved above. |
96 | | - for (var request of await tempCache.keys()) { |
97 | | - var response = await tempCache.match(request); |
98 | | - await contentCache.put(request, response); |
99 | | - } |
100 | | - await caches.delete(TEMP); |
101 | | - // Save the manifest to make future upgrades efficient. |
102 | | - await manifestCache.put('manifest', new Response(JSON.stringify(RESOURCES))); |
103 | | - // Claim client to enable caching on first launch |
104 | | - self.clients.claim(); |
105 | | - return; |
106 | | - } catch (err) { |
107 | | - // On an unhandled exception the state of the cache cannot be guaranteed. |
108 | | - console.error('Failed to upgrade service worker: ' + err); |
109 | | - await caches.delete(CACHE_NAME); |
110 | | - await caches.delete(TEMP); |
111 | | - await caches.delete(MANIFEST); |
112 | | - } |
113 | | - }()); |
114 | | -}); |
115 | | -// The fetch handler redirects requests for RESOURCE files to the service |
116 | | -// worker cache. |
117 | | -self.addEventListener("fetch", (event) => { |
118 | | - if (event.request.method !== 'GET') { |
119 | | - return; |
120 | | - } |
121 | | - var origin = self.location.origin; |
122 | | - var key = event.request.url.substring(origin.length + 1); |
123 | | - // Redirect URLs to the index.html |
124 | | - if (key.indexOf('?v=') != -1) { |
125 | | - key = key.split('?v=')[0]; |
126 | | - } |
127 | | - if (event.request.url == origin || event.request.url.startsWith(origin + '/#') || key == '') { |
128 | | - key = '/'; |
129 | | - } |
130 | | - // If the URL is not the RESOURCE list then return to signal that the |
131 | | - // browser should take over. |
132 | | - if (!RESOURCES[key]) { |
133 | | - return; |
134 | | - } |
135 | | - // If the URL is the index.html, perform an online-first request. |
136 | | - if (key == '/') { |
137 | | - return onlineFirst(event); |
138 | | - } |
139 | | - event.respondWith(caches.open(CACHE_NAME) |
140 | | - .then((cache) => { |
141 | | - return cache.match(event.request).then((response) => { |
142 | | - // Either respond with the cached resource, or perform a fetch and |
143 | | - // lazily populate the cache only if the resource was successfully fetched. |
144 | | - return response || fetch(event.request).then((response) => { |
145 | | - if (response && Boolean(response.ok)) { |
146 | | - cache.put(event.request, response.clone()); |
147 | | - } |
148 | | - return response; |
149 | | - }); |
150 | | - }) |
151 | | - }) |
152 | | - ); |
153 | | -}); |
154 | | -self.addEventListener('message', (event) => { |
155 | | - // SkipWaiting can be used to immediately activate a waiting service worker. |
156 | | - // This will also require a page refresh triggered by the main worker. |
157 | | - if (event.data === 'skipWaiting') { |
158 | | - self.skipWaiting(); |
159 | | - return; |
160 | | - } |
161 | | - if (event.data === 'downloadOffline') { |
162 | | - downloadOffline(); |
163 | | - return; |
164 | | - } |
165 | | -}); |
166 | | -// Download offline will check the RESOURCES for all files not in the cache |
167 | | -// and populate them. |
168 | | -async function downloadOffline() { |
169 | | - var resources = []; |
170 | | - var contentCache = await caches.open(CACHE_NAME); |
171 | | - var currentContent = {}; |
172 | | - for (var request of await contentCache.keys()) { |
173 | | - var key = request.url.substring(origin.length + 1); |
174 | | - if (key == "") { |
175 | | - key = "/"; |
176 | | - } |
177 | | - currentContent[key] = true; |
178 | | - } |
179 | | - for (var resourceKey of Object.keys(RESOURCES)) { |
180 | | - if (!currentContent[resourceKey]) { |
181 | | - resources.push(resourceKey); |
182 | | - } |
183 | | - } |
184 | | - return contentCache.addAll(resources); |
185 | | -} |
186 | | -// Attempt to download the resource online before falling back to |
187 | | -// the offline cache. |
188 | | -function onlineFirst(event) { |
189 | | - return event.respondWith( |
190 | | - fetch(event.request).then((response) => { |
191 | | - return caches.open(CACHE_NAME).then((cache) => { |
192 | | - cache.put(event.request, response.clone()); |
193 | | - return response; |
194 | | - }); |
195 | | - }).catch((error) => { |
196 | | - return caches.open(CACHE_NAME).then((cache) => { |
197 | | - return cache.match(event.request).then((response) => { |
198 | | - if (response != null) { |
199 | | - return response; |
200 | | - } |
201 | | - throw error; |
202 | | - }); |
203 | | - }); |
204 | | - }) |
205 | | - ); |
206 | | -} |
0 commit comments