mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-16 04:45:20 +03:00
Merge pull request #2012 from WalcoFPV/dark_theme
DarkTheme auto change when prefers color scheme change
This commit is contained in:
commit
de70148a4b
2 changed files with 22 additions and 9 deletions
|
@ -12,18 +12,28 @@ DarkTheme.isDarkThemeEnabled = function (val) {
|
|||
return val === 0 || val === 2 && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
};
|
||||
|
||||
DarkTheme.apply = function() {
|
||||
if (this.isDarkThemeEnabled(this.configEnabled)) {
|
||||
this.applyDark();
|
||||
} else {
|
||||
this.applyNormal();
|
||||
}
|
||||
|
||||
if (chrome.app.window !== undefined) {
|
||||
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;
|
||||
|
||||
if (this.isDarkThemeEnabled(this.configEnabled)) {
|
||||
this.applyDark();
|
||||
} else {
|
||||
this.applyNormal();
|
||||
}
|
||||
|
||||
windowWatcherUtil.passValue(chrome.app.window.get("receiver_msp"), 'darkTheme', this.isDarkThemeEnabled(this.configEnabled));
|
||||
|
||||
this.apply();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -595,6 +595,9 @@ function startProcess() {
|
|||
setDarkTheme(result.darkTheme);
|
||||
}
|
||||
});
|
||||
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", function() {
|
||||
DarkTheme.autoSet();
|
||||
});
|
||||
}
|
||||
|
||||
function setDarkTheme(enabled) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue