Skip to content

Commit

Permalink
Merge pull request #454 from ivpn/bugfix/privacy-overlay
Browse files Browse the repository at this point in the history
[iOS 18] Privacy overlay not appearing when entering background
  • Loading branch information
jurajhilje authored Sep 17, 2024
2 parents d79e2f3 + f7ad688 commit 68101ea
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 21 deletions.
11 changes: 2 additions & 9 deletions IVPNClient/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
13 changes: 2 additions & 11 deletions IVPNClient/Managers/ConnectionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -128,10 +125,6 @@ class ConnectionManager {
}
}
}

if status == .disconnected && self.actionType == .disconnect {
self.evaluateCloseApp()
}

completion(status)
}
Expand Down Expand Up @@ -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)
}
}

Expand Down
5 changes: 5 additions & 0 deletions IVPNClient/Scenes/MainScreen/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion IVPNClient/Utilities/Extensions/UIApplication+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 68101ea

Please sign in to comment.