From 0f3cef7762fa299bdd19e12d02dd8e4c8aacfb90 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 20 Aug 2019 14:41:54 -0400 Subject: [PATCH] is popover open check from safari app --- src/safari/app/desktop/safari/SafariExtensionHandler.swift | 5 +++++ .../app/desktop/safari/SafariExtensionViewController.swift | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/safari/app/desktop/safari/SafariExtensionHandler.swift b/src/safari/app/desktop/safari/SafariExtensionHandler.swift index d578da4a25..ac5e2bf7e5 100644 --- a/src/safari/app/desktop/safari/SafariExtensionHandler.swift +++ b/src/safari/app/desktop/safari/SafariExtensionHandler.swift @@ -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 diff --git a/src/safari/app/desktop/safari/SafariExtensionViewController.swift b/src/safari/app/desktop/safari/SafariExtensionViewController.swift index 847484ae0a..96103bcbed 100644 --- a/src/safari/app/desktop/safari/SafariExtensionViewController.swift +++ b/src/safari/app/desktop/safari/SafariExtensionViewController.swift @@ -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()