1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-25 09:15:49 +03:00

Adding dark and light theme names to the sponsor request (params to API) (#3561)

* Adding dark and light theme names to the sponsor request (params to API)

* Renamed configEnabled to configSetting as it does not reflect whether or not the darkTheme is currently enabled (just its setting).

* Missed the configEnabled in the optionsTab.
This commit is contained in:
J Blackman 2023-09-27 22:20:26 +10:00 committed by GitHub
parent 56ab8073dc
commit e120c4893f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 11 deletions

View file

@ -172,8 +172,8 @@ export default class BuildApi {
this.load(url, onSuccess, onFailure);
}
loadSponsorTile(onSuccess, onFailure) {
const url = `${this._url}/api/configurator/sponsors`;
loadSponsorTile(mode, onSuccess, onFailure) {
const url = `${this._url}/api/configurator/sponsors/${mode}`;
this.load(url, onSuccess, onFailure);
}
}

View file

@ -8,13 +8,14 @@ const css_dark = [
];
const DarkTheme = {
configEnabled: undefined,
configSetting: undefined,
enabled: false,
};
DarkTheme.isDarkThemeEnabled = function (callback) {
if (this.configEnabled === 0) {
if (this.configSetting === 0) {
callback(true);
} else if (this.configEnabled === 2) {
} else if (this.configSetting === 2) {
if (GUI.isCordova()) {
cordova.plugins.ThemeDetection.isDarkModeEnabled(function(success) {
callback(success.value);
@ -47,27 +48,28 @@ DarkTheme.apply = function() {
};
DarkTheme.autoSet = function() {
if (this.configEnabled === 2) {
if (this.configSetting === 2) {
this.apply();
}
};
DarkTheme.setConfig = function (result) {
if (this.configEnabled !== result) {
this.configEnabled = result;
if (this.configSetting !== result) {
this.configSetting = result;
this.apply();
}
};
DarkTheme.applyDark = function () {
css_dark.forEach((el) => $(`link[href="${el}"]`).prop('disabled', false));
this.enabled = true;
};
DarkTheme.applyNormal = function () {
css_dark.forEach((el) => $(`link[href="${el}"]`).prop('disabled', true));
this.enabled = false;
};
export function setDarkTheme(enabled) {
DarkTheme.setConfig(enabled);

View file

@ -19,6 +19,7 @@ import { gui_log } from '../gui_log';
import semver from 'semver';
import { checkChromeRuntimeError, urlExists } from '../utils/common';
import { generateFilename } from '../utils/generate_filename';
import DarkTheme from '../DarkTheme';
const firmware_flasher = {
targets: null,
@ -55,7 +56,7 @@ firmware_flasher.initialize = function (callback) {
return;
}
self.releaseLoader.loadSponsorTile(
self.releaseLoader.loadSponsorTile(DarkTheme.enabled ? 'dark' : 'light',
(content) => {
if (content) {
$('div.tab_sponsor').html(content);

View file

@ -179,7 +179,7 @@ options.initCordovaForceComputerUI = function () {
options.initDarkTheme = function () {
$('#darkThemeSelect')
.val(DarkTheme.configEnabled)
.val(DarkTheme.configSetting)
.change(function () {
const value = parseInt($(this).val());