Don't notify normal tabs if style contents hasn't changed
This commit is contained in:
parent
e807d41eb7
commit
913df00f35
13
messaging.js
13
messaging.js
|
@ -1,12 +1,15 @@
|
||||||
// keep message channel open for sendResponse in chrome.runtime.onMessage listener
|
// keep message channel open for sendResponse in chrome.runtime.onMessage listener
|
||||||
const KEEP_CHANNEL_OPEN = true;
|
const KEEP_CHANNEL_OPEN = true;
|
||||||
|
const OWN_ORIGIN = chrome.runtime.getURL('');
|
||||||
|
|
||||||
function notifyAllTabs(request) {
|
function notifyAllTabs(request) {
|
||||||
chrome.windows.getAll({populate: true}, function(windows) {
|
chrome.windows.getAll({populate: true}, windows => {
|
||||||
windows.forEach(function(win) {
|
windows.forEach(win => {
|
||||||
win.tabs.forEach(function(tab) {
|
win.tabs.forEach(tab => {
|
||||||
chrome.tabs.sendMessage(tab.id, request);
|
if (request.codeIsUpdated !== false || tab.url.startsWith(OWN_ORIGIN)) {
|
||||||
updateIcon(tab);
|
chrome.tabs.sendMessage(tab.id, request);
|
||||||
|
updateIcon(tab);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -105,11 +105,13 @@ function saveStyle(style, {notify = true} = {}) {
|
||||||
if (style.id) {
|
if (style.id) {
|
||||||
style.id = Number(style.id);
|
style.id = Number(style.id);
|
||||||
os.get(style.id).onsuccess = eventGet => {
|
os.get(style.id).onsuccess = eventGet => {
|
||||||
style = Object.assign({}, eventGet.target.result, style);
|
const oldStyle = Object.assign({}, eventGet.target.result);
|
||||||
|
const codeIsUpdated = !styleSectionsEqual(style, oldStyle);
|
||||||
|
style = Object.assign(oldStyle, style);
|
||||||
os.put(style).onsuccess = eventPut => {
|
os.put(style).onsuccess = eventPut => {
|
||||||
style.id = style.id || eventPut.target.result;
|
style.id = style.id || eventPut.target.result;
|
||||||
if (notify) {
|
if (notify) {
|
||||||
notifyAllTabs({method: 'styleUpdated', style});
|
notifyAllTabs({method: 'styleUpdated', style, codeIsUpdated});
|
||||||
}
|
}
|
||||||
invalidateCache(notify);
|
invalidateCache(notify);
|
||||||
resolve(style);
|
resolve(style);
|
||||||
|
@ -576,6 +578,9 @@ function getSync() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function styleSectionsEqual(styleA, styleB) {
|
function styleSectionsEqual(styleA, styleB) {
|
||||||
|
if (!styleA.sections || !styleB.sections) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
if (styleA.sections.length != styleB.sections.length) {
|
if (styleA.sections.length != styleB.sections.length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user