flutter_service_worker.js 8.4 KB

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