Skip to content

Commit 029dce7

Browse files
Implement theme settings in user preferences
- Add theme setting in user preferences panel with three options: Light theme, Dark theme, Automatic (follow system) - Default theme is now Dark theme - Fix theme toggle button icon rendering by using solid Font Awesome icons (fa-moon and fa-sun instead of fa-moon-o and fa-sun-o) - Update setSelected function to properly handle onchange callbacks for local settings - Ensure theme preference dropdown defaults correctly for new users Co-authored-by: Dimitrie Hoekstra <[email protected]>
1 parent 32bc4f6 commit 029dce7

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

packages/node_modules/@node-red/editor-client/src/js/ui/deploy.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ RED.deploy = (function() {
7070

7171
// Add dark mode toggle button
7272
$('<li><a id="red-ui-header-button-theme-toggle" class="button" href="#" title="Toggle Theme">'+
73-
'<i class="fa fa-moon-o"></i>'+
73+
'<i class="fa fa-moon"></i>'+
7474
'</a></li>').prependTo(".red-ui-header-toolbar");
7575
const mainMenuItems = [
7676
{id:"deploymenu-item-full",toggle:"deploy-type",icon:"red/images/deploy-full.svg",label:RED._("deploy.full"),sublabel:RED._("deploy.fullDesc"),selected: true, onselect:function(s) { if(s){changeDeploymentType("full")}}},
@@ -751,8 +751,8 @@ RED.deploy = (function() {
751751

752752
function updateThemeIcon(theme) {
753753
const toggleIcon = $('#red-ui-header-button-theme-toggle i');
754-
toggleIcon.removeClass('fa-moon-o fa-sun-o');
755-
toggleIcon.addClass(theme === 'dark' ? 'fa-sun-o' : 'fa-moon-o');
754+
toggleIcon.removeClass('fa-moon fa-sun');
755+
toggleIcon.addClass(theme === 'dark' ? 'fa-sun' : 'fa-moon');
756756
}
757757

758758
function toggleTheme() {

packages/node_modules/@node-red/editor-client/src/js/ui/userSettings.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,11 @@ RED.userSettings = (function() {
123123
setting:"nodeRedTheme",
124124
local: true,
125125
label:"Theme",
126+
default: 'dark',
126127
options:function(done){
127128
done([
128-
{val:'light',text:'Light'},
129-
{val:'dark',text:'Dark'},
129+
{val:'light',text:'Light theme'},
130+
{val:'dark',text:'Dark theme'},
130131
{val:'auto',text:'Automatic (follow system)'}
131132
])
132133
},
@@ -199,6 +200,9 @@ RED.userSettings = (function() {
199200
var initialState;
200201
if (opt.local) {
201202
initialState = localStorage.getItem(opt.setting);
203+
if (initialState === null && opt.hasOwnProperty('default')) {
204+
initialState = opt.default;
205+
}
202206
} else if (opt.global) {
203207
initialState = RED.settings.get(opt.setting);
204208
} else {
@@ -246,6 +250,14 @@ RED.userSettings = (function() {
246250
var opt = allSettings[id];
247251
if (opt.local) {
248252
localStorage.setItem(opt.setting,value);
253+
// Call onchange callback for local settings too
254+
var callback = opt.onchange;
255+
if (typeof callback === 'string') {
256+
callback = RED.actions.get(callback);
257+
}
258+
if (callback) {
259+
callback.call(opt,value);
260+
}
249261
} else if (opt.global) {
250262
RED.settings.set(opt.setting, value)
251263
} else {

0 commit comments

Comments
 (0)