Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking for window.matchMedia('(prefers-color-scheme: dark)').matches would do

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll test this.

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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would duplicate configEnabled

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I'm not sure it does. It looked to me that configEnabled is not binary, so supports the option 'honour the system' so can't be relied upon for stating that dark theme was in fact enabled.

Copy link
Member

@haslinghuis haslinghuis Sep 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above statement would extract the value or [use] get ConfigStorage darkTheme value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which means configEnabled is not well named. It should be configSetting or similar. It can't be relied upon as to if it's actually applied or not... sure it'll have a value of two... but does that mean dark theme is active? I don't think it does because the test of isEnabled is not persisted...

};

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