Skip to content

Commit

Permalink
Merge pull request #238 from ivpn/feature/hide-sensitive-ui-when-ente…
Browse files Browse the repository at this point in the history
…ring-background

Hide sensitive UI when entering background
  • Loading branch information
jurajhilje authored Mar 29, 2022
2 parents 268a179 + 1ee1b27 commit 4a72916
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
56 changes: 55 additions & 1 deletion IVPNClient/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions IVPNClient/Scenes/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<viewController storyboardIdentifier="launchScreen" useStoryboardIdentifierAsRestorationIdentifier="YES" id="01J-lp-oVM" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
Expand Down

0 comments on commit 4a72916

Please sign in to comment.