summaryrefslogtreecommitdiffhomepage
path: root/ios
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2023-05-17 16:41:23 +0200
committerAndrej Mihajlov <and@mullvad.net>2023-05-30 11:16:01 +0200
commit89b0dd0059eb891ed25780eefcefe191ff42a9da (patch)
tree5f5649f6d3356e38e639e503495d6d676b457c86 /ios
parentf6e5bdc685aa6a1e5a826bdd2cc91a7f089e0ea2 (diff)
downloadmullvadvpn-89b0dd0059eb891ed25780eefcefe191ff42a9da.tar.xz
mullvadvpn-89b0dd0059eb891ed25780eefcefe191ff42a9da.zip
Refresh account and device data when account controller is being presented
Diffstat (limited to 'ios')
-rw-r--r--ios/MullvadVPN/Coordinators/App/ApplicationCoordinator.swift17
-rw-r--r--ios/MullvadVPN/Coordinators/App/SettingsCoordinator.swift2
-rw-r--r--ios/MullvadVPN/SceneDelegate.swift44
3 files changed, 48 insertions, 15 deletions
diff --git a/ios/MullvadVPN/Coordinators/App/ApplicationCoordinator.swift b/ios/MullvadVPN/Coordinators/App/ApplicationCoordinator.swift
index 9c8ae157d7..183cada2a3 100644
--- a/ios/MullvadVPN/Coordinators/App/ApplicationCoordinator.swift
+++ b/ios/MullvadVPN/Coordinators/App/ApplicationCoordinator.swift
@@ -644,8 +644,10 @@ final class ApplicationCoordinator: Coordinator, Presenting, RootContainerViewCo
preferredContentSize: preferredFormSheetContentSize,
modalPresentationStyle: .formSheet
)
- ) {
+ ) { [weak self] in
completion(coordinator)
+
+ self?.onShowAccount?()
}
}
@@ -785,12 +787,25 @@ final class ApplicationCoordinator: Coordinator, Presenting, RootContainerViewCo
// MARK: - Settings
+ /**
+ This closure is called each time when settings are presented or when navigating from any of sub-routes within
+ settings back to root.
+ */
var onShowSettings: (() -> Void)?
+ /// This closure is called each time when account controller is being presented.
+ var onShowAccount: (() -> Void)?
+
+ /// Returns `true` if settings are being presented.
var isPresentingSettings: Bool {
return router.isPresenting(.settings)
}
+ /// Returns `true` if account controller is being presented.
+ var isPresentingAccount: Bool {
+ return router.isPresenting(.account)
+ }
+
// MARK: - UISplitViewControllerDelegate
func primaryViewController(forExpanding splitViewController: UISplitViewController)
diff --git a/ios/MullvadVPN/Coordinators/App/SettingsCoordinator.swift b/ios/MullvadVPN/Coordinators/App/SettingsCoordinator.swift
index 34e8c90450..743c1b1827 100644
--- a/ios/MullvadVPN/Coordinators/App/SettingsCoordinator.swift
+++ b/ios/MullvadVPN/Coordinators/App/SettingsCoordinator.swift
@@ -118,7 +118,7 @@ final class SettingsCoordinator: Coordinator, Presentable, Presenting, SettingsV
animated: Bool
) {
/*
- Navigation controller tends to call this delegate method on `viewWillAppear`, for instance during cancellation
+ Navigation controller calls this delegate method on `viewWillAppear`, for instance during cancellation
of interactive dismissal of a modally presented settings navigation controller, so it's important that we
ignore repeating routes.
*/
diff --git a/ios/MullvadVPN/SceneDelegate.swift b/ios/MullvadVPN/SceneDelegate.swift
index 1e61422dee..f167d38a26 100644
--- a/ios/MullvadVPN/SceneDelegate.swift
+++ b/ios/MullvadVPN/SceneDelegate.swift
@@ -58,7 +58,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate, SettingsMigrationUIHand
accountDataThrottling = AccountDataThrottling(tunnelManager: tunnelManager)
deviceDataThrottling = DeviceDataThrottling(tunnelManager: tunnelManager)
- refreshDeviceAndAccountData(forceUpdate: true)
+ refreshLoginMetadata(forceUpdate: true)
appCoordinator = ApplicationCoordinator(
tunnelManager: tunnelManager,
@@ -69,8 +69,13 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate, SettingsMigrationUIHand
)
appCoordinator?.onShowSettings = { [weak self] in
- // Refresh account data each time user opens settings
- self?.refreshDeviceAndAccountData(forceUpdate: true)
+ // Refresh account data and device each time user opens settings
+ self?.refreshLoginMetadata(forceUpdate: true)
+ }
+
+ appCoordinator?.onShowAccount = { [weak self] in
+ // Refresh account data and device each time user opens account controller
+ self?.refreshLoginMetadata(forceUpdate: true)
}
window?.rootViewController = appCoordinator?.rootViewController
@@ -89,33 +94,46 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate, SettingsMigrationUIHand
private func deviceStateDidChange(_ deviceState: DeviceState) {
switch deviceState {
- case .loggedOut:
- resetDeviceAndAccountDataThrottling()
-
- case .revoked:
- resetDeviceAndAccountDataThrottling()
+ case .loggedOut, .revoked:
+ resetLoginMetadataThrottling()
case .loggedIn:
break
}
}
- private func refreshDeviceAndAccountData(forceUpdate: Bool) {
- let isPresentingSettings = appCoordinator?.isPresentingSettings ?? false
+ /**
+ Refresh login metadata (account and device data) potentially throttling refresh requests based on recency of
+ the last issued request.
+ Account data is always refreshed when either settings or account are presented on screen, otherwise only when close
+ to or past expiry.
+
+ Both account and device data are refreshed regardless of other conditions when `forceUpdate` is `true`.
+
+ For more information on exact timings used for throttling refresh requests refer to `AccountDataThrottling` and
+ `DeviceDataThrottling` types.
+ */
+ private func refreshLoginMetadata(forceUpdate: Bool) {
let condition: AccountDataThrottling.Condition
if forceUpdate {
condition = .always
} else {
- condition = isPresentingSettings ? .always : .whenCloseToExpiryAndBeyond
+ let isPresentingSettings = appCoordinator?.isPresentingSettings ?? false
+ let isPresentingAccount = appCoordinator?.isPresentingAccount ?? false
+
+ condition = isPresentingSettings || isPresentingAccount ? .always : .whenCloseToExpiryAndBeyond
}
accountDataThrottling?.requestUpdate(condition: condition)
deviceDataThrottling?.requestUpdate(forceUpdate: forceUpdate)
}
- private func resetDeviceAndAccountDataThrottling() {
+ /**
+ Reset throttling for login metadata making a subsequent refresh request execute unthrottled.
+ */
+ private func resetLoginMetadataThrottling() {
accountDataThrottling?.reset()
deviceDataThrottling?.reset()
}
@@ -149,7 +167,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate, SettingsMigrationUIHand
func sceneDidBecomeActive(_ scene: UIScene) {
if isSceneConfigured {
- refreshDeviceAndAccountData(forceUpdate: false)
+ refreshLoginMetadata(forceUpdate: false)
}
setShowsPrivacyOverlay(false)