summaryrefslogtreecommitdiffhomepage
path: root/ios
diff options
context:
space:
mode:
authorJon Petersson <jon.petersson@kvadrat.se>2023-04-25 13:20:22 +0200
committerAndrej Mihajlov <and@mullvad.net>2023-05-04 17:12:17 +0200
commitb6117d39b2de95b02285186f442320530643fcd9 (patch)
treeff1d0fd507f188711a231299ce2fdd70c78a3d77 /ios
parent8c56d5e3adb82ee5bbc259d55ea61a873f72be44 (diff)
downloadmullvadvpn-b6117d39b2de95b02285186f442320530643fcd9.tar.xz
mullvadvpn-b6117d39b2de95b02285186f442320530643fcd9.zip
Fix view state when disconnecting from out of time view
Diffstat (limited to 'ios')
-rw-r--r--ios/MullvadVPN/View controllers/OutOfTime/OutOfTimeContentView.swift7
-rw-r--r--ios/MullvadVPN/View controllers/OutOfTime/OutOfTimeInteractor.swift30
-rw-r--r--ios/MullvadVPN/View controllers/OutOfTime/OutOfTimeViewController.swift8
3 files changed, 40 insertions, 5 deletions
diff --git a/ios/MullvadVPN/View controllers/OutOfTime/OutOfTimeContentView.swift b/ios/MullvadVPN/View controllers/OutOfTime/OutOfTimeContentView.swift
index 13bf85dd9e..8bafb81ddf 100644
--- a/ios/MullvadVPN/View controllers/OutOfTime/OutOfTimeContentView.swift
+++ b/ios/MullvadVPN/View controllers/OutOfTime/OutOfTimeContentView.swift
@@ -105,6 +105,13 @@ class OutOfTimeContentView: UIView {
fatalError("init(coder:) has not been implemented")
}
+ func enableDisconnectButton(_ enabled: Bool, animated: Bool) {
+ disconnectButton.isEnabled = enabled
+ UIView.animate(withDuration: animated ? 0.25 : 0) {
+ self.disconnectButton.alpha = enabled ? 1 : 0
+ }
+ }
+
// MARK: - Private Functions
func setUpSubviews() {
diff --git a/ios/MullvadVPN/View controllers/OutOfTime/OutOfTimeInteractor.swift b/ios/MullvadVPN/View controllers/OutOfTime/OutOfTimeInteractor.swift
index 4166cb1e36..5a833fef22 100644
--- a/ios/MullvadVPN/View controllers/OutOfTime/OutOfTimeInteractor.swift
+++ b/ios/MullvadVPN/View controllers/OutOfTime/OutOfTimeInteractor.swift
@@ -7,21 +7,28 @@
//
import Foundation
+import MullvadLogging
import MullvadREST
import MullvadTypes
import Operations
import StoreKit
+/// Interval used for periodic polling account updates.
+private let accountUpdateTimerInterval: TimeInterval = 60
+
final class OutOfTimeInteractor {
private let storePaymentManager: StorePaymentManager
private let tunnelManager: TunnelManager
- var didReceivePaymentEvent: ((StorePaymentEvent) -> Void)?
- var didReceiveTunnelStatus: ((TunnelStatus) -> Void)?
-
private var tunnelObserver: TunnelObserver?
private var paymentObserver: StorePaymentObserver?
+ private let logger = Logger(label: "OutOfTimeInteractor")
+ private var accountUpdateTimer: DispatchSourceTimer?
+
+ var didReceivePaymentEvent: ((StorePaymentEvent) -> Void)?
+ var didReceiveTunnelStatus: ((TunnelStatus) -> Void)?
+
init(storePaymentManager: StorePaymentManager, tunnelManager: TunnelManager) {
self.storePaymentManager = storePaymentManager
self.tunnelManager = tunnelManager
@@ -81,4 +88,21 @@ final class OutOfTimeInteractor {
completionHandler: completionHandler
)
}
+
+ func startAccountUpdateTimer() {
+ logger.debug(
+ "Start polling account updates every \(accountUpdateTimerInterval) second(s)."
+ )
+
+ let timer = DispatchSource.makeTimerSource(queue: .main)
+ timer.setEventHandler { [weak self] in
+ self?.tunnelManager.updateAccountData()
+ }
+
+ accountUpdateTimer?.cancel()
+ accountUpdateTimer = timer
+
+ timer.schedule(wallDeadline: .now() + accountUpdateTimerInterval, repeating: accountUpdateTimerInterval)
+ timer.activate()
+ }
}
diff --git a/ios/MullvadVPN/View controllers/OutOfTime/OutOfTimeViewController.swift b/ios/MullvadVPN/View controllers/OutOfTime/OutOfTimeViewController.swift
index ff1c6ff693..516c977c4f 100644
--- a/ios/MullvadVPN/View controllers/OutOfTime/OutOfTimeViewController.swift
+++ b/ios/MullvadVPN/View controllers/OutOfTime/OutOfTimeViewController.swift
@@ -99,6 +99,7 @@ class OutOfTimeViewController: UIViewController, RootContainment {
interactor.didReceiveTunnelStatus = { [weak self] tunnelStatus in
self?.setNeedsHeaderBarStyleAppearanceUpdate()
+ self?.applyViewState()
}
if StorePaymentManager.canMakePayments {
@@ -106,6 +107,8 @@ class OutOfTimeViewController: UIViewController, RootContainment {
} else {
productState = .cannotMakePurchases
}
+
+ interactor.startAccountUpdateTimer()
}
// MARK: - Private
@@ -136,8 +139,8 @@ class OutOfTimeViewController: UIViewController, RootContainment {
purchaseButton.isEnabled = productState.isReceived && isInteractionEnabled && !tunnelState
.isSecured
contentView.restoreButton.isEnabled = isInteractionEnabled
- contentView.disconnectButton.isEnabled = tunnelState.isSecured
- contentView.disconnectButton.alpha = tunnelState.isSecured ? 1 : 0
+
+ contentView.enableDisconnectButton(tunnelState.isSecured, animated: true)
if tunnelState.isSecured {
contentView.setBodyLabelText(
@@ -341,6 +344,7 @@ class OutOfTimeViewController: UIViewController, RootContainment {
}
@objc private func handleDisconnect(_ sender: Any) {
+ contentView.disconnectButton.isEnabled = false
interactor.stopTunnel()
}
}