Skip to content

Commit 6f15a5d

Browse files
committed
update background storage when saveShowcase
1 parent 92993c0 commit 6f15a5d

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/background.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,25 @@ browser.tabs.onUpdated.addListener(handleUpdated)
88
browser.runtime.onMessage.addListener(
99
async function (message, sender, sendResponse) {
1010
if (message.action === 'analyze') {
11+
// when sending message from popup.js there's no sender.tab, so need to pass tabId
12+
const tabId = (sender.tab && sender.tab.id) || message.payload.tabId
1113
browser.browserAction.setIcon({
12-
tabId: sender.tab.id,
14+
tabId: tabId,
1315
path: message.payload.hasVue ? 'icons/icon-128.png' : 'icons/icon-grey-128.png'
1416
})
1517

16-
if (!tabsStorage[sender.tab.id]) {
17-
tabsStorage[sender.tab.id] = message.payload
18+
if (!tabsStorage[tabId]) {
19+
tabsStorage[tabId] = message.payload
1820
} else {
1921
// temporary fix when hit CSP
2022
if (!message.payload.modules.length) delete message.payload.modules
2123
if (!message.payload.plugins.length) delete message.payload.plugins
2224

23-
tabsStorage[sender.tab.id] = { ...tabsStorage[sender.tab.id], ...message.payload }
25+
tabsStorage[tabId] = { ...tabsStorage[tabId], ...message.payload }
2426
}
2527

26-
const showcase = tabsStorage[sender.tab.id]
27-
if (showcase.hasVue && !showcase.slug) {
28+
const showcase = tabsStorage[tabId]
29+
if (showcase.hasVue) {
2830
try {
2931
const res = await fetch(`https://vuetelemetry.com/api/analyze?url=${message.payload.url}`, {
3032
method: 'GET'
@@ -47,7 +49,7 @@ browser.runtime.onMessage.addListener(
4749
}
4850
} catch (err) {}
4951
}
50-
// tabsStorage[sender.tab.id] = message.payload
52+
// tabsStorage[tabId] = message.payload
5153
} else if (!sender.tab) {
5254
if (message.action === 'getShowcase') {
5355
// this is likely popup requesting

src/popup/App.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,15 @@ export default {
309309
this.showcase.isPublic = body.isPublic
310310
this.saving = false
311311
})
312+
const tabId = this.currentTab.id
313+
await this.sendToBackground({
314+
from: 'popup',
315+
action: 'analyze',
316+
payload: {
317+
tabId,
318+
...this.showcase // TODO: ugly stuff, make separate handler in background for refreshing backend analyzer data later
319+
}
320+
})
312321
} catch (err) {
313322
this.saving = false
314323
this.savingError = true

0 commit comments

Comments
 (0)