Skip to content

Commit 2813bbe

Browse files
committed
Draft for mobile app.
1 parent b65daf4 commit 2813bbe

File tree

5 files changed

+145
-0
lines changed

5 files changed

+145
-0
lines changed

astro.config.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import pagefind from "astro-pagefind";
1111
import deleteUnusedImages from "astro-delete-unused-images";
1212
import preload from "astro-preload";
1313
import { execSync } from "node:child_process";
14+
import basicSsl from "@vitejs/plugin-basic-ssl";
1415

1516
import compress from "astro-compress";
1617

@@ -31,6 +32,10 @@ if (!gitVersion) {
3132
// https://astro.build/config
3233
export default defineConfig({
3334
vite: {
35+
plugins: [basicSsl()],
36+
server: {
37+
https: true,
38+
},
3439
define: {
3540
__TIMESTAMP__: JSON.stringify(
3641
new Date()

pnpm-lock.yaml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/manifest.json

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"name": "EuroPython 2025",
3+
"short_name": "EP2025",
4+
"display": "standalone",
5+
"start_url": "./?utm_source=pwa_install",
6+
"lang": "en",
7+
"scope": ".",
8+
"background_color": "#6200ee",
9+
"theme_color": "#6200ee",
10+
"icons": [
11+
{
12+
"src": "android-chrome-36x36.png",
13+
"sizes": "36x36",
14+
"type": "image/png"
15+
},
16+
{
17+
"src": "android-chrome-48x48.png",
18+
"sizes": "48x48",
19+
"type": "image/png"
20+
},
21+
{
22+
"src": "android-chrome-72x72.png",
23+
"sizes": "72x72",
24+
"type": "image/png"
25+
},
26+
{
27+
"src": "android-chrome-96x96.png",
28+
"sizes": "96x96",
29+
"type": "image/png"
30+
},
31+
{
32+
"src": "android-chrome-144x144.png",
33+
"sizes": "144x144",
34+
"type": "image/png"
35+
},
36+
{
37+
"src": "android-chrome-192x192.png",
38+
"sizes": "192x192",
39+
"type": "image/png"
40+
},
41+
{
42+
"src": "android-chrome-256x256.png",
43+
"sizes": "256x256",
44+
"type": "image/png"
45+
},
46+
{
47+
"src": "android-chrome-384x384.png",
48+
"sizes": "384x384",
49+
"type": "image/png"
50+
},
51+
{
52+
"src": "android-chrome-512x512.png",
53+
"sizes": "512x512",
54+
"type": "image/png"
55+
},
56+
{
57+
"src": "maskable_icon.png",
58+
"sizes": "650x650",
59+
"type": "image/png",
60+
"purpose": "maskable"
61+
}
62+
]
63+
}

public/sw.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const cacheName = "cache2";
2+
3+
self.addEventListener("install", (event) => {
4+
self.skipWaiting();
5+
6+
event.waitUntil(
7+
caches.open(cacheName).then((cache) => {
8+
return cache.addAll([
9+
"/",
10+
"favicon.ico",
11+
"index.html",
12+
"main.js",
13+
"manifest.json",
14+
"style.css",
15+
]);
16+
})
17+
);
18+
});
19+
20+
self.addEventListener("activate", (event) => {
21+
event.waitUntil(
22+
caches.keys().then((keys) => {
23+
Promise.all(
24+
keys.map((key) => {
25+
if (![cacheName].includes(key)) {
26+
return caches.delete(key);
27+
}
28+
})
29+
);
30+
})
31+
);
32+
});
33+
34+
self.addEventListener("fetch", (event) => {
35+
event.respondWith(
36+
caches.open(cacheName).then((cache) => {
37+
return cache.match(event.request).then((response) => {
38+
return (
39+
response ||
40+
fetch(event.request).then((networkResponse) => {
41+
cache.put(event.request, networkResponse.clone());
42+
return networkResponse;
43+
})
44+
);
45+
});
46+
})
47+
);
48+
});

src/layouts/Layout.astro

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ const externalDomain = new URL(Astro.site || "").hostname;
2828
<head>
2929
<BaseHead title={title} description={description} />
3030
<slot name="head" />
31+
32+
<link rel="manifest" href="/manifest.json" />
33+
<meta name="theme-color" content="#6200ee" />
34+
<link rel="apple-touch-icon" href="/icons/icon-192x192.png" />
3135
</Fragment>
3236

3337
<body>
@@ -96,3 +100,15 @@ const externalDomain = new URL(Astro.site || "").hostname;
96100
}
97101
}
98102
</style>
103+
104+
<script>
105+
if ("serviceWorker" in navigator) {
106+
window.addEventListener("load", () => {
107+
navigator.serviceWorker.register("/sw.js").then((registration) => {
108+
console.log("ServiceWorker registered: ", registration);
109+
}).catch((registrationError) => {
110+
console.log("ServiceWorker registration failed: ", registrationError);
111+
});
112+
});
113+
}
114+
</script>

0 commit comments

Comments
 (0)