1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-07 09:31:31 +01:00

is popover open check from safari app

This commit is contained in:
Kyle Spearrin 2019-08-20 14:41:54 -04:00
parent 5c47b33967
commit 0f3cef7762
2 changed files with 7 additions and 1 deletions

View File

@ -43,11 +43,16 @@ class SafariExtensionHandler: SFSafariExtensionHandler {
}
override func popoverWillShow(in _: SFSafariWindow) {
SafariExtensionViewController.shared.popoverOpenCount += 1
DispatchQueue.main.async {
self.sendMessage(msg: ["command": "reloadPopup"], sender: nil)
}
}
override func popoverDidClose(in _: SFSafariWindow) {
SafariExtensionViewController.shared.popoverOpenCount -= 1
}
func sendMessage(msg: [String: Any]?, sender: Tab? = nil) {
if SafariExtensionViewController.shared.webView == nil {
return

View File

@ -12,6 +12,7 @@ import WebKit
class SafariExtensionViewController: SFSafariExtensionViewController, WKScriptMessageHandler, WKNavigationDelegate {
var webView: WKWebView!
var initedWebView: Bool = false
var popoverOpenCount: Int = 0
static let shared: SafariExtensionViewController = {
let shared = SafariExtensionViewController()
@ -148,7 +149,7 @@ class SafariExtensionViewController: SFSafariExtensionViewController, WKScriptMe
})
}
} else if command == "isPopoverOpen" {
m!.responseData = "true";
m!.responseData = popoverOpenCount > 0 ? "true" : "false";
replyMessage(message: m!)
} else if command == "reloadExtension" {
webView?.reload()