swarm-ui: the browser chrome takes the theme's background colour
The theme-color meta was a fixed mauve, so a phone's status bar and an installed app's title bar stayed mauve under every theme, light ones included. The theme effect sets it from the computed --bg after each change, and again when the OS scheme changes under auto.
This commit is contained in:
parent
bcb432caf4
commit
868b8743d8
1 changed files with 53 additions and 0 deletions
|
|
@ -15,6 +15,7 @@
|
|||
// default").
|
||||
import { useEffect } from "preact/hooks";
|
||||
import { useLocalSetting } from "./settings-storage.js";
|
||||
import { themeColorOf } from "./theme-color.js";
|
||||
import { AUTO_THEME, DEFAULT_THEME, themeChoice } from "./themes.js";
|
||||
|
||||
/** `[choice, setChoice]`: `auto` or a theme id from `./themes.ts`. */
|
||||
|
|
@ -42,5 +43,21 @@ export function useApplyThemeOverride(
|
|||
} else {
|
||||
root.dataset.theme = choice;
|
||||
}
|
||||
// The browser's own chrome follows the page background. `auto` can
|
||||
// change with the OS, so it is read again then.
|
||||
const sync = () => {
|
||||
const color = themeColorOf(
|
||||
getComputedStyle(root).getPropertyValue("--bg"),
|
||||
);
|
||||
if (color === null) return;
|
||||
document
|
||||
.querySelector<HTMLMetaElement>('meta[name="theme-color"]')
|
||||
?.setAttribute("content", color);
|
||||
};
|
||||
sync();
|
||||
if (choice !== AUTO_THEME) return;
|
||||
const scheme = window.matchMedia("(prefers-color-scheme: dark)");
|
||||
scheme.addEventListener("change", sync);
|
||||
return () => scheme.removeEventListener("change", sync);
|
||||
}, [choice]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue