From 451bcab01fd591ec54b63af0fc7084dc9f37928b Mon Sep 17 00:00:00 2001 From: Kuuuube <61125188+Kuuuube@users.noreply.github.com> Date: Tue, 18 Jun 2024 20:18:43 -0400 Subject: Add auto option to body theme (#1086) * Add auto option to body theme * Fix firefox bug where themes do not set correctly in settings due to getOptions failing --- ext/js/pages/settings/popup-preview-frame.js | 2 +- ext/js/pages/settings/settings-display-controller.js | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'ext/js/pages/settings') diff --git a/ext/js/pages/settings/popup-preview-frame.js b/ext/js/pages/settings/popup-preview-frame.js index 7abcfe2a..dc00d091 100644 --- a/ext/js/pages/settings/popup-preview-frame.js +++ b/ext/js/pages/settings/popup-preview-frame.js @@ -77,7 +77,6 @@ export class PopupPreviewFrame { async prepare() { window.addEventListener('message', this._onMessage.bind(this), false); - this._themeController.siteTheme = 'light'; this._themeController.prepare(); // Setup events @@ -141,6 +140,7 @@ export class PopupPreviewFrame { options.general.popupVerticalTextPosition = 'before'; options.scanning.selectText = false; this._themeController.theme = options.general.popupTheme; + this._themeController.siteOverride = true; this._themeController.updateTheme(); return options; } diff --git a/ext/js/pages/settings/settings-display-controller.js b/ext/js/pages/settings/settings-display-controller.js index 49f7192c..e179b835 100644 --- a/ext/js/pages/settings/settings-display-controller.js +++ b/ext/js/pages/settings/settings-display-controller.js @@ -42,11 +42,12 @@ export class SettingsDisplayController { this._onMenuButtonClickBind = this._onMenuButtonClick.bind(this); /** @type {ThemeController} */ this._themeController = new ThemeController(document.documentElement); + /** @type {HTMLSelectElement | null}*/ + this._themeDropdown = document.querySelector('[data-setting="general.popupTheme"]'); } /** */ prepare() { - this._themeController.siteTheme = 'light'; this._themeController.prepare(); void this._updateTheme(); @@ -92,16 +93,18 @@ export class SettingsDisplayController { window.addEventListener('popstate', this._onPopState.bind(this), false); this._updateScrollTarget(); - const themeDropdown = document.querySelector('[data-setting="general.popupTheme"]'); - if (themeDropdown) { - themeDropdown.addEventListener('change', this._updateTheme.bind(this), false); + if (this._themeDropdown) { + this._themeDropdown.addEventListener('change', this._updateTheme.bind(this), false); } } /** */ async _updateTheme() { - const options = await this._settingsController.getOptions(); - this._themeController.theme = options.general.popupTheme; + const theme = this._themeDropdown?.value; + if (theme === 'site' || theme === 'light' || theme === 'dark' || theme === 'browser') { + this._themeController.theme = theme; + } + this._themeController.siteOverride = true; this._themeController.updateTheme(); } -- cgit v1.2.3