diff --git a/background/style-manager.js b/background/style-manager.js index 316e43c2..13355b83 100644 --- a/background/style-manager.js +++ b/background/style-manager.js @@ -281,7 +281,7 @@ const styleManager = (() => { // FIXME: do we want to cache this? Who would like to open popup rapidly // or search the DB with the same URL? const result = []; - const datas = !id ? styles.values.map(s => s.data) : + const datas = !id ? [...styles.values()].map(s => s.data) : styles.has(id) ? [styles.get(id).data] : []; for (const data of datas) { let excluded = false; diff --git a/popup/popup.js b/popup/popup.js index 74228730..99877b42 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -53,7 +53,7 @@ function onRuntimeMessage(msg) { case 'styleUpdated': case 'exclusionsUpdated': if (msg.reason === 'editPreview' || msg.reason === 'editPreviewEnd') return; - handleUpdate(msg.style); + handleUpdate(msg); break; case 'styleDeleted': handleDelete(msg.style.id); @@ -499,20 +499,31 @@ Object.assign(handleEvent, { }); -function handleUpdate(style) { - if ($(ENTRY_ID_PREFIX + style.id)) { - createStyleElement({style, check: true}); - return; - } +function handleUpdate({style, reason}) { if (!tabURL) return; - // Add an entry when a new style for the current url is installed - API.getStylesByUrl(tabURL, style.id).then(([style]) => { - if (style) { + + fetchStyle() + .then(style => { + if (!style) { + return; + } + if ($(ENTRY_ID_PREFIX + style.id)) { + createStyleElement({style}); + return; + } document.body.classList.remove('blocked'); $$.remove('.blocked-info, #no-styles'); - createStyleElement({style, check: true}); + createStyleElement({style}); + }) + .catch(console.error); + + function fetchStyle() { + if (reason === 'toggle' && $(ENTRY_ID_PREFIX + style.id)) { + return Promise.resolve(style); } - }); + return API.getStylesByUrl(tabURL, style.id) + .then(([style]) => style); + } }