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