diff --git a/src/background/index.js b/src/background/index.js index f257e53..3e3e42b 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -170,6 +170,10 @@ function initTabState(sender) { } } +const getTabId = + async sender => sender?.tab?.id + || (await Browser.getActiveTab()).id + browser.runtime.onMessage.addListener(async (data, sender) => { console.log("background message", data, sender) @@ -211,13 +215,15 @@ browser.runtime.onMessage.addListener(async (data, sender) => { } if (data.type === 'use_in_statement') { - await browser.runtime.sendMessage({ + const message = { type: 'use_in_statement', dataype: data.dataype, value: data.value ? data.value : null, wdEntityId: data.entityId ? data.entityId : null, reference: data.reference ? data.reference : null, - }) + } + await browser.runtime.sendMessage(message) + await browser.tabs.sendMessage(await getTabId(sender), message) } diff --git a/src/background/push-enitiy-to-sidebar.js b/src/background/push-enitiy-to-sidebar.js index c85bdcf..9a02b3e 100644 --- a/src/background/push-enitiy-to-sidebar.js +++ b/src/background/push-enitiy-to-sidebar.js @@ -2,15 +2,20 @@ import browser from 'webextension-polyfill' import {getInternalUrlForEntity} from "../core/navigation" import {setSidebarUrl} from "./navigation" -function pushEnitiyToSidebar(id, tid, setPanel = true, nocache = false) { +async function pushEnitiyToSidebar(id, tid, setPanel = true, nocache = false) { if (!sidebarLocked && setPanel) { - return setSidebarUrl(tid, getInternalUrlForEntity(id, nocache)) + await setSidebarUrl(tid, getInternalUrlForEntity(id, nocache)) } else { - return browser.runtime.sendMessage({ + console.log("pushing entity_add to", tid) + await browser.tabs.sendMessage(tid, { + type: 'entity_add', + id: id, + }) + await browser.runtime.sendMessage({ type: 'entity_add', id: id, - }); - } + }) + } } export { pushEnitiyToSidebar } diff --git a/src/sidebar/add.js b/src/sidebar/add.js index 3a4414c..5af8c0e 100644 --- a/src/sidebar/add.js +++ b/src/sidebar/add.js @@ -60,7 +60,9 @@ content.innerHTML = ''; ]); let entities = await wikidataGetEntity(currentEntity); let e = entities[currentEntity]; - let currentTab = await getCurrentTab(); + // todo run-context incompatibility + // let currentTab = await getCurrentTab(); + let currentTab = null let description = getValueByLang(e, 'descriptions', false); let hasDescription = description != false; @@ -108,6 +110,7 @@ content.innerHTML = ''; }; browser.runtime.onMessage.addListener(async (data, sender) => { + console.log("add-content event", data) if (data.type === 'entity_add') { clearBouncer(); if (!receivedEntities.includes(data.id)) { diff --git a/src/update-status.js b/src/update-status.js index 20f9b0a..1e54581 100644 --- a/src/update-status.js +++ b/src/update-status.js @@ -1,10 +1,13 @@ import browser from 'webextension-polyfill' +import {Browser} from "./core/browser" -function updateStatus(parts) { - browser.runtime.sendMessage({ - type: 'status', - message: parts, - }); +async function updateStatus(parts) { + const message = { + type: 'status', + message: parts, + } + await browser.runtime.sendMessage(message) + await Browser.sendMessageToActiveTab(message) } function updateStatusInternal(parts) {