diff --git a/web/index.html b/web/index.html
index 606be5059..0f2e41db3 100644
--- a/web/index.html
+++ b/web/index.html
@@ -9,7 +9,8 @@
-
+
+
diff --git a/web/src/utils/theme.ts b/web/src/utils/theme.ts
index 2232be921..521b643d2 100644
--- a/web/src/utils/theme.ts
+++ b/web/src/utils/theme.ts
@@ -175,10 +175,27 @@ const setThemeAttribute = (theme: ResolvedTheme): void => {
* Updates the theme-color meta tag to match the current theme background.
* This colors the browser/status bar on mobile devices.
*/
-const updateThemeColorMeta = (theme: ResolvedTheme): void => {
- const meta = document.querySelector('meta[name="theme-color"]');
- if (meta) {
- meta.content = THEME_COLORS[theme];
+const updateThemeColorMeta = (theme: Theme): void => {
+ const lightMeta = document.querySelector('meta[name="theme-color"][media*="light"]');
+ const darkMeta = document.querySelector('meta[name="theme-color"][media*="dark"]');
+
+ if (theme === "system") {
+ if (lightMeta) {
+ lightMeta.content = THEME_COLORS.default;
+ }
+ if (darkMeta) {
+ darkMeta.content = THEME_COLORS["default-dark"];
+ }
+ return;
+ }
+
+ const resolvedTheme = resolveTheme(theme);
+ const color = THEME_COLORS[resolvedTheme];
+ if (lightMeta) {
+ lightMeta.content = color;
+ }
+ if (darkMeta) {
+ darkMeta.content = color;
}
};
@@ -213,7 +230,7 @@ export const loadTheme = (themeName: string): void => {
injectThemeStyle(resolvedTheme);
setThemeAttribute(resolvedTheme);
- updateThemeColorMeta(resolvedTheme);
+ updateThemeColorMeta(validTheme);
updateColorScheme(resolvedTheme);
setStoredTheme(validTheme); // Store original theme preference (not resolved)
};
diff --git a/web/tests/theme.test.ts b/web/tests/theme.test.ts
new file mode 100644
index 000000000..95db85937
--- /dev/null
+++ b/web/tests/theme.test.ts
@@ -0,0 +1,33 @@
+import { beforeEach, describe, expect, it } from "vitest";
+import { loadTheme } from "@/utils/theme";
+
+describe("theme-color meta tags update", () => {
+ beforeEach(() => {
+ document.head.innerHTML = `
+
+
+ `;
+ localStorage.clear();
+ });
+
+ it("updates meta tags to specific theme color when a non-system theme is loaded", () => {
+ loadTheme("default-dark");
+
+ const lightMeta = document.querySelector('meta[name="theme-color"][media*="light"]');
+ const darkMeta = document.querySelector('meta[name="theme-color"][media*="dark"]');
+
+ expect(lightMeta?.content).toBe("#1d1f23");
+ expect(darkMeta?.content).toBe("#1d1f23");
+ });
+
+ it("restores adaptive meta tags when system theme is loaded", () => {
+ loadTheme("paper");
+ loadTheme("system");
+
+ const lightMeta = document.querySelector('meta[name="theme-color"][media*="light"]');
+ const darkMeta = document.querySelector('meta[name="theme-color"][media*="dark"]');
+
+ expect(lightMeta?.content).toBe("#faf9f5");
+ expect(darkMeta?.content).toBe("#1d1f23");
+ });
+});