2021-08-08 05:47:29 +00:00
|
|
|
export default {
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2021-08-12 14:17:20 +00:00
|
|
|
system: (window.matchMedia("(prefers-color-scheme: dark)").matches) ? "dark" : "light",
|
2021-08-08 05:47:29 +00:00
|
|
|
userTheme: localStorage.theme,
|
2021-08-16 15:14:05 +00:00
|
|
|
userHeartbeatBar: localStorage.heartbeatBarTheme,
|
2023-08-07 19:00:40 +00:00
|
|
|
styleElapsedTime: localStorage.styleElapsedTime,
|
2021-09-23 05:57:24 +00:00
|
|
|
statusPageTheme: "light",
|
2022-04-10 05:46:00 +00:00
|
|
|
forceStatusPageTheme: false,
|
2021-09-11 11:40:03 +00:00
|
|
|
path: "",
|
2021-08-08 05:47:29 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
// Default Light
|
|
|
|
if (! this.userTheme) {
|
2021-09-04 18:47:31 +00:00
|
|
|
this.userTheme = "auto";
|
2021-08-08 05:47:29 +00:00
|
|
|
}
|
|
|
|
|
2021-08-16 15:14:13 +00:00
|
|
|
// Default Heartbeat Bar
|
2021-08-16 15:14:21 +00:00
|
|
|
if (!this.userHeartbeatBar) {
|
2021-08-15 18:46:21 +00:00
|
|
|
this.userHeartbeatBar = "normal";
|
|
|
|
}
|
|
|
|
|
2023-08-07 19:00:40 +00:00
|
|
|
// Default Elapsed Time Style
|
|
|
|
if (!this.styleElapsedTime) {
|
|
|
|
this.styleElapsedTime = "no-line";
|
|
|
|
}
|
|
|
|
|
2021-08-08 05:47:29 +00:00
|
|
|
document.body.classList.add(this.theme);
|
2021-08-12 16:23:40 +00:00
|
|
|
this.updateThemeColorMeta();
|
2021-08-08 05:47:29 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
theme() {
|
2022-04-10 05:46:00 +00:00
|
|
|
// As entry can be status page now, set forceStatusPageTheme to true to use status page theme
|
|
|
|
if (this.forceStatusPageTheme) {
|
2023-06-21 15:58:49 +00:00
|
|
|
if (this.statusPageTheme === "auto") {
|
|
|
|
return this.system;
|
|
|
|
}
|
2022-04-10 05:46:00 +00:00
|
|
|
return this.statusPageTheme;
|
|
|
|
}
|
2021-09-23 05:57:24 +00:00
|
|
|
|
|
|
|
// Entry no need dark
|
|
|
|
if (this.path === "") {
|
|
|
|
return "light";
|
|
|
|
}
|
|
|
|
|
2022-03-18 04:57:37 +00:00
|
|
|
if (this.path.startsWith("/status-page") || this.path.startsWith("/status")) {
|
2023-03-01 23:26:26 +00:00
|
|
|
if (this.statusPageTheme === "auto") {
|
|
|
|
return this.system;
|
|
|
|
}
|
2021-09-11 11:40:03 +00:00
|
|
|
return this.statusPageTheme;
|
|
|
|
} else {
|
|
|
|
if (this.userTheme === "auto") {
|
|
|
|
return this.system;
|
|
|
|
}
|
|
|
|
return this.userTheme;
|
2021-08-08 05:47:29 +00:00
|
|
|
}
|
2022-09-23 18:33:29 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
isDark() {
|
|
|
|
return this.theme === "dark";
|
2021-08-08 05:47:29 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
2021-09-11 11:40:03 +00:00
|
|
|
"$route.fullPath"(path) {
|
|
|
|
this.path = path;
|
|
|
|
},
|
|
|
|
|
2021-08-08 05:47:29 +00:00
|
|
|
userTheme(to, from) {
|
|
|
|
localStorage.theme = to;
|
|
|
|
},
|
|
|
|
|
2023-08-07 19:00:40 +00:00
|
|
|
styleElapsedTime(to, from) {
|
|
|
|
localStorage.styleElapsedTime = to;
|
|
|
|
},
|
|
|
|
|
2021-08-08 05:47:29 +00:00
|
|
|
theme(to, from) {
|
|
|
|
document.body.classList.remove(from);
|
|
|
|
document.body.classList.add(this.theme);
|
2021-08-12 16:23:40 +00:00
|
|
|
this.updateThemeColorMeta();
|
2021-08-15 18:46:21 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
userHeartbeatBar(to, from) {
|
|
|
|
localStorage.heartbeatBarTheme = to;
|
|
|
|
},
|
|
|
|
|
|
|
|
heartbeatBarTheme(to, from) {
|
|
|
|
document.body.classList.remove(from);
|
|
|
|
document.body.classList.add(this.heartbeatBarTheme);
|
2021-08-12 16:23:40 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2023-08-11 07:46:41 +00:00
|
|
|
/**
|
|
|
|
* Update the theme color meta tag
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2021-08-12 16:23:40 +00:00
|
|
|
updateThemeColorMeta() {
|
|
|
|
if (this.theme === "dark") {
|
|
|
|
document.querySelector("#theme-color").setAttribute("content", "#161B22");
|
|
|
|
} else {
|
|
|
|
document.querySelector("#theme-color").setAttribute("content", "#5cdd8b");
|
|
|
|
}
|
2021-08-08 05:47:29 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-23 05:57:24 +00:00
|
|
|
};
|
2021-08-08 05:47:29 +00:00
|
|
|
|