From 9717e8155722e1d2bbb32a077af4e16a86554889 Mon Sep 17 00:00:00 2001 From: "Jeevanandam M." Date: Fri, 2 Aug 2024 13:39:46 -0700 Subject: [PATCH] fix: preserve the user selected locale value from the options ui #155 (#158) --- background.js | 5 +++++ modules/settings.mjs | 6 ++++++ options/options.js | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/background.js b/background.js index 7aeaa36..88c5b48 100644 --- a/background.js +++ b/background.js @@ -39,6 +39,11 @@ messenger.accounts.onDeleted.addListener(async function (id) { }); async function detectLocaleAndSetAsDefault() { + let userSelected = await rwhSettings.isHeaderLocaleUserSelected(); + if (userSelected) { + return; + } + let uiLocale = messenger.i18n.getUILanguage(); let selected = rwhI18n.i18n.lang[uiLocale]; let currentLocale = await rwhSettings.getHeaderLocale(); diff --git a/modules/settings.mjs b/modules/settings.mjs index 0e7c5aa..4be01a3 100755 --- a/modules/settings.mjs +++ b/modules/settings.mjs @@ -32,6 +32,7 @@ let keyHeaderDateFormat = 'header.date.format'; let keyHeaderTimeFormat = 'header.time.format'; let keyHeaderTimeZone = 'header.date.timezone'; let keyHeaderLocale = 'header.locale'; +let keyHeaderLocaleUserSelected = 'header.locale.user.selected'; let keyHeaderPlainPrefixText = 'header.plain.prefix.text'; let keyHeaderHtmlPrefixLine = 'header.html.prefix.line'; let keyHeaderHtmlPrefixLineColor = 'header.html.prefix.line.color'; @@ -45,6 +46,7 @@ let rwhDefaultSettings = { [keyHeaderLabelSeqStyle]: 1, [keyHeaderLocale]: 'en-US', + [keyHeaderLocaleUserSelected]: false, [keyHeaderPlainPrefixText]: true, [keyHeaderHtmlPrefixLine]: true, [keyHeaderHtmlPrefixLineColor]: '#B5C4DF', @@ -139,6 +141,10 @@ export async function getHeaderLocale() { return await get(keyHeaderLocale, rwhDefaultSettings[keyHeaderLocale]); } +export async function isHeaderLocaleUserSelected() { + return await get(keyHeaderLocaleUserSelected, rwhDefaultSettings[keyHeaderLocaleUserSelected]); +} + export async function isHeaderPlainPrefixText() { return await get(keyHeaderPlainPrefixText, rwhDefaultSettings[keyHeaderPlainPrefixText]); } diff --git a/options/options.js b/options/options.js index ce9cfc3..91fa0d7 100644 --- a/options/options.js +++ b/options/options.js @@ -125,6 +125,12 @@ async function savePref(prefElement) { case 'SELECT': case 'color': case 'text': + switch (name) { + case 'header.locale': + rwhSettings.set('header.locale.user.selected', true); + break; + } + rwhSettings.set(name, prefElement.value); break; }