From 8d7c48b698b9d3614f4606ab2b8e2b8d0d3484c9 Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Mon, 2 Sep 2024 16:55:34 +0200 Subject: [PATCH 1/2] fix(ui): update UIApplication+Ext.swift --- IVPNClient/AppDelegate.swift | 11 ++--------- .../Utilities/Extensions/UIApplication+Ext.swift | 2 +- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/IVPNClient/AppDelegate.swift b/IVPNClient/AppDelegate.swift index 1753b0197..beb58b02d 100644 --- a/IVPNClient/AppDelegate.swift +++ b/IVPNClient/AppDelegate.swift @@ -96,16 +96,9 @@ class AppDelegate: UIResponder { private func showSecurityScreen() { var showWindow = false + let topVC = UIApplication.topViewController() - if UIApplication.topViewController() as? AccountViewController != nil { - showWindow = true - } - - if UIApplication.topViewController() as? LoginViewController != nil { - showWindow = true - } - - if UIApplication.topViewController() as? CreateAccountViewController != nil { + if topVC is AccountViewController || topVC is LoginViewController || topVC is CreateAccountViewController { showWindow = true } diff --git a/IVPNClient/Utilities/Extensions/UIApplication+Ext.swift b/IVPNClient/Utilities/Extensions/UIApplication+Ext.swift index f78fff72f..398d3f0d1 100644 --- a/IVPNClient/Utilities/Extensions/UIApplication+Ext.swift +++ b/IVPNClient/Utilities/Extensions/UIApplication+Ext.swift @@ -27,7 +27,7 @@ extension UIApplication { var keyWindow: UIWindow? { return self.connectedScenes - .filter { $0.activationState == .foregroundActive } + .filter { $0.activationState == .foregroundActive || $0.activationState == .foregroundInactive } .first(where: { $0 is UIWindowScene }) .flatMap({ $0 as? UIWindowScene })?.windows .first(where: \.isKeyWindow) From f7ad688308f8d4563cd6bba3b1e4341b8e6a1155 Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Wed, 11 Sep 2024 10:32:48 +0200 Subject: [PATCH 2/2] fix(widget): update ConnectionManager.swift --- IVPNClient/Managers/ConnectionManager.swift | 13 ++----------- .../Scenes/MainScreen/MainViewController.swift | 5 +++++ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/IVPNClient/Managers/ConnectionManager.swift b/IVPNClient/Managers/ConnectionManager.swift index be4ed03d2..bd52b54fc 100644 --- a/IVPNClient/Managers/ConnectionManager.swift +++ b/IVPNClient/Managers/ConnectionManager.swift @@ -96,9 +96,6 @@ class ConnectionManager { self.updateOpenVPNLogFile() self.updateWireGuardLogFile() self.reconnectAutomatically = false - if self.actionType == .connect { - self.evaluateCloseApp() - } } DispatchQueue.delay(2.5) { if UserDefaults.shared.isV2ray && !V2RayCore.shared.reconnectWithV2ray { @@ -128,10 +125,6 @@ class ConnectionManager { } } } - - if status == .disconnected && self.actionType == .disconnect { - self.evaluateCloseApp() - } completion(status) } @@ -575,12 +568,10 @@ class ConnectionManager { } } - private func evaluateCloseApp() { + func evaluateCloseApp() { if closeApp { closeApp = false - DispatchQueue.delay(1.5) { - UIControl().sendAction(#selector(NSXPCConnection.suspend), to: UIApplication.shared, for: nil) - } + UIControl().sendAction(#selector(NSXPCConnection.suspend), to: UIApplication.shared, for: nil) } } diff --git a/IVPNClient/Scenes/MainScreen/MainViewController.swift b/IVPNClient/Scenes/MainScreen/MainViewController.swift index efaa9804d..557b874d7 100644 --- a/IVPNClient/Scenes/MainScreen/MainViewController.swift +++ b/IVPNClient/Scenes/MainScreen/MainViewController.swift @@ -167,6 +167,9 @@ class MainViewController: UIViewController { if !model.isIvpnServer { Application.shared.geoLookup = model } + + WidgetCenter.shared.reloadTimelines(ofKind: "IVPNWidget") + Application.shared.connectionManager.evaluateCloseApp() case .failure: controlPanel.controlPanelView.ipv4ViewModel = ProofsViewModel(displayMode: .error) mainView.infoAlertViewModel.infoAlert = .connectionInfoFailure @@ -180,6 +183,8 @@ class MainViewController: UIViewController { case .success(let model): controlPanel.controlPanelView.ipv6ViewModel = ProofsViewModel(model: model, displayMode: .content) mainView.ipv6ViewModel = ProofsViewModel(model: model) + WidgetCenter.shared.reloadTimelines(ofKind: "IVPNWidget") + Application.shared.connectionManager.evaluateCloseApp() case .failure: controlPanel.controlPanelView.ipv6ViewModel = ProofsViewModel(displayMode: .error) mainView.ipv6ViewModel = ProofsViewModel(displayMode: .error)