create-eigen-game 0.16.2 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,82 +0,0 @@
1
- // The app shell's cache, so a game can be opened with no network.
2
- //
3
- // Flutter stopped generating a service worker in 2025, and the browser cache it
4
- // left behind is not a promise: it is evicted on its own terms and never
5
- // answers a cold start offline. Offline play needs the opposite guarantee, so
6
- // this worker is the app's own, small and readable rather than generated.
7
- //
8
- // Runtime caching, not a precache manifest. Flutter's build emits hashed file
9
- // names that a checked-in manifest would have to track release by release; what
10
- // this does instead is remember what the app actually asked for, which after one
11
- // online visit is exactly the shell.
12
-
13
- const CACHE = "eigen-shell-v1";
14
-
15
- // Never cached: the engine's own API and socket. They are the live truth, and a
16
- // stale answer from here would be worse than an honest failure the app already
17
- // knows how to render.
18
- const isApi = (url) => url.pathname.startsWith("/api/");
19
-
20
- self.addEventListener("install", (event) => {
21
- // Take over as soon as this version is ready; there is no migration to stage.
22
- event.waitUntil(self.skipWaiting());
23
- });
24
-
25
- self.addEventListener("activate", (event) => {
26
- event.waitUntil(
27
- (async () => {
28
- const names = await caches.keys();
29
- await Promise.all(names.filter((name) => name !== CACHE).map((name) => caches.delete(name)));
30
- await self.clients.claim();
31
- })(),
32
- );
33
- });
34
-
35
- self.addEventListener("fetch", (event) => {
36
- const request = event.request;
37
- if (request.method !== "GET") return;
38
- const url = new URL(request.url);
39
- if (url.origin !== self.location.origin || isApi(url)) return;
40
-
41
- // A navigation is the app opening. Prefer the network so a deploy is picked
42
- // up, and fall back to whatever shell was cached, which is what makes a cold
43
- // start offline work at all.
44
- if (request.mode === "navigate") {
45
- event.respondWith(
46
- (async () => {
47
- try {
48
- const response = await fetch(request);
49
- const cache = await caches.open(CACHE);
50
- cache.put(request, response.clone());
51
- return response;
52
- } catch (error) {
53
- const cached = (await caches.match(request)) || (await caches.match("/"));
54
- if (cached) return cached;
55
- throw error;
56
- }
57
- })(),
58
- );
59
- return;
60
- }
61
-
62
- // Everything else the shell is built from: answer from the cache instantly and
63
- // refresh it in the background, so a release lands on the next load.
64
- event.respondWith(
65
- (async () => {
66
- const cached = await caches.match(request);
67
- const network = fetch(request)
68
- .then(async (response) => {
69
- if (response.ok) {
70
- const cache = await caches.open(CACHE);
71
- cache.put(request, response.clone());
72
- }
73
- return response;
74
- })
75
- .catch((error) => {
76
- if (cached) return cached;
77
- throw error;
78
- });
79
- return cached || network;
80
- })(),
81
- );
82
- });