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