diff --git a/IVPNClient/AppDelegate.swift b/IVPNClient/AppDelegate.swift index 08c32e458..d7d815519 100644 --- a/IVPNClient/AppDelegate.swift +++ b/IVPNClient/AppDelegate.swift @@ -31,6 +31,18 @@ class AppDelegate: UIResponder { var window: UIWindow? + private lazy var securityWindow: UIWindow = { + let screen = UIScreen.main + let window = UIWindow(frame: screen.bounds) + let storyBoard = UIStoryboard(name: "LaunchScreen", bundle: nil) + let viewController = storyBoard.instantiateViewController(withIdentifier: "launchScreen") + viewController.view.alpha = 0 + window.screen = screen + window.rootViewController = viewController + window.windowLevel = .alert + return window + }() + // MARK: - Methods - private func evaluateUITests() { @@ -96,6 +108,37 @@ class AppDelegate: UIResponder { } } + private func showSecurityScreen() { + var showWindow = false + + if let _ = UIApplication.topViewController() as? AccountViewController { + showWindow = true + } + + if let _ = UIApplication.topViewController() as? LoginViewController { + showWindow = true + } + + if let _ = UIApplication.topViewController() as? CreateAccountViewController { + showWindow = true + } + + if showWindow { + securityWindow.isHidden = false + UIView.animate(withDuration: 0.15, animations: { [self] in + securityWindow.rootViewController?.view.alpha = 1 + }) + } + } + + private func hideSecurityScreen() { + UIView.animate(withDuration: 0.15, animations: { [self] in + securityWindow.rootViewController?.view.alpha = 0 + }, completion: { [self] _ in + securityWindow.isHidden = true + }) + } + private func handleURLEndpoint(_ endpoint: String) { guard let viewController = UIApplication.topViewController() else { return @@ -168,11 +211,22 @@ extension AppDelegate: UIApplicationDelegate { if UserDefaults.shared.networkProtectionEnabled { NetworkManager.shared.startMonitoring() } + + hideSecurityScreen() } func applicationWillEnterForeground(_ application: UIApplication) { - NetworkManager.shared.stopMonitoring() + hideSecurityScreen() refreshUI() + NetworkManager.shared.stopMonitoring() + } + + func applicationWillResignActive(_ application: UIApplication) { + showSecurityScreen() + } + + func applicationDidEnterBackground(_ application: UIApplication) { + showSecurityScreen() } func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) { diff --git a/IVPNClient/Scenes/Base.lproj/LaunchScreen.storyboard b/IVPNClient/Scenes/Base.lproj/LaunchScreen.storyboard index eb4aa1b4c..af1239b6c 100644 --- a/IVPNClient/Scenes/Base.lproj/LaunchScreen.storyboard +++ b/IVPNClient/Scenes/Base.lproj/LaunchScreen.storyboard @@ -1,9 +1,9 @@ - + - + @@ -11,7 +11,7 @@ - +