index.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <!DOCTYPE html><html><head>
  2. <!--
  3. If you are serving your web app in a path other than the root, change the
  4. href value below to reflect the base path you are serving from.
  5. The path provided below has to start and end with a slash "/" in order for
  6. it to work correctly.
  7. For more details:
  8. * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
  9. This is a placeholder for base href that will be replaced by the value of
  10. the `--base-href` argument provided to `flutter build`.
  11. -->
  12. <base href="$FLUTTER_BASE_HREF">
  13. <meta charset="UTF-8">
  14. <meta content="IE=Edge" http-equiv="X-UA-Compatible">
  15. <meta name="description" content="A Very Good new Flutter project.">
  16. <!-- iOS meta tags & icons -->
  17. <meta name="apple-mobile-web-app-capable" content="yes">
  18. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  19. <meta name="apple-mobile-web-app-title" content="My App">
  20. <link rel="apple-touch-icon" href="icons/Icon-192.png">
  21. <!-- Favicon -->
  22. <link rel="icon" type="image/png" href="favicon.png">
  23. <title>My App</title>
  24. <link rel="manifest" href="manifest.json">
  25. <link rel="stylesheet" type="text/css" href="splash/style.css">
  26. <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">
  27. <script src="splash/splash.js"></script>
  28. </head>
  29. <body>
  30. <picture id="splash">
  31. <source srcset="splash/img/light-1x.png 1x, splash/img/light-2x.png 2x, splash/img/light-3x.png 3x, splash/img/light-4x.png 4x" media="(prefers-color-scheme: light)">
  32. <source srcset="splash/img/dark-1x.png 1x, splash/img/dark-2x.png 2x, splash/img/dark-3x.png 3x, splash/img/dark-4x.png 4x" media="(prefers-color-scheme: dark)">
  33. <img class="center" aria-hidden="true" src="splash/img/light-1x.png" alt="">
  34. </picture>
  35. <!-- This script installs service_worker.js to provide PWA functionality to
  36. application. For more information, see:
  37. https://developers.google.com/web/fundamentals/primers/service-workers -->
  38. <script>
  39. var serviceWorkerVersion = null;
  40. var scriptLoaded = false;
  41. function loadMainDartJs() {
  42. if (scriptLoaded) {
  43. return;
  44. }
  45. scriptLoaded = true;
  46. var scriptTag = document.createElement('script');
  47. scriptTag.src = 'main.dart.js';
  48. scriptTag.type = 'application/javascript';
  49. document.body.append(scriptTag);
  50. }
  51. if ('serviceWorker' in navigator) {
  52. // Service workers are supported. Use them.
  53. window.addEventListener('load', function () {
  54. // Wait for registration to finish before dropping the <script> tag.
  55. // Otherwise, the browser will load the script multiple times,
  56. // potentially different versions.
  57. var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;
  58. navigator.serviceWorker.register(serviceWorkerUrl)
  59. .then((reg) => {
  60. function waitForActivation(serviceWorker) {
  61. serviceWorker.addEventListener('statechange', () => {
  62. if (serviceWorker.state == 'activated') {
  63. console.log('Installed new service worker.');
  64. loadMainDartJs();
  65. }
  66. });
  67. }
  68. if (!reg.active && (reg.installing || reg.waiting)) {
  69. // No active web worker and we have installed or are installing
  70. // one for the first time. Simply wait for it to activate.
  71. waitForActivation(reg.installing || reg.waiting);
  72. } else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
  73. // When the app updates the serviceWorkerVersion changes, so we
  74. // need to ask the service worker to update.
  75. console.log('New service worker available.');
  76. reg.update();
  77. waitForActivation(reg.installing);
  78. } else {
  79. // Existing service worker is still good.
  80. console.log('Loading app from service worker.');
  81. loadMainDartJs();
  82. }
  83. });
  84. // If service worker doesn't succeed in a reasonable amount of time,
  85. // fallback to plaint <script> tag.
  86. setTimeout(() => {
  87. if (!scriptLoaded) {
  88. console.warn(
  89. 'Failed to load app from service worker. Falling back to plain <script> tag.',
  90. );
  91. loadMainDartJs();
  92. }
  93. }, 4000);
  94. });
  95. } else {
  96. // Service workers not supported. Just drop the <script> tag.
  97. loadMainDartJs();
  98. }
  99. </script>
  100. </body></html>