Skip to content

Commit

Permalink
Handle when the event listener for storage changes triggers even if t…
Browse files Browse the repository at this point in the history
…here are no actual changes
  • Loading branch information
david-tejada committed Apr 25, 2023
1 parent 6ec4475 commit 9b92387
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/content/settings/watchSettingsChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, browser.Storage.StorageChange>
) {
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) =>
Expand Down

0 comments on commit 9b92387

Please sign in to comment.