diff --git a/lib/infrastructure/rpc/browser_extension_aws.web.dart b/lib/infrastructure/rpc/browser_extension_aws.web.dart index 89abdc480..84d5b1a65 100644 --- a/lib/infrastructure/rpc/browser_extension_aws.web.dart +++ b/lib/infrastructure/rpc/browser_extension_aws.web.dart @@ -10,13 +10,6 @@ import 'package:stream_channel/stream_channel.dart'; class BrowserExtensionAWS { BrowserExtensionAWS() { print('[AWCBrowserExtension] Init'); - onMessage.addListener( - allowInterop((message, sender, sendResponse) { - if (message == 'isExtensionPopupReady') { - sendResponse(_isRunning); - } - }), - ); } static const logName = 'Browser RPC Server'; @@ -51,7 +44,7 @@ class BrowserExtensionAWS { onConnectExternal.addListener(allowInterop(_connectionReceived)); _isRunning = true; - sendMessage('extensionPopupReady'); + // sendMessage('extensionPopupReady'); }, (error, stack) { print( diff --git a/web_chrome_extension/src/background.ts b/web_chrome_extension/src/background.ts index 05f3e0f68..2b9b155be 100644 --- a/web_chrome_extension/src/background.ts +++ b/web_chrome_extension/src/background.ts @@ -1,8 +1,7 @@ -chrome.runtime.onMessageExternal.addListener((message, sender, sendResponse) => { - if (message === 'waitForExtensionPopup') { - waitForExtensionPopup().then(() => { - sendResponse() - }) +chrome.runtime.onMessageExternal.addListener(async (message, sender, sendResponse) => { + if (message === 'ensureExtensionPopupOpened') { + await ensureExtensionPopupOpened() + sendResponse() } }) @@ -33,33 +32,13 @@ async function openExtensionPopup(): Promise { }) } -async function extensionPopupExists(): Promise { +async function isExtensionPopupOpened(): Promise { return (await findExtensionWindowId()) !== null } -async function isExtensionPopupReady(): Promise { - if (await extensionPopupExists()) { - return await chrome.runtime.sendMessage('isExtensionPopupReady'); +async function ensureExtensionPopupOpened() { + if (await isExtensionPopupOpened()) { + return } - return false -} - -async function waitForExtensionPopup() { - return new Promise(async (resolve) => { - if (await isExtensionPopupReady()) { - resolve() - return - } - - const _extensionPopupReadyListener = (message: string) => { - if (message === 'extensionPopupReady') { - console.log('Extension popup ready') - chrome.runtime.onMessage.removeListener(_extensionPopupReadyListener) - resolve() - } - } - - chrome.runtime.onMessage.addListener(_extensionPopupReadyListener) - openExtensionPopup() - }) + await openExtensionPopup() }