feat: dark mode support (#53)

This commit is contained in:
qier222 2020-10-25 21:04:33 +08:00 committed by GitHub
parent 4e482941ed
commit b655c59761
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 301 additions and 181 deletions

View file

@ -45,4 +45,24 @@ if ([undefined, null].includes(store.state.settings.lang)) {
localStorage.setItem("settings", JSON.stringify(store.state.settings));
}
if (
store.state.settings.appearance !== "auto" &&
store.state.settings.appearance !== undefined
) {
document.body.setAttribute("data-theme", store.state.settings.appearance);
} else {
document.body.setAttribute(
"data-theme",
window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"
);
}
window
.matchMedia("(prefers-color-scheme: dark)")
.addEventListener("change", (e) => {
if (store.state.settings.appearance === "auto") {
store.commit("updateTmpAppearance", e.matches ? "dark" : "light");
document.body.setAttribute("data-theme", e.matches ? "dark" : "light");
}
});
export default store;