flutter_service_worker.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. 'use strict';
  2. const MANIFEST = 'flutter-app-manifest';
  3. const TEMP = 'flutter-temp-cache';
  4. const CACHE_NAME = 'flutter-app-cache';
  5. const RESOURCES = {".git/config": "60b6b72b4099ebaecfb6179e8b2e5f9e",
  6. ".git/description": "a0a7c3fff21f2aea3cfa1d0316dd816c",
  7. ".git/FETCH_HEAD": "ea1106d8f9b205b4d8daa1f1193ab174",
  8. ".git/HEAD": "4cf2d64e44205fe628ddd534e1151b58",
  9. ".git/hooks/applypatch-msg.sample": "ce562e08d8098926a3862fc6e7905199",
  10. ".git/hooks/commit-msg.sample": "579a3c1e12a1e74a98169175fb913012",
  11. ".git/hooks/fsmonitor-watchman.sample": "a0b2633a2c8e97501610bd3f73da66fc",
  12. ".git/hooks/post-update.sample": "2b7ea5cee3c49ff53d41e00785eb974c",
  13. ".git/hooks/pre-applypatch.sample": "054f9ffb8bfe04a599751cc757226dda",
  14. ".git/hooks/pre-commit.sample": "305eadbbcd6f6d2567e033ad12aabbc4",
  15. ".git/hooks/pre-merge-commit.sample": "39cb268e2a85d436b9eb6f47614c3cbc",
  16. ".git/hooks/pre-push.sample": "2c642152299a94e05ea26eae11993b13",
  17. ".git/hooks/pre-rebase.sample": "56e45f2bcbc8226d2b4200f7c46371bf",
  18. ".git/hooks/pre-receive.sample": "2ad18ec82c20af7b5926ed9cea6aeedd",
  19. ".git/hooks/prepare-commit-msg.sample": "2b5c047bdb474555e1787db32b2d2fc5",
  20. ".git/hooks/push-to-checkout.sample": "c7ab00c7784efeadad3ae9b228d4b4db",
  21. ".git/hooks/sendemail-validate.sample": "4d67df3a8d5c98cb8565c07e42be0b04",
  22. ".git/hooks/update.sample": "647ae13c682f7827c22f5fc08a03674e",
  23. ".git/index": "44e2864bbbf316f64f30746f1404d4de",
  24. ".git/info/exclude": "036208b4a1ab4a235d75c181e685e5a3",
  25. ".git/logs/HEAD": "425b06a76e29e6a961e4a9729395380b",
  26. ".git/logs/refs/heads/master": "425b06a76e29e6a961e4a9729395380b",
  27. ".git/logs/refs/remotes/origin/HEAD": "425b06a76e29e6a961e4a9729395380b",
  28. ".git/objects/pack/pack-f97eba008558126c6b05cbe0d977c240616e5769.idx": "6ecc91d7dab0b00ce1de146aaacb67f6",
  29. ".git/objects/pack/pack-f97eba008558126c6b05cbe0d977c240616e5769.pack": "67853c7be6657d14d27102bc89b29bd4",
  30. ".git/objects/pack/pack-f97eba008558126c6b05cbe0d977c240616e5769.rev": "c0a3d704210a6e8b46dcbc8566a06797",
  31. ".git/packed-refs": "fcbfb42a2cccad535268911906880c33",
  32. ".git/refs/heads/master": "10f141bcf5f013bff032cbafff3023f1",
  33. ".git/refs/remotes/origin/HEAD": "73a00957034783b7b5c8294c54cd3e12",
  34. ".vscode/launch.json": "8536c0b1b0a5a6da1637feed7ca91d43",
  35. "assets/AssetManifest.bin": "0b0a3415aad49b6e9bf965ff578614f9",
  36. "assets/AssetManifest.bin.json": "a1fee2517bf598633e2f67fcf3e26c94",
  37. "assets/AssetManifest.json": "99914b932bd37a50b983c5e7c90ae93b",
  38. "assets/FontManifest.json": "7b2a36307916a9721811788013e65289",
  39. "assets/fonts/MaterialIcons-Regular.otf": "0db35ae7a415370b89e807027510caf0",
  40. "assets/NOTICES": "308b58ca5304581480ce433b822f503c",
  41. "assets/shaders/ink_sparkle.frag": "ecc85a2e95f5e9f53123dcaf8cb9b6ce",
  42. "canvaskit/canvaskit.js": "c86fbd9e7b17accae76e5ad116583dc4",
  43. "canvaskit/canvaskit.js.symbols": "38cba9233b92472a36ff011dc21c2c9f",
  44. "canvaskit/canvaskit.wasm": "3d2a2d663e8c5111ac61a46367f751ac",
  45. "canvaskit/chromium/canvaskit.js": "43787ac5098c648979c27c13c6f804c3",
  46. "canvaskit/chromium/canvaskit.js.symbols": "4525682ef039faeb11f24f37436dca06",
  47. "canvaskit/chromium/canvaskit.wasm": "f5934e694f12929ed56a671617acd254",
  48. "canvaskit/skwasm.js": "445e9e400085faead4493be2224d95aa",
  49. "canvaskit/skwasm.js.symbols": "741d50ffba71f89345996b0aa8426af8",
  50. "canvaskit/skwasm.wasm": "e42815763c5d05bba43f9d0337fa7d84",
  51. "canvaskit/skwasm.worker.js": "bfb704a6c714a75da9ef320991e88b03",
  52. "favicon.png": "a8dac4984aa5229f2f2c176b2b626e1f",
  53. "flutter.js": "c71a09214cb6f5f8996a531350400a9a",
  54. "icons/Icon-192.png": "ab1f3346eb3e23e19304ac088cc236c1",
  55. "icons/Icon-512.png": "29fa67fed2325c5febd96dd9180e60dc",
  56. "icons/Icon-maskable-192.png": "c8230bd12eac2e925faa8531f5633292",
  57. "icons/Icon-maskable-512.png": "4eb4557b51424f785b4dcf7096a9fdde",
  58. "index.html": "b77b885b3ce5c70fc7fe4f50900c4324",
  59. "/": "b77b885b3ce5c70fc7fe4f50900c4324",
  60. "main.dart.js": "8ebbc98c411d7c92261ca8fcd476b2bd",
  61. "manifest.json": "27a391c5ac472fe33d066bdd6e1c50be",
  62. "version.json": "da11dc51486ca396fa77df44efc636c4"};
  63. // The application shell files that are downloaded before a service worker can
  64. // start.
  65. const CORE = ["main.dart.js",
  66. "index.html",
  67. "assets/AssetManifest.bin.json",
  68. "assets/FontManifest.json"];
  69. // During install, the TEMP cache is populated with the application shell files.
  70. self.addEventListener("install", (event) => {
  71. self.skipWaiting();
  72. return event.waitUntil(
  73. caches.open(TEMP).then((cache) => {
  74. return cache.addAll(
  75. CORE.map((value) => new Request(value, {'cache': 'reload'})));
  76. })
  77. );
  78. });
  79. // During activate, the cache is populated with the temp files downloaded in
  80. // install. If this service worker is upgrading from one with a saved
  81. // MANIFEST, then use this to retain unchanged resource files.
  82. self.addEventListener("activate", function(event) {
  83. return event.waitUntil(async function() {
  84. try {
  85. var contentCache = await caches.open(CACHE_NAME);
  86. var tempCache = await caches.open(TEMP);
  87. var manifestCache = await caches.open(MANIFEST);
  88. var manifest = await manifestCache.match('manifest');
  89. // When there is no prior manifest, clear the entire cache.
  90. if (!manifest) {
  91. await caches.delete(CACHE_NAME);
  92. contentCache = await caches.open(CACHE_NAME);
  93. for (var request of await tempCache.keys()) {
  94. var response = await tempCache.match(request);
  95. await contentCache.put(request, response);
  96. }
  97. await caches.delete(TEMP);
  98. // Save the manifest to make future upgrades efficient.
  99. await manifestCache.put('manifest', new Response(JSON.stringify(RESOURCES)));
  100. // Claim client to enable caching on first launch
  101. self.clients.claim();
  102. return;
  103. }
  104. var oldManifest = await manifest.json();
  105. var origin = self.location.origin;
  106. for (var request of await contentCache.keys()) {
  107. var key = request.url.substring(origin.length + 1);
  108. if (key == "") {
  109. key = "/";
  110. }
  111. // If a resource from the old manifest is not in the new cache, or if
  112. // the MD5 sum has changed, delete it. Otherwise the resource is left
  113. // in the cache and can be reused by the new service worker.
  114. if (!RESOURCES[key] || RESOURCES[key] != oldManifest[key]) {
  115. await contentCache.delete(request);
  116. }
  117. }
  118. // Populate the cache with the app shell TEMP files, potentially overwriting
  119. // cache files preserved above.
  120. for (var request of await tempCache.keys()) {
  121. var response = await tempCache.match(request);
  122. await contentCache.put(request, response);
  123. }
  124. await caches.delete(TEMP);
  125. // Save the manifest to make future upgrades efficient.
  126. await manifestCache.put('manifest', new Response(JSON.stringify(RESOURCES)));
  127. // Claim client to enable caching on first launch
  128. self.clients.claim();
  129. return;
  130. } catch (err) {
  131. // On an unhandled exception the state of the cache cannot be guaranteed.
  132. console.error('Failed to upgrade service worker: ' + err);
  133. await caches.delete(CACHE_NAME);
  134. await caches.delete(TEMP);
  135. await caches.delete(MANIFEST);
  136. }
  137. }());
  138. });
  139. // The fetch handler redirects requests for RESOURCE files to the service
  140. // worker cache.
  141. self.addEventListener("fetch", (event) => {
  142. if (event.request.method !== 'GET') {
  143. return;
  144. }
  145. var origin = self.location.origin;
  146. var key = event.request.url.substring(origin.length + 1);
  147. // Redirect URLs to the index.html
  148. if (key.indexOf('?v=') != -1) {
  149. key = key.split('?v=')[0];
  150. }
  151. if (event.request.url == origin || event.request.url.startsWith(origin + '/#') || key == '') {
  152. key = '/';
  153. }
  154. // If the URL is not the RESOURCE list then return to signal that the
  155. // browser should take over.
  156. if (!RESOURCES[key]) {
  157. return;
  158. }
  159. // If the URL is the index.html, perform an online-first request.
  160. if (key == '/') {
  161. return onlineFirst(event);
  162. }
  163. event.respondWith(caches.open(CACHE_NAME)
  164. .then((cache) => {
  165. return cache.match(event.request).then((response) => {
  166. // Either respond with the cached resource, or perform a fetch and
  167. // lazily populate the cache only if the resource was successfully fetched.
  168. return response || fetch(event.request).then((response) => {
  169. if (response && Boolean(response.ok)) {
  170. cache.put(event.request, response.clone());
  171. }
  172. return response;
  173. });
  174. })
  175. })
  176. );
  177. });
  178. self.addEventListener('message', (event) => {
  179. // SkipWaiting can be used to immediately activate a waiting service worker.
  180. // This will also require a page refresh triggered by the main worker.
  181. if (event.data === 'skipWaiting') {
  182. self.skipWaiting();
  183. return;
  184. }
  185. if (event.data === 'downloadOffline') {
  186. downloadOffline();
  187. return;
  188. }
  189. });
  190. // Download offline will check the RESOURCES for all files not in the cache
  191. // and populate them.
  192. async function downloadOffline() {
  193. var resources = [];
  194. var contentCache = await caches.open(CACHE_NAME);
  195. var currentContent = {};
  196. for (var request of await contentCache.keys()) {
  197. var key = request.url.substring(origin.length + 1);
  198. if (key == "") {
  199. key = "/";
  200. }
  201. currentContent[key] = true;
  202. }
  203. for (var resourceKey of Object.keys(RESOURCES)) {
  204. if (!currentContent[resourceKey]) {
  205. resources.push(resourceKey);
  206. }
  207. }
  208. return contentCache.addAll(resources);
  209. }
  210. // Attempt to download the resource online before falling back to
  211. // the offline cache.
  212. function onlineFirst(event) {
  213. return event.respondWith(
  214. fetch(event.request).then((response) => {
  215. return caches.open(CACHE_NAME).then((cache) => {
  216. cache.put(event.request, response.clone());
  217. return response;
  218. });
  219. }).catch((error) => {
  220. return caches.open(CACHE_NAME).then((cache) => {
  221. return cache.match(event.request).then((response) => {
  222. if (response != null) {
  223. return response;
  224. }
  225. throw error;
  226. });
  227. });
  228. })
  229. );
  230. }