Skip to content

Commit

Permalink
[WFX-346] Add toggle to force light/dark mode in dynamic themes.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamp01 authored and MrAlex94 committed Mar 7, 2022
1 parent 25faee1 commit 3b9d71a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
33 changes: 33 additions & 0 deletions browser/components/preferences/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ Preferences.addAll([
{ id: "browser.tabs.insertAfterCurrent", type: "bool" },
{ id: "browser.tabs.insertRelatedAfterCurrent", type: "bool" },

// Dark Theme
{ id: "ui.systemUsesDarkTheme", type: "int" },

// Restart Menu Item
{ id: "browser.restart_menu.purgecache", type: "bool" },
{ id: "browser.restart_menu.requireconfirm", type: "bool" },
Expand Down Expand Up @@ -735,6 +738,13 @@ var gMainPane = {
}
}

// WATERFOX
// Select the correct radio button based on current pref value
this.setDynamicThemeGroupValue();
setEventListener("dynamicThemeGroup", "command", event => {
this.updateDynamicThemePref(event.target.value);
});

// Initilize Application section.

// Observe preferences that influence what we display so we can rebuild
Expand Down Expand Up @@ -2003,6 +2013,29 @@ var gMainPane = {
}
},

async setDynamicThemeGroupValue() {
let radiogroup = document.getElementById("dynamicThemeRadioGroup");
radiogroup.disabled = true;

radiogroup.value = Services.prefs.getIntPref("ui.systemUsesDarkTheme", -1);

radiogroup.disabled = false;
},

async updateDynamicThemePref(value) {
switch (value) {
case "1":
Services.prefs.setIntPref("ui.systemUsesDarkTheme", 1);
break;
case "0":
Services.prefs.setIntPref("ui.systemUsesDarkTheme", 0);
break;
case "-1":
Services.prefs.clearUserPref("ui.systemUsesDarkTheme");
break;
}
},

/**
* Displays the history of installed updates.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
<!-- Dynamic Theme preferences -->
<groupbox id="dynamicThemeGroup" data-category="paneGeneral" hidden="true">
<label>
<html:h2 data-l10n-id="dynamic-theme-header" />
</label>
<radiogroup id="dynamicThemeRadioGroup">
<radio value="1"
data-l10n-id="dynamic-theme-dark"/>
<radio value="0"
data-l10n-id="dynamic-theme-light"/>
<radio value="-1"
data-l10n-id="dynamic-theme-auto"/>
</radiogroup>
</groupbox>

<!-- Restart Menu Item preferences -->
<groupbox id="restartGroup" data-category="paneGeneral" hidden="true">
<label>
Expand Down
7 changes: 7 additions & 0 deletions browser/locales/en-US/browser/preferences/preferences.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,13 @@ insert-after-current =
.label = Insert new tab after current tab
insert-related-after-current =
.label = Insert related new tab after current tab
dynamic-theme-header = Dynamic Themes
dynamic-theme-dark =
.label = Force Dark Mode
dynamic-theme-light =
.label = Force Light Mode
dynamic-theme-auto =
.label = Dynamically Set Light/Dark Mode
restart-header = Restart Menu Item
restart-show-button =
.label = Show restart button in PanelUI
Expand Down

0 comments on commit 3b9d71a

Please sign in to comment.