DarkTheme auto change when prefers color scheme change
parent
d636ca9fd0
commit
c87e596dfb
|
@ -12,18 +12,28 @@ DarkTheme.isDarkThemeEnabled = function (val) {
|
||||||
return val === 0 || val === 2 && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
return val === 0 || val === 2 && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||||
};
|
};
|
||||||
|
|
||||||
DarkTheme.setConfig = function (result) {
|
DarkTheme.apply = function() {
|
||||||
if (this.configEnabled != result) {
|
|
||||||
this.configEnabled = result;
|
|
||||||
|
|
||||||
if (this.isDarkThemeEnabled(this.configEnabled)) {
|
if (this.isDarkThemeEnabled(this.configEnabled)) {
|
||||||
this.applyDark();
|
this.applyDark();
|
||||||
} else {
|
} else {
|
||||||
this.applyNormal();
|
this.applyNormal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (chrome.app.window !== undefined) {
|
||||||
windowWatcherUtil.passValue(chrome.app.window.get("receiver_msp"), 'darkTheme', this.isDarkThemeEnabled(this.configEnabled));
|
windowWatcherUtil.passValue(chrome.app.window.get("receiver_msp"), 'darkTheme', this.isDarkThemeEnabled(this.configEnabled));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
DarkTheme.autoSet = function() {
|
||||||
|
if (this.configEnabled === 2) {
|
||||||
|
this.apply();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
DarkTheme.setConfig = function (result) {
|
||||||
|
if (this.configEnabled != result) {
|
||||||
|
this.configEnabled = result;
|
||||||
|
this.apply();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -501,6 +501,9 @@ function startProcess() {
|
||||||
setDarkTheme(result.darkTheme);
|
setDarkTheme(result.darkTheme);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", function() {
|
||||||
|
DarkTheme.autoSet();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setDarkTheme(enabled) {
|
function setDarkTheme(enabled) {
|
||||||
|
|
Loading…
Reference in New Issue