From 01e6526d04034626844d20898c41a8179693b95e Mon Sep 17 00:00:00 2001 From: Jan Malakhovski Date: Tue, 5 Nov 2024 13:00:00 +0000 Subject: [PATCH] extension/*: subscribeToExtension: process all updates, use more specific `isSafe` functions This fixes some potential state display inconsistency bugs and improves UI pages' init performance when the core is very busy. Also, with this the logic inside `processUpdate` functions in the future patches becomes way too complex. --- extension/lib/lutils.js | 6 ------ extension/lib/utils.js | 2 -- extension/page/popup.js | 5 ++++- extension/page/saved.js | 2 +- extension/page/state.js | 5 ++++- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/extension/lib/lutils.js b/extension/lib/lutils.js index 848f10c..29702cb 100644 --- a/extension/lib/lutils.js +++ b/extension/lib/lutils.js @@ -78,12 +78,6 @@ function showSaved(suffix, ...args) { return showInternalPageAtNode("/page/saved.html" + suffix, ...args); } -// a filter for core events that can be ignored without causing inconsistencies -function thisIsFine(event) { - // it usually isn't, isn't it? - return false; -} - function setPageLoading() { document.getElementById("body_loading").innerHTML = "

Loading...

"; } diff --git a/extension/lib/utils.js b/extension/lib/utils.js index 145aa59..8dc5548 100644 --- a/extension/lib/utils.js +++ b/extension/lib/utils.js @@ -864,8 +864,6 @@ function subscribeToExtension(processUpdate, reinit, isSafe, markLoading, markSe } function processUpdateSmartly(event) { shouldReset = shouldReset || !isSafe(event); - if (shouldReset) - return; // apparently, this event can be processed synchronously processUpdateSync(event); } diff --git a/extension/page/popup.js b/extension/page/popup.js index 37119cb..a7b6c55 100644 --- a/extension/page/popup.js +++ b/extension/page/popup.js @@ -405,7 +405,10 @@ async function popupMain() { await updateTabConfig(); await updateTabStats(); } - }), thisIsFine, setPageLoading, setPageSettling); + }), (event) => { + let cmd = event[0]; + return !cmd.startsWith("update"); + }, setPageLoading, setPageSettling); // show UI setPageLoaded(); diff --git a/extension/page/saved.js b/extension/page/saved.js index 88e50cb..1fc03b1 100644 --- a/extension/page/saved.js +++ b/extension/page/saved.js @@ -67,7 +67,7 @@ async function stateMain() { await subscribeToExtension(catchAll(processUpdate), catchAll(async (willReset) => { await updateConfig(); - }), thisIsFine, setPageLoading, setPageSettling); + }), () => true, setPageLoading, setPageSettling); let rrfilters = await browser.runtime.sendMessage(["getSavedFilters"]); await browser.runtime.sendMessage(["setSavedFilters", rrfilters]); diff --git a/extension/page/state.js b/extension/page/state.js index 22a7c0d..934f082 100644 --- a/extension/page/state.js +++ b/extension/page/state.js @@ -159,7 +159,10 @@ async function stateMain() { resetLog(log); resetQueued(queuedLog); resetUnarchived(unarchivedLog); - }), thisIsFine, setPageLoading, setPageSettling); + }), (event) => { + let cmd = event[0]; + return !(cmd.startsWith("reset") || cmd.startsWith("new")); + }, setPageLoading, setPageSettling); // show UI setPageLoaded();