flutter_service_worker.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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": "25b5d291ff64948174d36b77dbaff9b1",
  7. "assets/FontManifest.json": "aab967607fda6f2ff0039b8d8f8091fc",
  8. "assets/fonts/MaterialIcons-Regular.otf": "95db9098c58fd6db106f1116bae85a0b",
  9. "assets/NOTICES": "1fa7f4a33a7e40f8bb11c0269fac4b7e",
  10. "assets/packages/cupertino_icons/assets/CupertinoIcons.ttf": "6d342eb68f170c97609e9da345464e5e",
  11. "assets/packages/gozap_package/assets/images/bg/gozap_large_banner.png": "d270797b596a16db7b11ffd8e3c63e17",
  12. "assets/packages/gozap_package/assets/images/bg/gozap_small_banner.png": "807041b9a909aed779248920b07ab684",
  13. "assets/packages/gozap_package/assets/images/logos/gofuel_logo.jpeg": "9420a633092b7f2b037b63b267e8516b",
  14. "assets/packages/gozap_package/assets/images/logos/gozap_large_white_logo.png": "58058340a5f34fc1d20f1eafc7adf9d5",
  15. "assets/packages/gozap_package/assets/images/logos/gozap_smaill_white_bg_logo.png": "90fc96bff9939c43ddfcd798031138fe",
  16. "assets/packages/gozap_package/assets/images/logos/gozap_small_color_logo.png": "48c88184ea5343e55b3109c7b2790f39",
  17. "assets/packages/gozap_package/assets/images/personal_info_profile.png": "babcac7192f46dd1c2fc42d852dc5d2c",
  18. "assets/packages/gozap_package/assets/json/countries.json": "3476a68d983d25ba5f17a1a4075fbeaa",
  19. "assets/packages/gozap_package/assets/locale/data.json": "4aab15bc3e4076bceea13e34d3f1ec18",
  20. "assets/packages/gozap_package/assets/locale/localization_en.json": "4d5feb3245324c4e9aa1f4c0f4eebcf2",
  21. "assets/packages/gozap_package/assets/lottie/logged_in_lottie.json": "284cd90a83e8909acb41ec804b1bc770",
  22. "assets/packages/gozap_package/assets/lottie/recharged_lottie.json": "232e8445268210a574d613f61a40beda",
  23. "assets/packages/gozap_package/assets/lottie/registered_lottie.json": "cb41def8492745f6da17aa174f24bc18",
  24. "assets/packages/gozap_package/fonts/gozap_icons.ttf": "e84cab828b7f01dc47d1e0dd7385a99b",
  25. "assets/packages/gozap_package/fonts/icomoon.ttf": "5748b712ce11ab7faa5431d9ed5bcdc4",
  26. "assets/packages/simple_barcode_scanner/assets/barcode.html": "afb6a6df8cb2e8242c1b72522cdfdafb",
  27. "assets/packages/simple_barcode_scanner/assets/html5-qrcode.min.js": "157c564823c850c8832b8bc75b392526",
  28. "assets/packages/toast/assets/toastify.css": "a85675050054f179444bc5ad70ffc635",
  29. "assets/packages/toast/assets/toastify.js": "e7006a0a033d834ef9414d48db3be6fc",
  30. "assets/shaders/ink_sparkle.frag": "ae6c1fd6f6ee6ee952cde379095a8f3f",
  31. "favicon.png": "5dcef449791fa27946b3d35ad8803796",
  32. "icons/Icon-192.png": "ac9a721a12bbc803b44f645561ecb1e1",
  33. "icons/Icon-512.png": "96e752610906ba2a93c65f8abe1645f1",
  34. "icons/Icon-maskable-192.png": "c457ef57daa1d16f64b27b786ec2ea3c",
  35. "icons/Icon-maskable-512.png": "301a7604d45b3e739efc881eb04896ea",
  36. "index.html": "6cc5c730921dd97f0e6a194140bd1aac",
  37. "/": "6cc5c730921dd97f0e6a194140bd1aac",
  38. "main.dart.js": "9b110b3b1ce92f631725c7a92199e75b",
  39. "manifest.json": "65af4122a86ee8d7f0c1b190019ef8f3",
  40. "packages/gozap_package/fonts/gozap_icons.ttf": "e84cab828b7f01dc47d1e0dd7385a99b",
  41. "version.json": "8c66f6f7c9f92618b937203d6df8e177"
  42. };
  43. // The application shell files that are downloaded before a service worker can
  44. // start.
  45. const CORE = [
  46. "main.dart.js",
  47. "index.html",
  48. "assets/AssetManifest.json",
  49. "assets/FontManifest.json"];
  50. // During install, the TEMP cache is populated with the application shell files.
  51. self.addEventListener("install", (event) => {
  52. self.skipWaiting();
  53. return event.waitUntil(
  54. caches.open(TEMP).then((cache) => {
  55. return cache.addAll(
  56. CORE.map((value) => new Request(value, {'cache': 'reload'})));
  57. })
  58. );
  59. });
  60. // During activate, the cache is populated with the temp files downloaded in
  61. // install. If this service worker is upgrading from one with a saved
  62. // MANIFEST, then use this to retain unchanged resource files.
  63. self.addEventListener("activate", function(event) {
  64. return event.waitUntil(async function() {
  65. try {
  66. var contentCache = await caches.open(CACHE_NAME);
  67. var tempCache = await caches.open(TEMP);
  68. var manifestCache = await caches.open(MANIFEST);
  69. var manifest = await manifestCache.match('manifest');
  70. // When there is no prior manifest, clear the entire cache.
  71. if (!manifest) {
  72. await caches.delete(CACHE_NAME);
  73. contentCache = await caches.open(CACHE_NAME);
  74. for (var request of await tempCache.keys()) {
  75. var response = await tempCache.match(request);
  76. await contentCache.put(request, response);
  77. }
  78. await caches.delete(TEMP);
  79. // Save the manifest to make future upgrades efficient.
  80. await manifestCache.put('manifest', new Response(JSON.stringify(RESOURCES)));
  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. return;
  107. } catch (err) {
  108. // On an unhandled exception the state of the cache cannot be guaranteed.
  109. console.error('Failed to upgrade service worker: ' + err);
  110. await caches.delete(CACHE_NAME);
  111. await caches.delete(TEMP);
  112. await caches.delete(MANIFEST);
  113. }
  114. }());
  115. });
  116. // The fetch handler redirects requests for RESOURCE files to the service
  117. // worker cache.
  118. self.addEventListener("fetch", (event) => {
  119. if (event.request.method !== 'GET') {
  120. return;
  121. }
  122. var origin = self.location.origin;
  123. var key = event.request.url.substring(origin.length + 1);
  124. // Redirect URLs to the index.html
  125. if (key.indexOf('?v=') != -1) {
  126. key = key.split('?v=')[0];
  127. }
  128. if (event.request.url == origin || event.request.url.startsWith(origin + '/#') || key == '') {
  129. key = '/';
  130. }
  131. // If the URL is not the RESOURCE list then return to signal that the
  132. // browser should take over.
  133. if (!RESOURCES[key]) {
  134. return;
  135. }
  136. // If the URL is the index.html, perform an online-first request.
  137. if (key == '/') {
  138. return onlineFirst(event);
  139. }
  140. event.respondWith(caches.open(CACHE_NAME)
  141. .then((cache) => {
  142. return cache.match(event.request).then((response) => {
  143. // Either respond with the cached resource, or perform a fetch and
  144. // lazily populate the cache only if the resource was successfully fetched.
  145. return response || fetch(event.request).then((response) => {
  146. if (response && Boolean(response.ok)) {
  147. cache.put(event.request, response.clone());
  148. }
  149. return response;
  150. });
  151. })
  152. })
  153. );
  154. });
  155. self.addEventListener('message', (event) => {
  156. // SkipWaiting can be used to immediately activate a waiting service worker.
  157. // This will also require a page refresh triggered by the main worker.
  158. if (event.data === 'skipWaiting') {
  159. self.skipWaiting();
  160. return;
  161. }
  162. if (event.data === 'downloadOffline') {
  163. downloadOffline();
  164. return;
  165. }
  166. });
  167. // Download offline will check the RESOURCES for all files not in the cache
  168. // and populate them.
  169. async function downloadOffline() {
  170. var resources = [];
  171. var contentCache = await caches.open(CACHE_NAME);
  172. var currentContent = {};
  173. for (var request of await contentCache.keys()) {
  174. var key = request.url.substring(origin.length + 1);
  175. if (key == "") {
  176. key = "/";
  177. }
  178. currentContent[key] = true;
  179. }
  180. for (var resourceKey of Object.keys(RESOURCES)) {
  181. if (!currentContent[resourceKey]) {
  182. resources.push(resourceKey);
  183. }
  184. }
  185. return contentCache.addAll(resources);
  186. }
  187. // Attempt to download the resource online before falling back to
  188. // the offline cache.
  189. function onlineFirst(event) {
  190. return event.respondWith(
  191. fetch(event.request).then((response) => {
  192. return caches.open(CACHE_NAME).then((cache) => {
  193. cache.put(event.request, response.clone());
  194. return response;
  195. });
  196. }).catch((error) => {
  197. return caches.open(CACHE_NAME).then((cache) => {
  198. return cache.match(event.request).then((response) => {
  199. if (response != null) {
  200. return response;
  201. }
  202. throw error;
  203. });
  204. });
  205. })
  206. );
  207. }