flutter_service_worker.js 9.6 KB

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