From e94c7edb38c218d87c11f18c81e9f2446f564359 Mon Sep 17 00:00:00 2001 From: Rob Garrison Date: Wed, 25 Apr 2018 17:09:45 -0500 Subject: [PATCH] Attempt to fix popup exclusion issues --- background/storage.js | 12 ++++++------ js/exclusions.js | 4 ++-- js/messaging.js | 2 +- popup/popup-exclusions.js | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/background/storage.js b/background/storage.js index b0f6c12d..bb925c7f 100644 --- a/background/storage.js +++ b/background/storage.js @@ -388,7 +388,7 @@ function saveStyle(style) { } codeIsUpdated = !existed || 'sections' in style && !styleSectionsEqual(style, oldStyle) - || reason === 'exclusionsUpdate'; + || reason === 'exclusionsUpdated'; style = Object.assign({installDate: Date.now()}, oldStyle, style); return write(style, store); }); @@ -427,7 +427,7 @@ function saveStyle(style) { style.id = style.id || event.target.result; invalidateCache(existed ? {updated: style} : {added: style}); if (notify) { - const method = reason === 'exclusionsUpdate' ? reason : + const method = reason === 'exclusionsUpdated' ? reason : existed ? 'styleUpdated' : 'styleAdded'; notifyAllTabs({method, style, codeIsUpdated, reason}); } @@ -457,12 +457,12 @@ function compileExclusionRegexps(exclusions) { } function isPageExcluded(matchUrl, exclusions = {}) { - const values = Object.values(exclusions); - if (!values.length) { + const keys = Object.keys(exclusions); + if (!keys.length) { return false; } - compileExclusionRegexps(values); - return values.some(exclude => { + compileExclusionRegexps(keys); + return keys.some(exclude => { const rx = cachedStyles.exclusions.get(exclude); return rx && rx.test(matchUrl); }); diff --git a/js/exclusions.js b/js/exclusions.js index dde8ddac..5fa9674c 100644 --- a/js/exclusions.js +++ b/js/exclusions.js @@ -135,7 +135,7 @@ const exclusions = (() => { } function onRuntimeMessage(msg) { - if (msg.method === 'exclusionsUpdate' && msg.style && msg.style.exclusions) { + if (msg.method === 'exclusionsUpdated' && msg.style && msg.style.exclusions) { update({list: Object.keys(msg.style.exclusions), isUpdating: true}); // update popup, if loaded if (typeof popupExclusions !== 'undefined') { @@ -156,7 +156,7 @@ const exclusions = (() => { // get last saved version API.getStyles({id: id || exclusions.id}).then(([style]) => { style.exclusions = exclusionList; - style.reason = 'exclusionsUpdate'; + style.reason = 'exclusionsUpdated'; API.saveStyle(style); }); } diff --git a/js/messaging.js b/js/messaging.js index dcbc1dd7..3023ad7b 100644 --- a/js/messaging.js +++ b/js/messaging.js @@ -161,7 +161,7 @@ var API = (() => { function notifyAllTabs(msg) { const originalMessage = msg; - const styleUpdated = msg.method === 'styleUpdated'; + const styleUpdated = msg.method === 'styleUpdated' || msg.method === 'exclusionsUpdated'; if (styleUpdated || msg.method === 'styleAdded') { // apply/popup/manage use only meta for these two methods, // editor may need the full code but can fetch it directly, diff --git a/popup/popup-exclusions.js b/popup/popup-exclusions.js index bfa56483..08d36c71 100644 --- a/popup/popup-exclusions.js +++ b/popup/popup-exclusions.js @@ -156,11 +156,11 @@ const popupExclusions = (() => { className: 'lights-on', onComplete: () => (box.dataset.display = false), }); + document.body.style.height = ''; if (ok) { handlePopupSave(style); entry.styleMeta = style; entry.classList.toggle('excluded', isExcluded(tabURL, style.exclusions)); - document.body.style.height = ''; } } return Promise.resolve();