isPopoverOpen for safari app

This commit is contained in:
Kyle Spearrin 2019-08-20 13:54:10 -04:00
parent deb5d2bf62
commit 7d2c4cbd9a
3 changed files with 14 additions and 11 deletions

View File

@ -168,14 +168,14 @@ export class BrowserApi {
}
}
static isPopupOpen(): boolean {
static async isPopupOpen(): Promise<boolean> {
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);
}
}

View File

@ -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!)

View File

@ -89,23 +89,23 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
return this.analyticsIdCache;
}
isViewOpen(): Promise<boolean> {
if (BrowserApi.isPopupOpen()) {
return Promise.resolve(true);
async isViewOpen(): Promise<boolean> {
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 {