Skip to content

Commit 99e691d

Browse files
fix: Use browser.storage.local.onChanged.addListener (#1755)
1 parent 4cefae7 commit 99e691d

File tree

20 files changed

+34
-48
lines changed

20 files changed

+34
-48
lines changed

docs/Chapter 4.2 - Feature modules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The cleanup function of the feature. Called whenever the user disables the featu
1818
- Type: Async Function
1919
- Required: No
2020

21-
The preference-handling code of the feature. Added as a `browser.storage.onChanged` listener when the feature is enabled, and removed when the feature is disabled. If the module does not export this function, the feature will be automatically restarted when its preferences are changed.
21+
The preference-handling code of the feature. Added as a `browser.storage.local.onChanged` listener when the feature is enabled, and removed when the feature is disabled. If the module does not export this function, the feature will be automatically restarted when its preferences are changed.
2222

2323
## `stylesheet`
2424
- Type: Boolean

src/action/render_backup.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,7 @@ const localRestore = async function () {
7878

7979
const renderLocalBackup = async function () {
8080
updateLocalExportDisplay();
81-
browser.storage.onChanged.addListener((changes, areaName) => {
82-
if (areaName === 'local') {
83-
updateLocalExportDisplay();
84-
}
85-
});
81+
browser.storage.local.onChanged.addListener(updateLocalExportDisplay);
8682

8783
localCopyButton.addEventListener('click', localCopy);
8884
localDownloadButton.addEventListener('click', localExport);

src/content_scripts/main.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,19 @@
3636
document.documentElement.append(styleElement);
3737
}
3838

39-
restartListeners[name] = async (changes, areaName) => {
40-
if (areaName !== 'local') return;
41-
39+
restartListeners[name] = async (changes) => {
4240
const { [enabledFeaturesKey]: enabledFeatures } = changes;
4341
if (enabledFeatures && !enabledFeatures.newValue.includes(name)) return;
4442

4543
if (onStorageChanged instanceof Function) {
46-
onStorageChanged(changes, areaName);
44+
onStorageChanged(changes);
4745
} else if (Object.keys(changes).some(key => key.startsWith(`${name}.preferences`) && changes[key].oldValue !== undefined)) {
4846
await clean?.();
4947
await main?.();
5048
}
5149
};
5250

53-
browser.storage.onChanged.addListener(restartListeners[name]);
51+
browser.storage.local.onChanged.addListener(restartListeners[name]);
5452
};
5553

5654
const destroyFeature = async function (name) {
@@ -70,15 +68,11 @@
7068
styleElement.remove();
7169
}
7270

73-
browser.storage.onChanged.removeListener(restartListeners[name]);
71+
browser.storage.local.onChanged.removeListener(restartListeners[name]);
7472
delete restartListeners[name];
7573
};
7674

77-
const onStorageChanged = async function (changes, areaName) {
78-
if (areaName !== 'local') {
79-
return;
80-
}
81-
75+
const onStorageChanged = async function (changes) {
8276
const { [enabledFeaturesKey]: enabledFeatures } = changes;
8377

8478
if (enabledFeatures) {
@@ -114,7 +108,7 @@
114108
const init = async function () {
115109
$('style.xkit, link.xkit').remove();
116110

117-
browser.storage.onChanged.addListener(onStorageChanged);
111+
browser.storage.local.onChanged.addListener(onStorageChanged);
118112

119113
const [
120114
installedFeatures,

src/features/accesskit/disable_gifs.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,7 @@ const processRows = function (rowsElements) {
186186
const processHoverableElements = elements =>
187187
elements.forEach(element => element.setAttribute(hoverContainerAttribute, ''));
188188

189-
const onStorageChanged = async function (changes, areaName) {
190-
if (areaName !== 'local') return;
191-
189+
const onStorageChanged = async function (changes) {
192190
const { 'accesskit.preferences.disable_gifs_loading_mode': modeChanges } = changes;
193191
if (modeChanges?.oldValue === undefined) return;
194192

@@ -233,11 +231,11 @@ export const main = async function () {
233231
processRows
234232
);
235233

236-
browser.storage.onChanged.addListener(onStorageChanged);
234+
browser.storage.local.onChanged.addListener(onStorageChanged);
237235
};
238236

239237
export const clean = async function () {
240-
browser.storage.onChanged.removeListener(onStorageChanged);
238+
browser.storage.local.onChanged.removeListener(onStorageChanged);
241239

242240
pageModifications.unregister(processGifs);
243241
pageModifications.unregister(processBackgroundGifs);

src/features/accesskit/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const destroyOption = async function (name) {
2323
}
2424
};
2525

26-
export const onStorageChanged = async function (changes, areaName) {
26+
export const onStorageChanged = async function (changes) {
2727
if (Object.keys(changes).some(key => key.startsWith('accesskit') && changes[key].oldValue !== undefined)) {
2828
const preferences = await getPreferences('accesskit');
2929

src/features/accesskit/visible_alt_text.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ const processImages = function (imageElements) {
4949
}
5050
};
5151

52-
const onStorageChanged = async function (changes, areaName) {
53-
if (areaName !== 'local') return;
54-
52+
const onStorageChanged = async function (changes) {
5553
const { 'accesskit.preferences.visible_alt_text_mode': modeChanges } = changes;
5654
if (modeChanges?.oldValue === undefined) return;
5755

@@ -65,12 +63,12 @@ export const main = async function () {
6563
({ visible_alt_text_mode: mode } = await getPreferences('accesskit'));
6664

6765
pageModifications.register(`article ${imageBlockSelector} img[alt]`, processImages);
68-
browser.storage.onChanged.addListener(onStorageChanged);
66+
browser.storage.local.onChanged.addListener(onStorageChanged);
6967
};
7068

7169
export const clean = async function () {
7270
pageModifications.unregister(processImages);
73-
browser.storage.onChanged.removeListener(onStorageChanged);
71+
browser.storage.local.onChanged.removeListener(onStorageChanged);
7472

7573
$(`.${processedClass} figcaption`).remove();
7674
$(`.${processedClass}`).removeClass(processedClass);

src/features/no_recommended/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const destroyOption = async function (name) {
2323
}
2424
};
2525

26-
export const onStorageChanged = async function (changes, areaName) {
26+
export const onStorageChanged = async function (changes) {
2727
if (Object.keys(changes).some(key => key.startsWith('no_recommended') && changes[key].oldValue !== undefined)) {
2828
const preferences = await getPreferences('no_recommended');
2929

src/features/notificationblock/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const unblockPostFilter = async ({ id, rebloggedRootId }) => {
9999
return blockedPostTargetIDs.includes(rootId);
100100
};
101101

102-
export const onStorageChanged = (changes, areaName) => {
102+
export const onStorageChanged = (changes) => {
103103
if (Object.keys(changes).includes(storageKey)) {
104104
blockedPostTargetIDs = changes[storageKey].newValue;
105105
styleElement.textContent = buildCss();

src/features/panorama/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ const processPostImages = images => images.forEach(image => {
133133
}
134134
});
135135

136-
export const onStorageChanged = async (changes, areaName) =>
136+
export const onStorageChanged = async (changes) =>
137137
Object.keys(changes).some(key => key.startsWith('panorama')) && main();
138138

139139
export const main = async () => {

src/features/postblock/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const blockPost = async rootID => {
4949
browser.storage.local.set({ [storageKey]: blockedPostRootIDs });
5050
};
5151

52-
export const onStorageChanged = async function (changes, areaName) {
52+
export const onStorageChanged = async function (changes) {
5353
if (Object.keys(changes).includes(storageKey)) {
5454
({ newValue: blockedPostRootIDs = [] } = changes[storageKey]);
5555
pageModifications.trigger(processPosts);

0 commit comments

Comments
 (0)