From 9b92387cfe948dbd78b58a9aad5f4dfe69607ac7 Mon Sep 17 00:00:00 2001 From: David Tejada Date: Tue, 25 Apr 2023 14:59:28 +0200 Subject: [PATCH] Handle when the event listener for storage changes triggers even if there are no actual changes --- src/content/settings/watchSettingsChanges.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/content/settings/watchSettingsChanges.ts b/src/content/settings/watchSettingsChanges.ts index 7a4b6ded..29165ac5 100644 --- a/src/content/settings/watchSettingsChanges.ts +++ b/src/content/settings/watchSettingsChanges.ts @@ -11,7 +11,20 @@ import { notify, notifyTogglesStatus } from "../notify/notify"; import { addUrlToTitle } from "../utils/addUrlToTitle"; import { cacheSettings, getCachedSetting } from "./cacheSettings"; -async function handleSettingsChanges(changes: browser.Storage.StorageChange) { +async function handleSettingsChanges( + changes: Record +) { + let hasActuallyChanged = false; + + for (const key of Object.keys(changes)) { + const change = changes[key]; + if (change && change.oldValue !== change.newValue) { + hasActuallyChanged = true; + } + } + + if (!hasActuallyChanged) return; + await cacheSettings(); const isToggleChange = Object.keys(changes).some((key) =>