diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2023-05-25 16:06:01 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2023-05-25 16:06:01 +0200 |
| commit | 6b3f0e2fb40aaba765b9e7d90874842b0ded922c (patch) | |
| tree | 720058eac587d07cb1995eab6dbf5c7a71b83b83 | |
| parent | 292635f2f8a9df2163fa3827eb2cfc21ac60364d (diff) | |
| parent | 790ce1b318c8910acb5e61ddf3cc02bcc7bce0a3 (diff) | |
| download | mullvadvpn-6b3f0e2fb40aaba765b9e7d90874842b0ded922c.tar.xz mullvadvpn-6b3f0e2fb40aaba765b9e7d90874842b0ded922c.zip | |
Merge branch 'add-alert-if-user-disconnects-when-ios-157'
3 files changed, 61 insertions, 3 deletions
diff --git a/ios/MullvadVPN/Coordinators/App/TunnelCoordinator.swift b/ios/MullvadVPN/Coordinators/App/TunnelCoordinator.swift index bd35d79558..98faee4f85 100644 --- a/ios/MullvadVPN/Coordinators/App/TunnelCoordinator.swift +++ b/ios/MullvadVPN/Coordinators/App/TunnelCoordinator.swift @@ -11,6 +11,7 @@ import UIKit class TunnelCoordinator: Coordinator { private let tunnelManager: TunnelManager private let controller: TunnelViewController + private let alertPresenter = AlertPresenter() private var tunnelObserver: TunnelObserver? @@ -31,6 +32,10 @@ class TunnelCoordinator: Coordinator { controller.shouldShowSelectLocationPicker = { [weak self] in self?.showSelectLocationPicker?() } + + controller.shouldShowCancelTunnelAlert = { [weak self] in + self?.showCancelTunnelAlert() + } } func start() { @@ -51,4 +56,45 @@ class TunnelCoordinator: Coordinator { controller.setMainContentHidden(!deviceState.isLoggedIn, animated: animated) } + + private func showCancelTunnelAlert() { + let alertController = UIAlertController( + title: nil, + message: NSLocalizedString( + "CANCEL_TUNNEL_ALERT_MESSAGE", + tableName: "Main", + value: "If you disconnect now, you won’t be able to secure your connection until the device is online.", + comment: "" + ), + preferredStyle: .alert + ) + + alertController.addAction( + UIAlertAction( + title: NSLocalizedString( + "CANCEL_TUNNEL_ALERT_DISCONNECT_ACTION", + tableName: "Main", + value: "Disconnect", + comment: "" + ), + style: .destructive, + handler: { [weak self] _ in + self?.tunnelManager.stopTunnel() + } + ) + ) + + alertController.addAction( + UIAlertAction( + title: NSLocalizedString( + "CANCEL_TUNNEL_ALERT_CANCEL_ACTION", + tableName: "Main", + value: "Cancel", + comment: "" + ), style: .cancel + ) + ) + + alertPresenter.enqueue(alertController, presentingController: rootViewController) + } } diff --git a/ios/MullvadVPN/View controllers/Tunnel/TunnelControlView.swift b/ios/MullvadVPN/View controllers/Tunnel/TunnelControlView.swift index bf5c654e3e..fec49f8de2 100644 --- a/ios/MullvadVPN/View controllers/Tunnel/TunnelControlView.swift +++ b/ios/MullvadVPN/View controllers/Tunnel/TunnelControlView.swift @@ -187,7 +187,7 @@ final class TunnelControlView: UIView { NSLocalizedString( "CANCEL_BUTTON_TITLE", tableName: "Main", - value: "Cancel", + value: tunnelState == .waitingForConnectivity(.noConnection) ? "Disconnect" : "Cancel", comment: "" ), for: .normal ) @@ -313,7 +313,7 @@ final class TunnelControlView: UIView { ) cancelButton.addTarget( self, - action: #selector(handleDisconnect), + action: #selector(handleCancel), for: .touchUpInside ) splitDisconnectButton.primaryButton.addTarget( @@ -417,6 +417,10 @@ final class TunnelControlView: UIView { actionHandler?(.connect) } + @objc private func handleCancel() { + actionHandler?(.cancel) + } + @objc private func handleDisconnect() { actionHandler?(.disconnect) } diff --git a/ios/MullvadVPN/View controllers/Tunnel/TunnelViewController.swift b/ios/MullvadVPN/View controllers/Tunnel/TunnelViewController.swift index 8f6cc10a18..ae18153c45 100644 --- a/ios/MullvadVPN/View controllers/Tunnel/TunnelViewController.swift +++ b/ios/MullvadVPN/View controllers/Tunnel/TunnelViewController.swift @@ -19,6 +19,7 @@ class TunnelViewController: UIViewController, RootContainment { private var tunnelState: TunnelState = .disconnected var shouldShowSelectLocationPicker: (() -> Void)? + var shouldShowCancelTunnelAlert: (() -> Void)? private let mapViewController = MapViewController() @@ -68,7 +69,14 @@ class TunnelViewController: UIViewController, RootContainment { case .connect: self?.interactor.startTunnel() - case .disconnect, .cancel: + case .cancel: + if case .waitingForConnectivity(.noConnection) = self?.interactor.tunnelStatus.state { + self?.shouldShowCancelTunnelAlert?() + } else { + self?.interactor.stopTunnel() + } + + case .disconnect: self?.interactor.stopTunnel() case .reconnect: |
