Skip to content

Commit

Permalink
fix: preserve the user selected locale value from the options ui #155 (
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm authored Aug 2, 2024
1 parent 12fef41 commit 9717e81
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions modules/settings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -45,6 +46,7 @@ let rwhDefaultSettings = {
[keyHeaderLabelSeqStyle]: 1,

[keyHeaderLocale]: 'en-US',
[keyHeaderLocaleUserSelected]: false,
[keyHeaderPlainPrefixText]: true,
[keyHeaderHtmlPrefixLine]: true,
[keyHeaderHtmlPrefixLineColor]: '#B5C4DF',
Expand Down Expand Up @@ -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]);
}
Expand Down
6 changes: 6 additions & 0 deletions options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 9717e81

Please sign in to comment.