Skip to content

Commit

Permalink
fix preferences handling for accounts/folders, fix race condition
Browse files Browse the repository at this point in the history
- checking enabled/disabled accounts was checking for .key instead of .id
- use folder.folderURL consistently (instead of folder.URI)
- building folder checkboxes did not wait for preferences being loaded
  • Loading branch information
ahubmann committed Aug 31, 2024
1 parent 68b8a44 commit 593079e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/chrome/content/threadvis.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export class ThreadVis {
}

if (Preferences.get(Preferences.DISABLED_FOLDERS) !== ""
&& Preferences.get(Preferences.DISABLED_FOLDERS).indexOf(" " + folder.URI + " ") > -1) {
&& Preferences.get(Preferences.DISABLED_FOLDERS).indexOf(" " + folder.folderURL + " ") > -1) {
return false;
}
return true;
Expand Down Expand Up @@ -745,7 +745,7 @@ export class ThreadVis {
if (folder) {
let folderSetting = Preferences.get(Preferences.DISABLED_FOLDERS);

folderSetting = folderSetting + " " + folder.URI + " ";
folderSetting = folderSetting + " " + folder.folderURL + " ";

Preferences.set(
Preferences.DISABLED_FOLDERS,
Expand All @@ -763,8 +763,8 @@ export class ThreadVis {
if (folder) {
let folderSetting = Preferences.get(Preferences.DISABLED_FOLDERS);

const index = folderSetting.indexOf(" " + folder.URI + " ");
folderSetting = folderSetting.substring(0, index) + folderSetting.substring(index + folder.URI.length + 2);
const index = folderSetting.indexOf(" " + folder.folderURL + " ");
folderSetting = folderSetting.substring(0, index) + folderSetting.substring(index + folder.folderURL.length + 2);

Preferences.set(
Preferences.DISABLED_FOLDERS,
Expand Down
25 changes: 16 additions & 9 deletions src/settings/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ const getAccounts = async () =>

const querySelector = (name, value) => `[name="${name}"]` + (value ? `[value="${value}"]` : "");

const prefDisabled = (pref, value) => pref !== "" && pref.indexOf(" " + value + " ") > -1;

const init = async () => {
[
await Promise.all([
{ key: PreferenceKeys.TIMESCALING, type: "bool"},
{ key: PreferenceKeys.TIMESCALING_METHOD, type: "string"},
{ key: PreferenceKeys.VIS_MESSAGE_CIRCLES, type: "bool"},
Expand All @@ -65,7 +67,7 @@ const init = async () => {
{ key: PreferenceKeys.STATUSBAR, type: "bool"},
{ key: PreferenceKeys.DISABLED_ACCOUNTS, type: "string"},
{ key: PreferenceKeys.DISABLED_FOLDERS, type: "string"}
].forEach((pref) => {
].map((pref) =>
getPref(pref.key).then((value) => {
const elems = document.querySelectorAll(querySelector(pref.key));
if (elems.length === 1) {
Expand Down Expand Up @@ -96,8 +98,8 @@ const init = async () => {
});
});
}
});
});
})
));

// build account list
await buildAccountList();
Expand All @@ -124,7 +126,8 @@ const buildAccountList = async () => {
box.disabled = ! this.checked;
});
});
if (pref !== "" && pref.indexOf(" " + account.key + " ") > -1) {
const accountDisabled = prefDisabled(pref, account.id);
if (accountDisabled) {
checkbox.checked = false;
} else {
checkbox.checked = true;
Expand Down Expand Up @@ -158,7 +161,7 @@ const buildAccountList = async () => {
hbox.appendChild(buttonNone);
accountBox.appendChild(hbox);

buildFolderCheckboxes(accountBox, account.folders, account.id, 1);
buildFolderCheckboxes(accountBox, account.folders, account.id, accountDisabled, 1);
});
};

Expand All @@ -168,9 +171,10 @@ const buildAccountList = async () => {
* @param {DOMElement} box - The box to which to add the checkbox elements to
* @param {Array} folders - All folders for which to create checkboxes
* @param {Account} account - The account for which the checkboxes are created
* @param {Boolean} disabled - The account is disabled, so disable all checkboxes
* @param {Number} indent - The amount of indentation
*/
const buildFolderCheckboxes = (box, folders, account, indent) => {
const buildFolderCheckboxes = (box, folders, account, disabled, indent) => {
const pref = document.getElementById("ThreadVisHiddenDisabledFolders").value;

folders.forEach((folder) => {
Expand All @@ -185,11 +189,14 @@ const buildFolderCheckboxes = (box, folders, account, indent) => {
buildFolderPreference();
});
div.style.paddingLeft = indent + "em";
if (pref !== "" && pref.indexOf(folder.url + " ") > -1) {
if (prefDisabled(pref, folder.url)) {
checkbox.checked = false;
} else {
checkbox.checked = true;
}
if (disabled) {
checkbox.disabled = true;
}
const label = document.createElement("label");
label.setAttribute("for", "ThreadVis-Account-" + account + "-Folder-" + folder.url);
label.textContent = folder.name;
Expand All @@ -199,7 +206,7 @@ const buildFolderCheckboxes = (box, folders, account, indent) => {

// descend into subfolders
if (folder.folders) {
buildFolderCheckboxes(box, folder.folders, account, indent + 1);
buildFolderCheckboxes(box, folder.folders, account, disabled, indent + 1);
}
});
};
Expand Down

0 comments on commit 593079e

Please sign in to comment.