diff --git a/src/browser/browserApi.ts b/src/browser/browserApi.ts index a502c2e4c8..9250cdfe5a 100644 --- a/src/browser/browserApi.ts +++ b/src/browser/browserApi.ts @@ -168,14 +168,14 @@ export class BrowserApi { } } - static isPopupOpen(): boolean { + static async isPopupOpen(): Promise { if (BrowserApi.isChromeApi) { - return chrome.extension.getViews({ type: 'popup' }).length > 0; + return Promise.resolve(chrome.extension.getViews({ type: 'popup' }).length > 0); } else if (BrowserApi.isSafariApi) { - // TODO - return true; + const open = await SafariApp.sendMessageToApp('isPopoverOpen'); + return open === 'true'; } else { - return null; + return Promise.resolve(false); } } diff --git a/src/safari/app/desktop/safari/SafariExtensionViewController.swift b/src/safari/app/desktop/safari/SafariExtensionViewController.swift index 3549916720..847484ae0a 100644 --- a/src/safari/app/desktop/safari/SafariExtensionViewController.swift +++ b/src/safari/app/desktop/safari/SafariExtensionViewController.swift @@ -147,6 +147,9 @@ class SafariExtensionViewController: SFSafariExtensionViewController, WKScriptMe self.replyMessage(message: m!) }) } + } else if command == "isPopoverOpen" { + m!.responseData = "true"; + replyMessage(message: m!) } else if command == "reloadExtension" { webView?.reload() replyMessage(message: m!) diff --git a/src/services/browserPlatformUtils.service.ts b/src/services/browserPlatformUtils.service.ts index 326fcfc469..dfbe665a65 100644 --- a/src/services/browserPlatformUtils.service.ts +++ b/src/services/browserPlatformUtils.service.ts @@ -89,23 +89,23 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService return this.analyticsIdCache; } - isViewOpen(): Promise { - if (BrowserApi.isPopupOpen()) { - return Promise.resolve(true); + async isViewOpen(): Promise { + if (await BrowserApi.isPopupOpen()) { + return true; } if (this.isSafari()) { - return Promise.resolve(false); + return false; } const sidebarView = this.sidebarViewName(); const sidebarOpen = sidebarView != null && chrome.extension.getViews({ type: sidebarView }).length > 0; if (sidebarOpen) { - return Promise.resolve(true); + return true; } const tabOpen = chrome.extension.getViews({ type: 'tab' }).length > 0; - return Promise.resolve(tabOpen); + return tabOpen; } lockTimeout(): number {