flutter_service_worker.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 = {"main.dart.js": "76f3808e9dde3737b284c7f665e2402f",
  6. "favicon.png": "5dcef449791fa27946b3d35ad8803796",
  7. "version.json": "92f697c02cebd09de4c9f42514753601",
  8. "icons/Icon-maskable-512.png": "301a7604d45b3e739efc881eb04896ea",
  9. "icons/Icon-maskable-192.png": "c457ef57daa1d16f64b27b786ec2ea3c",
  10. "icons/Icon-512.png:Zone.Identifier": "8bd539172c70ab7ee8d93dfc100f48c6",
  11. "icons/Icon-512.png": "96e752610906ba2a93c65f8abe1645f1",
  12. "icons/Icon-192.png": "ac9a721a12bbc803b44f645561ecb1e1",
  13. "icons/Icon-192.png:Zone.Identifier": "8bd539172c70ab7ee8d93dfc100f48c6",
  14. "favicon.png%3AZone.Identifier": "8bd539172c70ab7ee8d93dfc100f48c6",
  15. "assets/AssetManifest.json": "7107f01592ede37d667c303623ccd708",
  16. "assets/AssetManifest.bin": "d4dec74aed52fc1f0ba0e1c4db49c432",
  17. "assets/FontManifest.json": "71a4a82de411f155107da3f8dac64ebd",
  18. "assets/NOTICES": "2acc594a42393e46699e1b3b0419cbe6",
  19. "assets/assets/email.png": "d06f5f879781f1a2cfcaa4907052ecb2",
  20. "assets/assets/communications.png": "b1b531ec21bc2e7dbfb0dd9908bbe119",
  21. "assets/assets/contact-book.png": "bb7600a8929229e95653fecfb7601837",
  22. "assets/assets/back.png": "6186dd3ad1836cbb49828b6cf2aa2919",
  23. "assets/AssetManifest.bin.json": "dab53058cc1526f8ede0d2d03185f493",
  24. "assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Main-BoldItalic.ttf": "e3c361ea8d1c215805439ce0941a1c8d",
  25. "assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Caligraphic-Bold.ttf": "a9c8e437146ef63fcd6fae7cf65ca859",
  26. "assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Fraktur-Regular.ttf": "dede6f2c7dad4402fa205644391b3a94",
  27. "assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Typewriter-Regular.ttf": "87f56927f1ba726ce0591955c8b3b42d",
  28. "assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_SansSerif-Regular.ttf": "b5f967ed9e4933f1c3165a12fe3436df",
  29. "assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_SansSerif-Italic.ttf": "d89b80e7bdd57d238eeaa80ed9a1013a",
  30. "assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Size3-Regular.ttf": "e87212c26bb86c21eb028aba2ac53ec3",
  31. "assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Fraktur-Bold.ttf": "46b41c4de7a936d099575185a94855c4",
  32. "assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Math-BoldItalic.ttf": "946a26954ab7fbd7ea78df07795a6cbc",
  33. "assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Main-Regular.ttf": "5a5766c715ee765aa1398997643f1589",
  34. "assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Size2-Regular.ttf": "959972785387fe35f7d47dbfb0385bc4",
  35. "assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Size1-Regular.ttf": "1e6a3368d660edc3a2fbbe72edfeaa85",
  36. "assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Math-Italic.ttf": "a7732ecb5840a15be39e1eda377bc21d",
  37. "assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_AMS-Regular.ttf": "657a5353a553777e270827bd1630e467",
  38. "assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Size4-Regular.ttf": "85554307b465da7eb785fd3ce52ad282",
  39. "assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_SansSerif-Bold.ttf": "ad0a28f28f736cf4c121bcb0e719b88a",
  40. "assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Caligraphic-Regular.ttf": "7ec92adfa4fe03eb8e9bfb60813df1fa",
  41. "assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Main-Italic.ttf": "ac3b1882325add4f148f05db8cafd401",
  42. "assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Script-Regular.ttf": "55d2dcd4778875a53ff09320a85a5296",
  43. "assets/packages/flutter_math_fork/lib/katex_fonts/fonts/KaTeX_Main-Bold.ttf": "9eef86c1f9efa78ab93d41a0551948f7",
  44. "assets/packages/wakelock_web/assets/no_sleep.js": "7748a45cd593f33280669b29c2c8919a",
  45. "assets/packages/cupertino_icons/assets/CupertinoIcons.ttf": "e986ebe42ef785b27164c36a9abc7818",
  46. "assets/shaders/ink_sparkle.frag": "ecc85a2e95f5e9f53123dcaf8cb9b6ce",
  47. "assets/fonts/MaterialIcons-Regular.otf": "df2312a70f35ed7f476f2b29fcd6c151",
  48. "flutter.js": "f393d3c16b631f36852323de8e583132",
  49. "manifest.json": "301edc2c632971d4cfa1d7b18326b147",
  50. "flutter_bootstrap.js": "f4d66c145ea2a94373c64390d41aa8dd",
  51. "index.html": "63893b2fbb06840ee4ccd5685b789dfc",
  52. "/": "63893b2fbb06840ee4ccd5685b789dfc",
  53. "canvaskit/skwasm.wasm": "9f0c0c02b82a910d12ce0543ec130e60",
  54. "canvaskit/chromium/canvaskit.js": "671c6b4f8fcc199dcc551c7bb125f239",
  55. "canvaskit/chromium/canvaskit.wasm": "b1ac05b29c127d86df4bcfbf50dd902a",
  56. "canvaskit/chromium/canvaskit.js.symbols": "a012ed99ccba193cf96bb2643003f6fc",
  57. "canvaskit/canvaskit.js": "66177750aff65a66cb07bb44b8c6422b",
  58. "canvaskit/skwasm.worker.js": "89990e8c92bcb123999aa81f7e203b1c",
  59. "canvaskit/skwasm.js": "694fda5704053957c2594de355805228",
  60. "canvaskit/canvaskit.wasm": "1f237a213d7370cf95f443d896176460",
  61. "canvaskit/canvaskit.js.symbols": "48c83a2ce573d9692e8d970e288d75f7",
  62. "canvaskit/skwasm.js.symbols": "262f4827a1317abb59d71d6c587a93e2"};
  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. "flutter_bootstrap.js",
  68. "assets/AssetManifest.bin.json",
  69. "assets/FontManifest.json"];
  70. // During install, the TEMP cache is populated with the application shell files.
  71. self.addEventListener("install", (event) => {
  72. self.skipWaiting();
  73. return event.waitUntil(
  74. caches.open(TEMP).then((cache) => {
  75. return cache.addAll(
  76. CORE.map((value) => new Request(value, {'cache': 'reload'})));
  77. })
  78. );
  79. });
  80. // During activate, the cache is populated with the temp files downloaded in
  81. // install. If this service worker is upgrading from one with a saved
  82. // MANIFEST, then use this to retain unchanged resource files.
  83. self.addEventListener("activate", function(event) {
  84. return event.waitUntil(async function() {
  85. try {
  86. var contentCache = await caches.open(CACHE_NAME);
  87. var tempCache = await caches.open(TEMP);
  88. var manifestCache = await caches.open(MANIFEST);
  89. var manifest = await manifestCache.match('manifest');
  90. // When there is no prior manifest, clear the entire cache.
  91. if (!manifest) {
  92. await caches.delete(CACHE_NAME);
  93. contentCache = await caches.open(CACHE_NAME);
  94. for (var request of await tempCache.keys()) {
  95. var response = await tempCache.match(request);
  96. await contentCache.put(request, response);
  97. }
  98. await caches.delete(TEMP);
  99. // Save the manifest to make future upgrades efficient.
  100. await manifestCache.put('manifest', new Response(JSON.stringify(RESOURCES)));
  101. // Claim client to enable caching on first launch
  102. self.clients.claim();
  103. return;
  104. }
  105. var oldManifest = await manifest.json();
  106. var origin = self.location.origin;
  107. for (var request of await contentCache.keys()) {
  108. var key = request.url.substring(origin.length + 1);
  109. if (key == "") {
  110. key = "/";
  111. }
  112. // If a resource from the old manifest is not in the new cache, or if
  113. // the MD5 sum has changed, delete it. Otherwise the resource is left
  114. // in the cache and can be reused by the new service worker.
  115. if (!RESOURCES[key] || RESOURCES[key] != oldManifest[key]) {
  116. await contentCache.delete(request);
  117. }
  118. }
  119. // Populate the cache with the app shell TEMP files, potentially overwriting
  120. // cache files preserved above.
  121. for (var request of await tempCache.keys()) {
  122. var response = await tempCache.match(request);
  123. await contentCache.put(request, response);
  124. }
  125. await caches.delete(TEMP);
  126. // Save the manifest to make future upgrades efficient.
  127. await manifestCache.put('manifest', new Response(JSON.stringify(RESOURCES)));
  128. // Claim client to enable caching on first launch
  129. self.clients.claim();
  130. return;
  131. } catch (err) {
  132. // On an unhandled exception the state of the cache cannot be guaranteed.
  133. console.error('Failed to upgrade service worker: ' + err);
  134. await caches.delete(CACHE_NAME);
  135. await caches.delete(TEMP);
  136. await caches.delete(MANIFEST);
  137. }
  138. }());
  139. });
  140. // The fetch handler redirects requests for RESOURCE files to the service
  141. // worker cache.
  142. self.addEventListener("fetch", (event) => {
  143. if (event.request.method !== 'GET') {
  144. return;
  145. }
  146. var origin = self.location.origin;
  147. var key = event.request.url.substring(origin.length + 1);
  148. // Redirect URLs to the index.html
  149. if (key.indexOf('?v=') != -1) {
  150. key = key.split('?v=')[0];
  151. }
  152. if (event.request.url == origin || event.request.url.startsWith(origin + '/#') || key == '') {
  153. key = '/';
  154. }
  155. // If the URL is not the RESOURCE list then return to signal that the
  156. // browser should take over.
  157. if (!RESOURCES[key]) {
  158. return;
  159. }
  160. // If the URL is the index.html, perform an online-first request.
  161. if (key == '/') {
  162. return onlineFirst(event);
  163. }
  164. event.respondWith(caches.open(CACHE_NAME)
  165. .then((cache) => {
  166. return cache.match(event.request).then((response) => {
  167. // Either respond with the cached resource, or perform a fetch and
  168. // lazily populate the cache only if the resource was successfully fetched.
  169. return response || fetch(event.request).then((response) => {
  170. if (response && Boolean(response.ok)) {
  171. cache.put(event.request, response.clone());
  172. }
  173. return response;
  174. });
  175. })
  176. })
  177. );
  178. });
  179. self.addEventListener('message', (event) => {
  180. // SkipWaiting can be used to immediately activate a waiting service worker.
  181. // This will also require a page refresh triggered by the main worker.
  182. if (event.data === 'skipWaiting') {
  183. self.skipWaiting();
  184. return;
  185. }
  186. if (event.data === 'downloadOffline') {
  187. downloadOffline();
  188. return;
  189. }
  190. });
  191. // Download offline will check the RESOURCES for all files not in the cache
  192. // and populate them.
  193. async function downloadOffline() {
  194. var resources = [];
  195. var contentCache = await caches.open(CACHE_NAME);
  196. var currentContent = {};
  197. for (var request of await contentCache.keys()) {
  198. var key = request.url.substring(origin.length + 1);
  199. if (key == "") {
  200. key = "/";
  201. }
  202. currentContent[key] = true;
  203. }
  204. for (var resourceKey of Object.keys(RESOURCES)) {
  205. if (!currentContent[resourceKey]) {
  206. resources.push(resourceKey);
  207. }
  208. }
  209. return contentCache.addAll(resources);
  210. }
  211. // Attempt to download the resource online before falling back to
  212. // the offline cache.
  213. function onlineFirst(event) {
  214. return event.respondWith(
  215. fetch(event.request).then((response) => {
  216. return caches.open(CACHE_NAME).then((cache) => {
  217. cache.put(event.request, response.clone());
  218. return response;
  219. });
  220. }).catch((error) => {
  221. return caches.open(CACHE_NAME).then((cache) => {
  222. return cache.match(event.request).then((response) => {
  223. if (response != null) {
  224. return response;
  225. }
  226. throw error;
  227. });
  228. });
  229. })
  230. );
  231. }