Attempt to fix popup exclusion issues

This commit is contained in:
Rob Garrison 2018-04-25 17:09:45 -05:00
parent 2b4a1a5635
commit e94c7edb38
4 changed files with 10 additions and 10 deletions

View File

@ -388,7 +388,7 @@ function saveStyle(style) {
} }
codeIsUpdated = !existed codeIsUpdated = !existed
|| 'sections' in style && !styleSectionsEqual(style, oldStyle) || 'sections' in style && !styleSectionsEqual(style, oldStyle)
|| reason === 'exclusionsUpdate'; || reason === 'exclusionsUpdated';
style = Object.assign({installDate: Date.now()}, oldStyle, style); style = Object.assign({installDate: Date.now()}, oldStyle, style);
return write(style, store); return write(style, store);
}); });
@ -427,7 +427,7 @@ function saveStyle(style) {
style.id = style.id || event.target.result; style.id = style.id || event.target.result;
invalidateCache(existed ? {updated: style} : {added: style}); invalidateCache(existed ? {updated: style} : {added: style});
if (notify) { if (notify) {
const method = reason === 'exclusionsUpdate' ? reason : const method = reason === 'exclusionsUpdated' ? reason :
existed ? 'styleUpdated' : 'styleAdded'; existed ? 'styleUpdated' : 'styleAdded';
notifyAllTabs({method, style, codeIsUpdated, reason}); notifyAllTabs({method, style, codeIsUpdated, reason});
} }
@ -457,12 +457,12 @@ function compileExclusionRegexps(exclusions) {
} }
function isPageExcluded(matchUrl, exclusions = {}) { function isPageExcluded(matchUrl, exclusions = {}) {
const values = Object.values(exclusions); const keys = Object.keys(exclusions);
if (!values.length) { if (!keys.length) {
return false; return false;
} }
compileExclusionRegexps(values); compileExclusionRegexps(keys);
return values.some(exclude => { return keys.some(exclude => {
const rx = cachedStyles.exclusions.get(exclude); const rx = cachedStyles.exclusions.get(exclude);
return rx && rx.test(matchUrl); return rx && rx.test(matchUrl);
}); });

View File

@ -135,7 +135,7 @@ const exclusions = (() => {
} }
function onRuntimeMessage(msg) { 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({list: Object.keys(msg.style.exclusions), isUpdating: true});
// update popup, if loaded // update popup, if loaded
if (typeof popupExclusions !== 'undefined') { if (typeof popupExclusions !== 'undefined') {
@ -156,7 +156,7 @@ const exclusions = (() => {
// get last saved version // get last saved version
API.getStyles({id: id || exclusions.id}).then(([style]) => { API.getStyles({id: id || exclusions.id}).then(([style]) => {
style.exclusions = exclusionList; style.exclusions = exclusionList;
style.reason = 'exclusionsUpdate'; style.reason = 'exclusionsUpdated';
API.saveStyle(style); API.saveStyle(style);
}); });
} }

View File

@ -161,7 +161,7 @@ var API = (() => {
function notifyAllTabs(msg) { function notifyAllTabs(msg) {
const originalMessage = msg; const originalMessage = msg;
const styleUpdated = msg.method === 'styleUpdated'; const styleUpdated = msg.method === 'styleUpdated' || msg.method === 'exclusionsUpdated';
if (styleUpdated || msg.method === 'styleAdded') { if (styleUpdated || msg.method === 'styleAdded') {
// apply/popup/manage use only meta for these two methods, // apply/popup/manage use only meta for these two methods,
// editor may need the full code but can fetch it directly, // editor may need the full code but can fetch it directly,

View File

@ -156,11 +156,11 @@ const popupExclusions = (() => {
className: 'lights-on', className: 'lights-on',
onComplete: () => (box.dataset.display = false), onComplete: () => (box.dataset.display = false),
}); });
document.body.style.height = '';
if (ok) { if (ok) {
handlePopupSave(style); handlePopupSave(style);
entry.styleMeta = style; entry.styleMeta = style;
entry.classList.toggle('excluded', isExcluded(tabURL, style.exclusions)); entry.classList.toggle('excluded', isExcluded(tabURL, style.exclusions));
document.body.style.height = '';
} }
} }
return Promise.resolve(); return Promise.resolve();