|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | + <!-- |
| 5 | + If you are serving your web app in a path other than the root, change the |
| 6 | + href value below to reflect the base path you are serving from. |
| 7 | +
|
| 8 | + The path provided below has to start and end with a slash "/" in order for |
| 9 | + it to work correctly. |
| 10 | +
|
| 11 | + For more details: |
| 12 | + * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base |
| 13 | +
|
| 14 | + This is a placeholder for base href that will be replaced by the value of |
| 15 | + the `--base-href` argument provided to `flutter build`. |
| 16 | + --> |
| 17 | + <base href="$FLUTTER_BASE_HREF"> |
| 18 | + |
| 19 | + <meta charset="UTF-8"> |
| 20 | + <meta content="IE=Edge" http-equiv="X-UA-Compatible"> |
| 21 | + <meta name="description" content="{{{project_description}}}"> |
| 22 | + |
| 23 | + <!-- iOS meta tags & icons --> |
| 24 | + <meta name="apple-mobile-web-app-capable" content="yes"> |
| 25 | + <meta name="apple-mobile-web-app-status-bar-style" content="black"> |
| 26 | + <meta name="apple-mobile-web-app-title" content="{{project_title}}"> |
| 27 | + <link rel="apple-touch-icon" href="icons/Icon-192.png"> |
| 28 | + |
| 29 | + <!-- Favicon --> |
| 30 | + <link rel="icon" type="image/png" href="favicon.png"/> |
| 31 | + |
| 32 | + <title>{{project_title}}</title> |
| 33 | + <link rel="manifest" href="manifest.json"> |
| 34 | + <style type="text/css"> |
| 35 | + body.loading-mode { |
| 36 | + display: flex; |
| 37 | + align-items: center; |
| 38 | + justify-content: center; |
| 39 | + } |
| 40 | + </style> |
| 41 | + |
| 42 | + <script> |
| 43 | + // The value below is injected by flutter build, do not touch. |
| 44 | + var serviceWorkerVersion = null; |
| 45 | + </script> |
| 46 | +</head> |
| 47 | +<body class="loading-mode"> |
| 48 | + <div id="progress-bar" style="border: 1px solid blue; width: 250px; height: 50px;"> |
| 49 | + <div id="progress-indicator" style="background-color: blue; height: 100%; width: 0%;"></div> |
| 50 | + </div> |
| 51 | + <script> |
| 52 | + // The value below is injected by flutter build, do not touch. |
| 53 | + var serviceWorkerVersion = null; |
| 54 | + </script> |
| 55 | + <script> |
| 56 | + (function() { |
| 57 | + const progressBar = document.querySelector('#progress-bar'); |
| 58 | + const progressIndicator = document.querySelector('#progress-indicator'); |
| 59 | + |
| 60 | + const additionalScripts = [ |
| 61 | + // Add additional scripts here. |
| 62 | + ]; |
| 63 | + |
| 64 | + function injectScript(url) { |
| 65 | + return new Promise(function(resolve) { |
| 66 | + let scriptTag = document.createElement('script'); |
| 67 | + scriptTag.src = url; |
| 68 | + scriptTag.type = 'application/javascript'; |
| 69 | + scriptTag.onload = function() { |
| 70 | + resolve(); |
| 71 | + }; |
| 72 | + |
| 73 | + document.body.append(scriptTag); |
| 74 | + }); |
| 75 | + } |
| 76 | + |
| 77 | + function beginPreloading(manifestAssets) { |
| 78 | + var assets = [ |
| 79 | + 'flutter.js', |
| 80 | + 'main.dart.js', |
| 81 | + {{#canvaskit}} |
| 82 | + 'canvaskit/canvaskit.wasm', |
| 83 | + 'canvaskit/canvaskit.js', |
| 84 | + {{/canvaskit}} |
| 85 | + ...additionalScripts, |
| 86 | + ...manifestAssets, |
| 87 | + ]; |
| 88 | + let totalAssets = assets.length + 1; |
| 89 | + let loaded = 0; |
| 90 | + |
| 91 | + const batchSize = {{batch_size}}; |
| 92 | + |
| 93 | + async function reportProgress() { |
| 94 | + loaded++; |
| 95 | + const value = Math.floor((loaded / totalAssets) * 100) + '%'; |
| 96 | + progressIndicator.style.width = value; |
| 97 | + |
| 98 | + if (assets.length == 0) { |
| 99 | + dispatchAppLoad(); |
| 100 | + } else { |
| 101 | + load(assets.shift()); |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + function load(url) { |
| 106 | + const req = new XMLHttpRequest(); |
| 107 | + req.onload = reportProgress; |
| 108 | + req.open('get', url); |
| 109 | + req.send(); |
| 110 | + } |
| 111 | + |
| 112 | + function startBatch() { |
| 113 | + const end = Math.min(batchSize, assets.length); |
| 114 | + for (let i = 0; i < end; i++) { |
| 115 | + load(assets.shift()); |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + |
| 120 | + var scriptLoaded = false; |
| 121 | + async function dispatchAppLoad() { |
| 122 | + if (scriptLoaded) { |
| 123 | + return; |
| 124 | + } |
| 125 | + scriptLoaded = true; |
| 126 | + |
| 127 | + for (let i = 0; i < additionalScripts.length; i++) { |
| 128 | + await injectScript(additionalScripts[i]); |
| 129 | + } |
| 130 | + |
| 131 | + await injectScript('flutter.js'); |
| 132 | + |
| 133 | + // Download main.dart.js |
| 134 | + _flutter.loader.loadEntrypoint({ |
| 135 | + serviceWorker: { |
| 136 | + serviceWorkerVersion: serviceWorkerVersion, |
| 137 | + }, |
| 138 | + onEntrypointLoaded: function(engineInitializer) { |
| 139 | + engineInitializer.initializeEngine().then(async function(appRunner) { |
| 140 | + progressBar.remove(); |
| 141 | + document.body.classList.remove('loading-mode'); |
| 142 | + appRunner.runApp(); |
| 143 | + }); |
| 144 | + } |
| 145 | + }); |
| 146 | + } |
| 147 | + |
| 148 | + startBatch(); |
| 149 | + } |
| 150 | + |
| 151 | + window.addEventListener('load', async function(ev) { |
| 152 | + const response = await fetch('assets/AssetManifest.json'); |
| 153 | + const manifest = await response.json(); |
| 154 | + const assets = Object.values(manifest) |
| 155 | + .map((list) => list.map((url) => 'assets/' + url)) |
| 156 | + .reduce((arr, curr) => [...arr, ...curr]); |
| 157 | + |
| 158 | + beginPreloading(assets); |
| 159 | + }); |
| 160 | + })(); |
| 161 | + </script> |
| 162 | + </body> |
| 163 | +</html> |
0 commit comments