Skip to content

Commit 13bbefb

Browse files
committed
Add PWA support with dynamic themes
1 parent aade591 commit 13bbefb

File tree

8 files changed

+96
-0
lines changed

8 files changed

+96
-0
lines changed

public/images/pwa-icon-512.png

9.44 KB
Loading

public/images/screenshots/dark-1.jpg

46.2 KB
Loading

public/images/screenshots/dark-2.jpg

32.2 KB
Loading

public/images/screenshots/light-1.jpg

49 KB
Loading

public/images/screenshots/light-2.jpg

34.3 KB
Loading

public/manifest-dark.json

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"short_name": "Runic",
3+
"name": "Runic",
4+
"description": "The ultimate Tunic translator tool - translate, write and share text in the Tunic language!",
5+
"start_url": "/",
6+
"background_color": "#000000",
7+
"display": "standalone",
8+
"theme_color": "#000000",
9+
"icons": [
10+
{
11+
"src": "./images/pwa-icon-512.png",
12+
"type": "image/png",
13+
"sizes": "512x512",
14+
"purpose": "any"
15+
},
16+
{
17+
"src": "./images/pwa-icon-512.png",
18+
"type": "image/png",
19+
"sizes": "512x512",
20+
"purpose": "maskable"
21+
}
22+
],
23+
"screenshots": [
24+
{
25+
"src": "/images/screenshots/dark-1.jpg",
26+
"type": "image/jpeg",
27+
"sizes": "541x1201",
28+
"form_factor": "narrow",
29+
"label": "App on mobile (1)"
30+
},
31+
{
32+
"src": "/images/screenshots/dark-2.jpg",
33+
"type": "image/jpeg",
34+
"sizes": "541x1201",
35+
"form_factor": "narrow",
36+
"label": "App on mobile (2)"
37+
}
38+
]
39+
}

public/manifest-light.json

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"short_name": "Runic",
3+
"name": "Runic",
4+
"description": "The ultimate Tunic translator tool - translate, write and share text in the Tunic language!",
5+
"start_url": "/",
6+
"background_color": "#ffffff",
7+
"display": "standalone",
8+
"theme_color": "#ffffff",
9+
"icons": [
10+
{
11+
"src": "./images/pwa-icon-512.png",
12+
"type": "image/png",
13+
"sizes": "512x512",
14+
"purpose": "any"
15+
},
16+
{
17+
"src": "./images/pwa-icon-512.png",
18+
"type": "image/png",
19+
"sizes": "512x512",
20+
"purpose": "maskable"
21+
}
22+
],
23+
"screenshots": [
24+
{
25+
"src": "/images/screenshots/light-1.jpg",
26+
"type": "image/jpeg",
27+
"sizes": "541x1201",
28+
"form_factor": "narrow",
29+
"label": "App on mobile (1)"
30+
},
31+
{
32+
"src": "/images/screenshots/light-2.jpg",
33+
"type": "image/jpeg",
34+
"sizes": "541x1201",
35+
"form_factor": "narrow",
36+
"label": "App on mobile (2)"
37+
}
38+
]
39+
}

src/initial-resources/index.ts

+18
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
11
import "./fonts.css";
22
import "./index.css";
33

4+
function getManifestLinkElement(): HTMLLinkElement {
5+
const query = document.head.querySelector(`link[rel="manifest"]`) as HTMLLinkElement;
6+
if(query) return query;
7+
8+
// Create the link element
9+
const element = document.createElement("link");
10+
element.rel = "manifest";
11+
document.head.appendChild(element);
12+
13+
return element;
14+
}
15+
416
function setTheme() {
517
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
618
if (mediaQuery.matches) {
719
// Dark theme
820
document.documentElement.classList.remove("light-theme");
21+
// Set manifest
22+
const element = getManifestLinkElement();
23+
element.setAttribute("href", "manifest-dark.json");
924
} else {
1025
// Light theme
1126
document.documentElement.classList.add("light-theme");
27+
// Set manifest
28+
const element = getManifestLinkElement();
29+
element.setAttribute("href", "manifest-light.json");
1230
}
1331
}
1432

0 commit comments

Comments
 (0)