mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-12 03:54:16 +00:00
handle auto color scheme
This commit is contained in:
parent
1562ac7555
commit
ade7db35dc
@ -12,9 +12,11 @@ export default class StyleCore extends Core {
|
|||||||
currentVariant = null
|
currentVariant = null
|
||||||
|
|
||||||
events = {
|
events = {
|
||||||
"app.autoDarkMode": (value) => {
|
"app.autoDarkModeToogle": (value) => {
|
||||||
if (value === true) {
|
if (value === true) {
|
||||||
this.handleAutoColorScheme()
|
this.handleAutoColorScheme()
|
||||||
|
}else {
|
||||||
|
this.applyVariant(this.getStoragedVariant())
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"theme.applyVariant": (value) => {
|
"theme.applyVariant": (value) => {
|
||||||
@ -41,10 +43,10 @@ export default class StyleCore extends Core {
|
|||||||
handleAutoColorScheme() {
|
handleAutoColorScheme() {
|
||||||
const prefered = window.matchMedia("(prefers-color-scheme: light)")
|
const prefered = window.matchMedia("(prefers-color-scheme: light)")
|
||||||
|
|
||||||
if (window.app.settings.get("app.auto_darkMode") && !prefered.matches) {
|
if (!prefered.matches) {
|
||||||
this.applyVariant("dark")
|
this.applyVariant("dark")
|
||||||
} else {
|
} else {
|
||||||
this.applyVariant("false")
|
this.applyVariant("light")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,8 +80,16 @@ export default class StyleCore extends Core {
|
|||||||
this.applyVariant(variantKey)
|
this.applyVariant(variantKey)
|
||||||
|
|
||||||
// handle auto prefered color scheme
|
// handle auto prefered color scheme
|
||||||
if (window.app.settings.get("app.auto_darkMode")) {
|
window.matchMedia("(prefers-color-scheme: light)").addListener(() => {
|
||||||
window.matchMedia("(prefers-color-scheme: light)").addListener(this.handleAutoColorScheme)
|
console.log(`[THEME] Auto color scheme changed`)
|
||||||
|
|
||||||
|
if (window.app.settings.get("auto_darkMode")) {
|
||||||
|
this.handleAutoColorScheme()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (window.app.settings.get("auto_darkMode")) {
|
||||||
|
this.handleAutoColorScheme()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user