limit broadcast area of prefChanged in notifyAllTabs
This commit is contained in:
parent
4d143a03dc
commit
fcb149ae21
27
messaging.js
27
messaging.js
|
@ -14,12 +14,23 @@ function notifyAllTabs(request) {
|
|||
style: getStyleWithNoCode(request.style)
|
||||
});
|
||||
}
|
||||
chrome.tabs.query({}, tabs => {
|
||||
for (const tab of tabs) {
|
||||
chrome.tabs.sendMessage(tab.id, request);
|
||||
updateIcon(tab);
|
||||
}
|
||||
});
|
||||
const affectsAll = !request.affects || request.affects.all;
|
||||
const affectsOwnOrigin = !affectsAll && (request.affects.editor || request.affects.manager);
|
||||
const affectsTabs = affectsAll || affectsOwnOrigin;
|
||||
const affectsIcon = affectsAll || request.affects.icon;
|
||||
const affectsPopup = affectsAll || request.affects.popup;
|
||||
if (affectsTabs || affectsIcon) {
|
||||
chrome.tabs.query(affectsOwnOrigin ? {url: OWN_ORIGIN + '*'} : {}, tabs => {
|
||||
for (const tab of tabs) {
|
||||
if (affectsTabs || tab.url.startsWith(OWN_ORIGIN + 'options')) {
|
||||
chrome.tabs.sendMessage(tab.id, request);
|
||||
}
|
||||
if (affectsIcon) {
|
||||
updateIcon(tab);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// notify self: the message no longer is sent to the origin in new Chrome
|
||||
if (window.applyOnMessage) {
|
||||
applyOnMessage(request);
|
||||
|
@ -27,7 +38,9 @@ function notifyAllTabs(request) {
|
|||
onBackgroundMessage(request);
|
||||
}
|
||||
// notify background page and all open popups
|
||||
chrome.runtime.sendMessage(request);
|
||||
if (affectsPopup) {
|
||||
chrome.runtime.sendMessage(request);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
18
storage.js
18
storage.js
|
@ -608,11 +608,27 @@ prefs = prefs || new function Prefs() {
|
|||
};
|
||||
const values = deepCopy(defaults);
|
||||
|
||||
const affectsIcon = [
|
||||
'show-badge',
|
||||
'disableAll',
|
||||
'badgeDisabled',
|
||||
'badgeNormal',
|
||||
];
|
||||
|
||||
// coalesce multiple pref changes in broadcast
|
||||
let broadcastPrefs = {};
|
||||
|
||||
function doBroadcast() {
|
||||
notifyAllTabs({method: 'prefChanged', prefs: broadcastPrefs});
|
||||
const affects = {all: 'disableAll' in broadcastPrefs};
|
||||
if (!affects.all) {
|
||||
for (const key in broadcastPrefs) {
|
||||
affects.icon = affects.icon || affectsIcon.includes(key);
|
||||
affects.popup = affects.popup || key.startsWith('popup');
|
||||
affects.editor = affects.editor || key.startsWith('editor');
|
||||
affects.manager = affects.manager || key.startsWith('manage');
|
||||
}
|
||||
}
|
||||
notifyAllTabs({method: 'prefChanged', prefs: broadcastPrefs, affects});
|
||||
broadcastPrefs = {};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user