mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-24 00:35:26 +03:00
Merge pull request #2165 from WalcoFPV/cordova-themedetection-plugin
Fixed auto dark theme on android
This commit is contained in:
commit
8032b1f4ee
4 changed files with 53 additions and 14 deletions
|
@ -8,20 +8,39 @@ var DarkTheme = {
|
|||
configEnabled: undefined,
|
||||
};
|
||||
|
||||
DarkTheme.isDarkThemeEnabled = function (val) {
|
||||
return val === 0 || val === 2 && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
DarkTheme.isDarkThemeEnabled = function (callback) {
|
||||
if (this.configEnabled === 0) {
|
||||
callback(true);
|
||||
} else if (this.configEnabled === 2) {
|
||||
if (GUI.isCordova()) {
|
||||
cordova.plugins.ThemeDetection.isDarkModeEnabled(function(success) {
|
||||
callback(success.value);
|
||||
}, function(error) {
|
||||
console.log(`cordova-plugin-theme-detection: ${error}`);
|
||||
callback(false);
|
||||
});
|
||||
} else {
|
||||
const isEnabled = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
callback(isEnabled);
|
||||
}
|
||||
} else {
|
||||
callback(false);
|
||||
}
|
||||
};
|
||||
|
||||
DarkTheme.apply = function() {
|
||||
if (this.isDarkThemeEnabled(this.configEnabled)) {
|
||||
this.applyDark();
|
||||
} else {
|
||||
this.applyNormal();
|
||||
}
|
||||
const self = this;
|
||||
this.isDarkThemeEnabled(function(isEnabled) {
|
||||
if (isEnabled) {
|
||||
self.applyDark();
|
||||
} else {
|
||||
self.applyNormal();
|
||||
}
|
||||
|
||||
if (chrome.app.window !== undefined) {
|
||||
windowWatcherUtil.passValue(chrome.app.window.get("receiver_msp"), 'darkTheme', this.isDarkThemeEnabled(this.configEnabled));
|
||||
}
|
||||
if (chrome.app.window !== undefined) {
|
||||
windowWatcherUtil.passValue(chrome.app.window.get("receiver_msp"), 'darkTheme', isEnabled);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
DarkTheme.autoSet = function() {
|
||||
|
@ -31,7 +50,7 @@ DarkTheme.autoSet = function() {
|
|||
};
|
||||
|
||||
DarkTheme.setConfig = function (result) {
|
||||
if (this.configEnabled != result) {
|
||||
if (this.configEnabled !== result) {
|
||||
this.configEnabled = result;
|
||||
this.apply();
|
||||
}
|
||||
|
|
|
@ -514,9 +514,22 @@ function startProcess() {
|
|||
setDarkTheme(result.darkTheme);
|
||||
}
|
||||
});
|
||||
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", function() {
|
||||
DarkTheme.autoSet();
|
||||
});
|
||||
if (GUI.isCordova()) {
|
||||
let darkMode = false;
|
||||
const checkDarkMode = function() {
|
||||
cordova.plugins.ThemeDetection.isDarkModeEnabled(function(success) {
|
||||
if (success.value !== darkMode) {
|
||||
darkMode = success.value;
|
||||
DarkTheme.autoSet();
|
||||
}
|
||||
});
|
||||
};
|
||||
setInterval(checkDarkMode, 500);
|
||||
} else {
|
||||
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