From f4e3c13551221f9e40f7d8fe0e4a151316e1add7 Mon Sep 17 00:00:00 2001 From: potatojoayo Date: Wed, 14 Feb 2024 22:08:26 +0900 Subject: [PATCH] fix: #389 [macOS] Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'dismissViewController:: Error: maybe this view controller was not presented?' --- .../macos/Classes/FacebookAuthDesktopPlugin.swift | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/facebook_auth_desktop/macos/Classes/FacebookAuthDesktopPlugin.swift b/facebook_auth_desktop/macos/Classes/FacebookAuthDesktopPlugin.swift index 759f85a9..f51985b8 100644 --- a/facebook_auth_desktop/macos/Classes/FacebookAuthDesktopPlugin.swift +++ b/facebook_auth_desktop/macos/Classes/FacebookAuthDesktopPlugin.swift @@ -58,7 +58,8 @@ public class WebViewController: NSViewController, WKNavigationDelegate { var targetUriFragment: String? var onComplete: ((String?) -> Void)? var onDismissed: (() -> Void)? - + var window: NSWindow? + public override func loadView() { self.title = "" let webView = WKWebView(frame: NSMakeRect(0, 0, 980, 720)) @@ -68,6 +69,10 @@ public class WebViewController: NSViewController, WKNavigationDelegate { view = webView } + + public override func viewDidAppear() { + window = self.view.window! + } func loadUrl(_ url: String) { clearCookies() @@ -99,7 +104,7 @@ public class WebViewController: NSViewController, WKNavigationDelegate { if uriString.contains(targetUriFragment!) { decisionHandler(.cancel) onComplete!(uriString) - dismiss(self) + window?.performClose(nil); } else { decisionHandler(.allow) }