diff --git a/src/domain/session/settings/SettingsViewModel.js b/src/domain/session/settings/SettingsViewModel.js index caaa2579..aae83fb6 100644 --- a/src/domain/session/settings/SettingsViewModel.js +++ b/src/domain/session/settings/SettingsViewModel.js @@ -51,6 +51,7 @@ export class SettingsViewModel extends ViewModel { this.maxSentImageSizeLimit = 4000; this.pushNotifications = new PushNotificationStatus(); this._activeTheme = undefined; + this._activeVariant = undefined; } get _session() { @@ -79,6 +80,7 @@ export class SettingsViewModel extends ViewModel { this.pushNotifications.enabled = await this._session.arePushNotificationsEnabled(); if (!import.meta.env.DEV) { this._activeTheme = await this.platform.themeLoader.getActiveTheme(); + this._activeVariant = await this.platform.themeLoader.getCurrentVariant(); } this.emitChange(""); } @@ -139,6 +141,10 @@ export class SettingsViewModel extends ViewModel { return this._activeTheme; } + get activeVariant() { + return this._activeVariant; + } + setTheme(name) { this.platform.themeLoader.setTheme(name); } @@ -195,5 +201,16 @@ export class SettingsViewModel extends ViewModel { this.emitChange("themeOption"); } + get preferredColorScheme() { + return this.platform.themeLoader.preferredColorScheme; + } + + persistVariantToStorage(variant) { + this.platform.themeLoader.persistVariantToStorage(variant); + } + + removeVariantFromStorage() { + this.platform.themeLoader.removeVariantFromStorage(); + } } diff --git a/src/platform/web/ui/session/settings/SettingsView.js b/src/platform/web/ui/session/settings/SettingsView.js index 14893aba..45178990 100644 --- a/src/platform/web/ui/session/settings/SettingsView.js +++ b/src/platform/web/ui/session/settings/SettingsView.js @@ -16,6 +16,7 @@ limitations under the License. import {TemplateView} from "../../general/TemplateView"; import {KeyBackupSettingsView} from "./KeyBackupSettingsView.js" +import {ColorSchemePreference} from "../../../ThemeLoader"; export class SettingsView extends TemplateView { render(t, vm) { @@ -142,38 +143,49 @@ export class SettingsView extends TemplateView { _themeOptions(t, vm) { const activeTheme = vm.activeTheme; const optionTags = []; - let isDarkSelected = null, isLightSelected = null; + const isDarkSelected = vm.activeVariant === "dark"; + const isLightSelected = vm.activeVariant === "light"; + // 1. render the dropdown containing the themes for (const [name, details] of Object.entries(vm.themeMapping)) { - let isSelected = null; - if (details.id === activeTheme) { - isSelected = true; - } - else if (details.dark?.id === activeTheme) { - isSelected = true; - isDarkSelected = true; - } - else if (details.light?.id === activeTheme) { - isSelected = true; - isLightSelected = true; - } + const isSelected = (details.id ?? details.dark?.id ?? details.light?.id) === activeTheme; optionTags.push( t.option({ value: details.id ?? "", selected: isSelected} , name)); } const select = t.select({ onChange: (e) => { const themeId = e.target.value; - vm.changeThemeOption(themeId) - } - }, optionTags); - const radioButtons = t.form({ - className: { hidden: () => select.options[select.selectedIndex].value !== "" }, - onChange: (e) => { - const selectedThemeName = select.options[select.selectedIndex].text; - const colorScheme = e.target.value; - const themeId = vm.themeMapping[selectedThemeName][colorScheme].id; + if (themeId) { + /* if the