mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-11 03:24:16 +00:00
handle auto prefered color scheme
This commit is contained in:
parent
8590a364d2
commit
78a7ac018d
@ -12,6 +12,11 @@ export default class StyleCore extends Core {
|
|||||||
currentVariant = null
|
currentVariant = null
|
||||||
|
|
||||||
events = {
|
events = {
|
||||||
|
"app.autoDarkMode": (value) => {
|
||||||
|
if (value === true) {
|
||||||
|
this.handleAutoColorScheme()
|
||||||
|
}
|
||||||
|
},
|
||||||
"theme.applyVariant": (value) => {
|
"theme.applyVariant": (value) => {
|
||||||
this.applyVariant(value)
|
this.applyVariant(value)
|
||||||
this.setVariant(value)
|
this.setVariant(value)
|
||||||
@ -28,11 +33,21 @@ export default class StyleCore extends Core {
|
|||||||
publicMethods = {
|
publicMethods = {
|
||||||
style: this
|
style: this
|
||||||
}
|
}
|
||||||
|
|
||||||
static get currentVariant() {
|
static get currentVariant() {
|
||||||
return document.documentElement.style.getPropertyValue("--themeVariant")
|
return document.documentElement.style.getPropertyValue("--themeVariant")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleAutoColorScheme() {
|
||||||
|
const prefered = window.matchMedia("(prefers-color-scheme: light)")
|
||||||
|
|
||||||
|
if (window.app.settings.get("app.auto_darkMode") && !prefered.matches) {
|
||||||
|
this.applyVariant("dark")
|
||||||
|
}else {
|
||||||
|
this.applyVariant("false")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
initialize = async () => {
|
initialize = async () => {
|
||||||
let theme = this.getStoragedTheme()
|
let theme = this.getStoragedTheme()
|
||||||
|
|
||||||
@ -61,6 +76,11 @@ export default class StyleCore extends Core {
|
|||||||
|
|
||||||
// apply variation
|
// apply variation
|
||||||
this.applyVariant(variantKey)
|
this.applyVariant(variantKey)
|
||||||
|
|
||||||
|
// handle auto prefered color scheme
|
||||||
|
if (window.app.settings.get("app.auto_darkMode")) {
|
||||||
|
window.matchMedia("(prefers-color-scheme: light)").addListener(this.handleAutoColorScheme)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getRootVariables = () => {
|
getRootVariables = () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user