|
1 | 1 | <!DOCTYPE html>
|
2 | 2 | <html>
|
3 | 3 | <head>
|
| 4 | + <base href="$FLUTTER_BASE_HREF" /> |
| 5 | + |
4 | 6 | <meta charset="UTF-8" />
|
| 7 | + <meta content="IE=Edge" http-equiv="X-UA-Compatible" /> |
| 8 | + <meta name="description" content="A new Flutter project." /> |
| 9 | + |
| 10 | + <!-- iOS meta tags & icons --> |
| 11 | + <meta name="apple-mobile-web-app-capable" content="yes" /> |
| 12 | + <meta name="apple-mobile-web-app-status-bar-style" content="black" /> |
| 13 | + <meta name="apple-mobile-web-app-title" content="example" /> |
| 14 | + <link rel="apple-touch-icon" href="icons/Icon-192.png" /> |
| 15 | + |
| 16 | + <!-- Favicon --> |
| 17 | + <link rel="icon" type="image/png" href="favicon.png" /> |
| 18 | + |
5 | 19 | <title>example</title>
|
| 20 | + <link rel="manifest" href="manifest.json" /> |
6 | 21 | </head>
|
7 | 22 | <body>
|
8 |
| - <script> |
9 |
| - var serviceWorkerVersion = null; |
10 |
| - var scriptLoaded = false; |
11 |
| - function loadMainDartJs() { |
12 |
| - if (scriptLoaded) { |
13 |
| - return; |
14 |
| - } |
15 |
| - scriptLoaded = true; |
16 |
| - var scriptTag = document.createElement('script'); |
17 |
| - scriptTag.src = 'main.dart.js'; |
18 |
| - scriptTag.type = 'application/javascript'; |
19 |
| - document.body.append(scriptTag); |
20 |
| - } |
21 |
| - |
| 23 | + <script src="flutter_bootstrap.js" async> |
22 | 24 | if ('serviceWorker' in navigator) {
|
23 | 25 | // Service workers are supported. Use them.
|
24 | 26 | window.addEventListener('load', function () {
|
25 | 27 | // Register Firebase Messaging service worker.
|
26 | 28 | navigator.serviceWorker.register('firebase-messaging-sw.js', {
|
27 | 29 | scope: '/firebase-cloud-messaging-push-scope',
|
28 | 30 | });
|
29 |
| - |
30 |
| - // Wait for registration to finish before dropping the <script> tag. |
31 |
| - // Otherwise, the browser will load the script multiple times, |
32 |
| - // potentially different versions. |
33 |
| - var serviceWorkerUrl = |
34 |
| - 'flutter_service_worker.js?v=' + serviceWorkerVersion; |
35 |
| - |
36 |
| - navigator.serviceWorker.register(serviceWorkerUrl).then((reg) => { |
37 |
| - function waitForActivation(serviceWorker) { |
38 |
| - serviceWorker.addEventListener('statechange', () => { |
39 |
| - if (serviceWorker.state == 'activated') { |
40 |
| - console.log('Installed new service worker.'); |
41 |
| - loadMainDartJs(); |
42 |
| - } |
43 |
| - }); |
44 |
| - } |
45 |
| - if (!reg.active && (reg.installing || reg.waiting)) { |
46 |
| - // No active web worker and we have installed or are installing |
47 |
| - // one for the first time. Simply wait for it to activate. |
48 |
| - waitForActivation(reg.installing ?? reg.waiting); |
49 |
| - } else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) { |
50 |
| - // When the app updates the serviceWorkerVersion changes, so we |
51 |
| - // need to ask the service worker to update. |
52 |
| - console.log('New service worker available.'); |
53 |
| - reg.update(); |
54 |
| - waitForActivation(reg.installing); |
55 |
| - } else { |
56 |
| - // Existing service worker is still good. |
57 |
| - console.log('Loading app from service worker.'); |
58 |
| - loadMainDartJs(); |
59 |
| - } |
60 |
| - }); |
61 |
| - |
62 |
| - // If service worker doesn't succeed in a reasonable amount of time, |
63 |
| - // fallback to plaint <script> tag. |
64 |
| - setTimeout(() => { |
65 |
| - if (!scriptLoaded) { |
66 |
| - console.warn( |
67 |
| - 'Failed to load app from service worker. Falling back to plain <script> tag.' |
68 |
| - ); |
69 |
| - loadMainDartJs(); |
70 |
| - } |
71 |
| - }, 4000); |
72 | 31 | });
|
73 |
| - } else { |
74 |
| - // Service workers not supported. Just drop the <script> tag. |
75 |
| - loadMainDartJs(); |
76 | 32 | }
|
77 | 33 | </script>
|
78 | 34 | </body>
|
|
0 commit comments