Skip to content

Commit

Permalink
Adding dark and light theme names to the sponsor request (params to A…
Browse files Browse the repository at this point in the history
…PI) (#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.
  • Loading branch information
blckmn authored Sep 27, 2023
1 parent 56ab807 commit e120c48
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/js/BuildApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
16 changes: 9 additions & 7 deletions src/js/DarkTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion src/js/tabs/firmware_flasher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/js/tabs/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ options.initCordovaForceComputerUI = function () {

options.initDarkTheme = function () {
$('#darkThemeSelect')
.val(DarkTheme.configEnabled)
.val(DarkTheme.configSetting)
.change(function () {
const value = parseInt($(this).val());

Expand Down

0 comments on commit e120c48

Please sign in to comment.