-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env sh | ||
|
||
set -e | ||
|
||
patch build/web/flutter.js < build_tools/web/flutter.js.patch | ||
patch build/web/flutter_service_worker.js < build_tools/web/flutter_service_worker.js.patch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- build/web/flutter.js.orig 2023-03-01 15:40:58.588065610 +0800 | ||
+++ build/web/flutter.js 2023-03-01 15:43:48.879605009 +0800 | ||
@@ -375,7 +375,16 @@ | ||
// Install the `didCreateEngineInitializer` listener where Flutter web expects it to be. | ||
this.didCreateEngineInitializer = | ||
entrypointLoader.didCreateEngineInitializer.bind(entrypointLoader); | ||
- return entrypointLoader.loadEntrypoint(entrypoint); | ||
+ const main = entrypointLoader.loadEntrypoint(entrypoint); | ||
+ | ||
+ fetch("canvaskit/canvaskit.js"); | ||
+ fetch("canvaskit/canvaskit.wasm"); | ||
+ fetch("assets/FontManifest.json"); | ||
+ fetch("assets/fonts/MaterialIcons-Regular.otf"); | ||
+ fetch("assets/packages/cupertino_icons/assets/CupertinoIcons.ttf"); | ||
+ fetch("/"); | ||
+ | ||
+ return main; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
--- build/web/flutter_service_worker.js.orig 2023-02-14 05:46:14.641558233 +0800 | ||
+++ build/web/flutter_service_worker.js 2023-02-14 05:48:16.339943489 +0800 | ||
@@ -29,21 +29,6 @@ | ||
"/": "edf4d01f5266c63075af78507efdc906"}; | ||
// The application shell files that are downloaded before a service worker can | ||
// start. | ||
-const CORE = ["main.dart.js", | ||
-"index.html", | ||
-"assets/AssetManifest.json", | ||
-"assets/FontManifest.json"]; | ||
- | ||
-// During install, the TEMP cache is populated with the application shell files. | ||
-self.addEventListener("install", (event) => { | ||
- self.skipWaiting(); | ||
- return event.waitUntil( | ||
- caches.open(TEMP).then((cache) => { | ||
- return cache.addAll( | ||
- CORE.map((value) => new Request(value, {'cache': 'reload'}))); | ||
- }) | ||
- ); | ||
-}); | ||
// During activate, the cache is populated with the temp files downloaded in | ||
// install. If this service worker is upgrading from one with a saved | ||
// MANIFEST, then use this to retain unchanged resource files. | ||
@@ -104,6 +89,7 @@ | ||
} | ||
}()); | ||
}); | ||
+var IN_PROCESSING_REQUESTS = {}; | ||
// The fetch handler redirects requests for RESOURCE files to the service | ||
// worker cache. | ||
self.addEventListener("fetch", (event) => { | ||
@@ -133,12 +119,27 @@ | ||
return cache.match(event.request).then((response) => { | ||
// Either respond with the cached resource, or perform a fetch and | ||
// lazily populate the cache only if the resource was successfully fetched. | ||
- return response || fetch(event.request).then((response) => { | ||
+ | ||
+ if (response) { | ||
+ return response; | ||
+ } | ||
+ | ||
+ if (IN_PROCESSING_REQUESTS[key]) { | ||
+ return IN_PROCESSING_REQUESTS[key].clone(); | ||
+ } | ||
+ | ||
+ return fetch(event.request).then((response) => { | ||
if (response && Boolean(response.ok)) { | ||
- cache.put(event.request, response.clone()); | ||
+ | ||
+ cache.put(event.request, response.clone()) | ||
+ .then(() => delete IN_PROCESSING_REQUESTS[key]); | ||
} | ||
+ | ||
+ IN_PROCESSING_REQUESTS[key] = response.clone(); | ||
+ | ||
return response; | ||
}); | ||
+ | ||
}) | ||
}) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,6 +109,12 @@ <h2>End-to-end encryption</h2> | |
_loadScript("https://cdn.jsdelivr.net/npm/[email protected]/dist/jsQR.min.js"); | ||
}); | ||
}); | ||
|
||
// load serviceworker earlier | ||
const serviceWorkerActivation = navigator.serviceWorker.register( | ||
"flutter_service_worker.js?v=" + serviceWorkerVersion | ||
); | ||
|
||
</script> | ||
</body> | ||
</html> |