2021-08-08 01:47:29 -04:00
|
|
|
export default {
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2021-08-12 10:17:20 -04:00
|
|
|
system: (window.matchMedia("(prefers-color-scheme: dark)").matches) ? "dark" : "light",
|
2021-08-08 01:47:29 -04:00
|
|
|
userTheme: localStorage.theme,
|
2021-08-16 11:14:05 -04:00
|
|
|
userHeartbeatBar: localStorage.heartbeatBarTheme,
|
2021-09-23 01:57:24 -04:00
|
|
|
statusPageTheme: "light",
|
2021-09-11 07:40:03 -04:00
|
|
|
path: "",
|
2021-08-08 01:47:29 -04:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
// Default Light
|
|
|
|
if (! this.userTheme) {
|
2021-09-04 14:47:31 -04:00
|
|
|
this.userTheme = "auto";
|
2021-08-08 01:47:29 -04:00
|
|
|
}
|
|
|
|
|
2021-08-16 11:14:13 -04:00
|
|
|
// Default Heartbeat Bar
|
2021-08-16 11:14:21 -04:00
|
|
|
if (!this.userHeartbeatBar) {
|
2021-08-15 14:46:21 -04:00
|
|
|
this.userHeartbeatBar = "normal";
|
|
|
|
}
|
|
|
|
|
2021-08-08 01:47:29 -04:00
|
|
|
document.body.classList.add(this.theme);
|
2021-08-12 12:23:40 -04:00
|
|
|
this.updateThemeColorMeta();
|
2021-08-08 01:47:29 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
theme() {
|
2021-09-23 01:57:24 -04:00
|
|
|
|
|
|
|
// Entry no need dark
|
|
|
|
if (this.path === "") {
|
|
|
|
return "light";
|
|
|
|
}
|
|
|
|
|
2021-09-25 10:44:29 -04:00
|
|
|
if (this.path === "/status-page" || this.path === "/status") {
|
2021-09-11 07:40:03 -04:00
|
|
|
return this.statusPageTheme;
|
|
|
|
} else {
|
|
|
|
if (this.userTheme === "auto") {
|
|
|
|
return this.system;
|
|
|
|
}
|
|
|
|
return this.userTheme;
|
2021-08-08 01:47:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
2021-09-11 07:40:03 -04:00
|
|
|
"$route.fullPath"(path) {
|
|
|
|
this.path = path;
|
|
|
|
},
|
|
|
|
|
2021-08-08 01:47:29 -04:00
|
|
|
userTheme(to, from) {
|
|
|
|
localStorage.theme = to;
|
|
|
|
},
|
|
|
|
|
|
|
|
theme(to, from) {
|
|
|
|
document.body.classList.remove(from);
|
|
|
|
document.body.classList.add(this.theme);
|
2021-08-12 12:23:40 -04:00
|
|
|
this.updateThemeColorMeta();
|
2021-08-15 14:46:21 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
userHeartbeatBar(to, from) {
|
|
|
|
localStorage.heartbeatBarTheme = to;
|
|
|
|
},
|
|
|
|
|
|
|
|
heartbeatBarTheme(to, from) {
|
|
|
|
document.body.classList.remove(from);
|
|
|
|
document.body.classList.add(this.heartbeatBarTheme);
|
2021-08-12 12:23:40 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
updateThemeColorMeta() {
|
|
|
|
if (this.theme === "dark") {
|
|
|
|
document.querySelector("#theme-color").setAttribute("content", "#161B22");
|
|
|
|
} else {
|
|
|
|
document.querySelector("#theme-color").setAttribute("content", "#5cdd8b");
|
|
|
|
}
|
2021-08-08 01:47:29 -04:00
|
|
|
}
|
|
|
|
}
|
2021-09-23 01:57:24 -04:00
|
|
|
};
|
2021-08-08 01:47:29 -04:00
|
|
|
|