diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-05-04 17:41:22 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-05-04 17:41:22 +0530 |
commit | cd9a34cbb5ca8fb1c61aeda50517de60cc829e29 (patch) | |
tree | 4034f5e9eddaee12ee526f55298dbddfc97c8be3 /src/webex/wxBackend.ts | |
parent | 42b6c58db80b78efd62140e0752881090498dcc1 (diff) | |
download | wallet-core-cd9a34cbb5ca8fb1c61aeda50517de60cc829e29.tar.xz |
make wallet notifications work again
Diffstat (limited to 'src/webex/wxBackend.ts')
-rw-r--r-- | src/webex/wxBackend.ts | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/webex/wxBackend.ts b/src/webex/wxBackend.ts index 7966bbe25..54dd35ac4 100644 --- a/src/webex/wxBackend.ts +++ b/src/webex/wxBackend.ts @@ -68,6 +68,8 @@ const extendedPermissions = { origins: ["http://*/*", "https://*/*"], }; +const notificationPorts: chrome.runtime.Port[] = []; + async function handleMessage( sender: MessageSender, type: MessageType, @@ -447,6 +449,15 @@ async function reinitWallet(): Promise<void> { http, new BrowserCryptoWorkerFactory(), ); + wallet.addNotificationListener((x) => { + for (const x of notificationPorts) { + try { + x.postMessage({ type: "notification" }); + } catch (e) { + console.error(e); + } + } + }); wallet.runRetryLoop().catch((e) => { console.log("error during wallet retry loop", e); }); @@ -620,8 +631,18 @@ export async function wxMain(): Promise<void> { return true; }); + chrome.runtime.onConnect.addListener((port) => { + notificationPorts.push(port); + port.onDisconnect.addListener((discoPort) => { + const idx = notificationPorts.indexOf(discoPort); + if (idx >= 0) { + notificationPorts.splice(idx, 1); + } + }); + }); + setupHeaderListener(); - + chrome.permissions.onAdded.addListener((perm) => { if (chrome.runtime.lastError) { console.error(chrome.runtime.lastError); |