Add auto theme option.

This commit is contained in:
FireMasterK 2021-07-06 00:03:00 +05:30
parent b5a0ca8324
commit 9b79a9c848
No known key found for this signature in database
GPG Key ID: 49451E4482CC5BCD
2 changed files with 13 additions and 5 deletions

View File

@ -34,6 +34,7 @@
<b>Theme</b>
<br />
<select class="uk-select uk-width-auto" v-model="selectedTheme" @change="onChange($event)">
<option value="auto">Auto</option>
<option value="dark">Dark</option>
<option value="light">Light</option>
</select>

View File

@ -129,22 +129,29 @@ const mixin = {
apiUrl() {
return this.getPreferenceString("instance", "https://pipedapi.kavin.rocks");
},
getEffectiveTheme() {
var theme = this.getPreferenceString("theme", "dark");
if (theme === "auto")
theme =
window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
return theme;
},
},
computed: {
backgroundColor() {
return this.getPreferenceString("theme", "dark") === "light" ? "#fff" : "#0b0e0f";
return this.getEffectiveTheme() === "light" ? "#fff" : "#0b0e0f";
},
secondaryBackgroundColor() {
return this.getPreferenceString("theme", "dark") === "light" ? "#e5e5e5" : "#242727";
return this.getEffectiveTheme() === "light" ? "#e5e5e5" : "#242727";
},
foregroundColor() {
return this.getPreferenceString("theme", "dark") === "light" ? "#15191a" : "#0b0e0f";
return this.getEffectiveTheme() === "light" ? "#15191a" : "#0b0e0f";
},
secondaryForegroundColor() {
return this.getPreferenceString("theme", "dark") === "light" ? "#666" : "#393d3d";
return this.getEffectiveTheme() === "light" ? "#666" : "#393d3d";
},
darkMode() {
return this.getPreferenceString("theme", "dark") !== "light";
return this.getEffectiveTheme() !== "light";
},
},
};