mirror of
https://github.com/usememos/memos.git
synced 2024-11-11 07:24:18 +03:00
chore: update color scheme listener (#735)
This commit is contained in:
parent
37b7b983d2
commit
5e978e2cfc
@ -22,12 +22,23 @@ function App() {
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", (e) => {
|
||||
const darkMediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
||||
const handleColorSchemeChange = (e: MediaQueryListEvent) => {
|
||||
if (globalService.getState().appearance === "system") {
|
||||
const mode = e.matches ? "dark" : "light";
|
||||
setMode(mode);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
try {
|
||||
if (darkMediaQuery.addEventListener) {
|
||||
darkMediaQuery.addEventListener("change", handleColorSchemeChange);
|
||||
} else {
|
||||
darkMediaQuery.addListener(handleColorSchemeChange);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("failed to initial color scheme listener", error);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// Inject additional style and script codes.
|
||||
|
Loading…
Reference in New Issue
Block a user