flutter_service_worker.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 = {
  6. "assets/AssetManifest.json": "d4a84352f999f80ed4ade604f5362483",
  7. "assets/FontManifest.json": "4b7a15aa76d4082cb708323f85c4e208",
  8. "assets/fonts/Eras-BOLD-ITC.ttf": "2e8d0e1501575e1b7f1992c19ef9a8cd",
  9. "assets/fonts/Eras-DEMI-ITC.ttf": "9f7891f4f192f1e8360990fadccccafb",
  10. "assets/fonts/Eras-LIGHT-ITC.ttf": "7a959bdee9e87a5439b915faead1c476",
  11. "assets/fonts/Eras-MEDIUM-ITC.ttf": "00c37a78f957ab5b14c2c7aabddace19",
  12. "assets/fonts/gozap_icons.ttf": "720691457b1c84a823ae5141c32a6ca0",
  13. "assets/fonts/MaterialIcons-Regular.otf": "95db9098c58fd6db106f1116bae85a0b",
  14. "assets/NOTICES": "ccc5e80fe83e53ca211e7c856d613d00",
  15. "assets/packages/cupertino_icons/assets/CupertinoIcons.ttf": "6d342eb68f170c97609e9da345464e5e",
  16. "assets/packages/gozap_package/assets/images/bg/gozap_large_banner.png": "d270797b596a16db7b11ffd8e3c63e17",
  17. "assets/packages/gozap_package/assets/images/bg/gozap_small_banner.png": "807041b9a909aed779248920b07ab684",
  18. "assets/packages/gozap_package/assets/images/logos/gofuel_logo.jpeg": "9420a633092b7f2b037b63b267e8516b",
  19. "assets/packages/gozap_package/assets/images/logos/gozap_large_white_logo.png": "58058340a5f34fc1d20f1eafc7adf9d5",
  20. "assets/packages/gozap_package/assets/images/logos/gozap_smaill_white_bg_logo.png": "90fc96bff9939c43ddfcd798031138fe",
  21. "assets/packages/gozap_package/assets/images/logos/gozap_small_color_logo.png": "48c88184ea5343e55b3109c7b2790f39",
  22. "assets/packages/gozap_package/assets/images/personal_info_profile.png": "babcac7192f46dd1c2fc42d852dc5d2c",
  23. "assets/packages/gozap_package/assets/json/countries.json": "3476a68d983d25ba5f17a1a4075fbeaa",
  24. "assets/packages/gozap_package/assets/locale/data.json": "4aab15bc3e4076bceea13e34d3f1ec18",
  25. "assets/packages/gozap_package/assets/locale/localization_en.json": "4d5feb3245324c4e9aa1f4c0f4eebcf2",
  26. "assets/packages/gozap_package/assets/lottie/logged_in_lottie.json": "284cd90a83e8909acb41ec804b1bc770",
  27. "assets/packages/gozap_package/assets/lottie/recharged_lottie.json": "232e8445268210a574d613f61a40beda",
  28. "assets/packages/gozap_package/assets/lottie/registered_lottie.json": "cb41def8492745f6da17aa174f24bc18",
  29. "assets/packages/gozap_package/fonts/gozap_icons.ttf": "e84cab828b7f01dc47d1e0dd7385a99b",
  30. "assets/packages/gozap_package/fonts/icomoon.ttf": "5748b712ce11ab7faa5431d9ed5bcdc4",
  31. "assets/packages/toast/assets/toastify.css": "a85675050054f179444bc5ad70ffc635",
  32. "assets/packages/toast/assets/toastify.js": "e7006a0a033d834ef9414d48db3be6fc",
  33. "assets/shaders/ink_sparkle.frag": "ae6c1fd6f6ee6ee952cde379095a8f3f",
  34. "favicon.png": "5dcef449791fa27946b3d35ad8803796",
  35. "icons/Icon-192.png": "ac9a721a12bbc803b44f645561ecb1e1",
  36. "icons/Icon-512.png": "96e752610906ba2a93c65f8abe1645f1",
  37. "icons/Icon-maskable-192.png": "c457ef57daa1d16f64b27b786ec2ea3c",
  38. "icons/Icon-maskable-512.png": "301a7604d45b3e739efc881eb04896ea",
  39. "index.html": "e1e437e78fcf2b36080a55f623ddc149",
  40. "/": "e1e437e78fcf2b36080a55f623ddc149",
  41. "main.dart.js": "db2f0a6319b8587b4e12cf7f07124660",
  42. "manifest.json": "ab99c3f1ff8f1deab9f82a080776e4e2",
  43. "version.json": "7d4cf7885cb246fa8c9f282dcbd4e21c"
  44. };
  45. // The application shell files that are downloaded before a service worker can
  46. // start.
  47. const CORE = [
  48. "main.dart.js",
  49. "index.html",
  50. "assets/AssetManifest.json",
  51. "assets/FontManifest.json"];
  52. // During install, the TEMP cache is populated with the application shell files.
  53. self.addEventListener("install", (event) => {
  54. self.skipWaiting();
  55. return event.waitUntil(
  56. caches.open(TEMP).then((cache) => {
  57. return cache.addAll(
  58. CORE.map((value) => new Request(value, {'cache': 'reload'})));
  59. })
  60. );
  61. });
  62. // During activate, the cache is populated with the temp files downloaded in
  63. // install. If this service worker is upgrading from one with a saved
  64. // MANIFEST, then use this to retain unchanged resource files.
  65. self.addEventListener("activate", function(event) {
  66. return event.waitUntil(async function() {
  67. try {
  68. var contentCache = await caches.open(CACHE_NAME);
  69. var tempCache = await caches.open(TEMP);
  70. var manifestCache = await caches.open(MANIFEST);
  71. var manifest = await manifestCache.match('manifest');
  72. // When there is no prior manifest, clear the entire cache.
  73. if (!manifest) {
  74. await caches.delete(CACHE_NAME);
  75. contentCache = await caches.open(CACHE_NAME);
  76. for (var request of await tempCache.keys()) {
  77. var response = await tempCache.match(request);
  78. await contentCache.put(request, response);
  79. }
  80. await caches.delete(TEMP);
  81. // Save the manifest to make future upgrades efficient.
  82. await manifestCache.put('manifest', new Response(JSON.stringify(RESOURCES)));
  83. return;
  84. }
  85. var oldManifest = await manifest.json();
  86. var origin = self.location.origin;
  87. for (var request of await contentCache.keys()) {
  88. var key = request.url.substring(origin.length + 1);
  89. if (key == "") {
  90. key = "/";
  91. }
  92. // If a resource from the old manifest is not in the new cache, or if
  93. // the MD5 sum has changed, delete it. Otherwise the resource is left
  94. // in the cache and can be reused by the new service worker.
  95. if (!RESOURCES[key] || RESOURCES[key] != oldManifest[key]) {
  96. await contentCache.delete(request);
  97. }
  98. }
  99. // Populate the cache with the app shell TEMP files, potentially overwriting
  100. // cache files preserved above.
  101. for (var request of await tempCache.keys()) {
  102. var response = await tempCache.match(request);
  103. await contentCache.put(request, response);
  104. }
  105. await caches.delete(TEMP);
  106. // Save the manifest to make future upgrades efficient.
  107. await manifestCache.put('manifest', new Response(JSON.stringify(RESOURCES)));
  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. }