summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2022-11-24 17:12:43 +0100
committerAndrej Mihajlov <and@mullvad.net>2022-11-28 10:39:08 +0100
commitc2ab6df2e1d1fc89a509f5659ad32811b95c5944 (patch)
tree4b94c20f889ffe10dee4f3a16c56bc53dec1f396
parent4ecef23df44f761292f3cce39f07f3d38c936681 (diff)
downloadmullvadvpn-c2ab6df2e1d1fc89a509f5659ad32811b95c5944.tar.xz
mullvadvpn-c2ab6df2e1d1fc89a509f5659ad32811b95c5944.zip
Implement UI for migration errors
-rw-r--r--ios/MullvadVPN.xcodeproj/project.pbxproj4
-rw-r--r--ios/MullvadVPN/AppDelegate.swift50
-rw-r--r--ios/MullvadVPN/SceneDelegate.swift62
-rw-r--r--ios/MullvadVPN/SettingsMigrationUIHandler.swift13
4 files changed, 113 insertions, 16 deletions
diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj
index 4f7aaa8a3e..ccdeee7e73 100644
--- a/ios/MullvadVPN.xcodeproj/project.pbxproj
+++ b/ios/MullvadVPN.xcodeproj/project.pbxproj
@@ -293,6 +293,7 @@
58E0729F28814ACC008902F8 /* WireGuardLogLevel+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58E0729E28814ACC008902F8 /* WireGuardLogLevel+Logging.swift */; };
58E072A128814B0E008902F8 /* MullvadEndpoint+WgEndpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58E072A028814B0E008902F8 /* MullvadEndpoint+WgEndpoint.swift */; };
58E0A98827C8F46300FE6BDD /* Tunnel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58E0A98727C8F46300FE6BDD /* Tunnel.swift */; };
+ 58E11188292FA11F009FCA84 /* SettingsMigrationUIHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58E11187292FA11F009FCA84 /* SettingsMigrationUIHandler.swift */; };
58E20771274672CA00DE5D77 /* LaunchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58E20770274672CA00DE5D77 /* LaunchViewController.swift */; };
58E25F812837BBBB002CFB2C /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58E25F802837BBBB002CFB2C /* SceneDelegate.swift */; };
58E511E628DDDEAC00B0BCDE /* CodingErrors+CustomErrorDescription.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58E511E528DDDEAC00B0BCDE /* CodingErrors+CustomErrorDescription.swift */; };
@@ -788,6 +789,7 @@
58E072A028814B0E008902F8 /* MullvadEndpoint+WgEndpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MullvadEndpoint+WgEndpoint.swift"; sourceTree = "<group>"; };
58E072A428814C28008902F8 /* TunnelMonitorDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TunnelMonitorDelegate.swift; sourceTree = "<group>"; };
58E0A98727C8F46300FE6BDD /* Tunnel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tunnel.swift; sourceTree = "<group>"; };
+ 58E11187292FA11F009FCA84 /* SettingsMigrationUIHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsMigrationUIHandler.swift; sourceTree = "<group>"; };
58E20770274672CA00DE5D77 /* LaunchViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchViewController.swift; sourceTree = "<group>"; };
58E25F802837BBBB002CFB2C /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
58E511E028DDB7F100B0BCDE /* WrappingError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WrappingError.swift; sourceTree = "<group>"; };
@@ -1410,6 +1412,7 @@
58CCA0152242560B004F3011 /* UIColor+Palette.swift */,
585CA70E25F8C44600B47C62 /* UIMetrics.swift */,
58F7CA872692E34000FC59FD /* WireguardKeysContentView.swift */,
+ 58E11187292FA11F009FCA84 /* SettingsMigrationUIHandler.swift */,
);
path = MullvadVPN;
sourceTree = "<group>";
@@ -2261,6 +2264,7 @@
5888AD83227B11080051EB06 /* SelectLocationCell.swift in Sources */,
5891BF1C25E3E3EB006D6FB0 /* Bundle+ProductVersion.swift in Sources */,
5878A26F2907E7E00096FC88 /* ProblemReportInteractor.swift in Sources */,
+ 58E11188292FA11F009FCA84 /* SettingsMigrationUIHandler.swift in Sources */,
5807E2C02432038B00F5FF30 /* String+Split.swift in Sources */,
58677712290976FB006F721F /* SettingsInteractor.swift in Sources */,
58CE5E66224146200008646E /* LoginViewController.swift in Sources */,
diff --git a/ios/MullvadVPN/AppDelegate.swift b/ios/MullvadVPN/AppDelegate.swift
index b11ada5f7c..1721f80261 100644
--- a/ios/MullvadVPN/AppDelegate.swift
+++ b/ios/MullvadVPN/AppDelegate.swift
@@ -110,28 +110,48 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
setupNotificationHandler()
addApplicationNotifications(application: application)
- let setupTunnelManagerOperation =
- AsyncBlockOperation(dispatchQueue: .main) { operation in
- SettingsManager.migrateStore(with: self.proxyFactory) { error in
- precondition(error == nil)
-
- self.tunnelManager.loadConfiguration { error in
- // TODO: avoid throwing fatal error and show the problem report UI instead.
- if let error = error {
- fatalError(error.localizedDescription)
- }
+ let migrateSettingsOperation = AsyncBlockOperation(dispatchQueue: .main) { operation in
+ SettingsManager.migrateStore(with: self.proxyFactory) { error in
+ guard let error = error else {
+ operation.finish()
+ return
+ }
- self.logger.debug("Finished initialization.")
+ guard let migrationUIHandler = application.connectedScenes.compactMap({ scene in
+ return scene.delegate as? SettingsMigrationUIHandler
+ }).first else {
+ operation.finish()
+ return
+ }
- NotificationManager.shared.updateNotifications()
- self.storePaymentManager.startPaymentQueueMonitoring()
+ migrationUIHandler.showMigrationError(error) {
+ operation.finish()
+ }
+ }
+ }
- operation.finish()
+ let loadTunnelConfigurationOperation =
+ AsyncBlockOperation(dispatchQueue: .main) { operation in
+ self.tunnelManager.loadConfiguration { error in
+ // TODO: avoid throwing fatal error and show the problem report UI instead.
+ if let error = error {
+ fatalError(error.localizedDescription)
}
+
+ self.logger.debug("Finished initialization.")
+
+ NotificationManager.shared.updateNotifications()
+ self.storePaymentManager.startPaymentQueueMonitoring()
+
+ operation.finish()
}
}
+ loadTunnelConfigurationOperation.addDependency(migrateSettingsOperation)
- operationQueue.addOperation(setupTunnelManagerOperation)
+ operationQueue.addOperations(
+ [migrateSettingsOperation, loadTunnelConfigurationOperation],
+ waitUntilFinished: false
+ )
return true
}
diff --git a/ios/MullvadVPN/SceneDelegate.swift b/ios/MullvadVPN/SceneDelegate.swift
index 27fbfa7bf2..03f6bc3674 100644
--- a/ios/MullvadVPN/SceneDelegate.swift
+++ b/ios/MullvadVPN/SceneDelegate.swift
@@ -19,7 +19,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate, UISplitViewControllerDe
SettingsNavigationControllerDelegate, ConnectViewControllerDelegate,
OutOfTimeViewControllerDelegate, SelectLocationViewControllerDelegate,
RevokedDeviceViewControllerDelegate, NotificationManagerDelegate, TunnelObserver,
- RelayCacheTrackerObserver
+ RelayCacheTrackerObserver, SettingsMigrationUIHandler
{
private let logger = Logger(label: "SceneDelegate")
@@ -952,4 +952,64 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate, UISplitViewControllerDe
}
return nil
}
+
+ // MARK: - SettingsMigrationUIHandler
+
+ func showMigrationError(_ error: Error, completionHandler: @escaping () -> Void) {
+ let alertController = UIAlertController(
+ title: NSLocalizedString(
+ "ALERT_TITLE",
+ tableName: "SettingsMigrationUI",
+ value: "Settings migration error",
+ comment: ""
+ ),
+ message: Self.migrationErrorReason(error),
+ preferredStyle: .alert
+ )
+ alertController.addAction(
+ UIAlertAction(
+ title: NSLocalizedString("OK", tableName: "SettingsMigrationUI", comment: ""),
+ style: .default,
+ handler: { _ in
+ completionHandler()
+ }
+ )
+ )
+
+ if let rootViewController = window?.rootViewController {
+ rootViewController.present(alertController, animated: true)
+ } else {
+ completionHandler()
+ }
+ }
+
+ private static func migrationErrorReason(_ error: Error) -> String {
+ if error is UnsupportedSettingsVersionError {
+ return NSLocalizedString(
+ "NEWER_STORED_SETTINGS_ERROR",
+ tableName: "SettingsMigrationUI",
+ value: """
+ The version of settings stored on device is from a newer app than is currently \
+ running. Settings will be reset to defaults.
+ """,
+ comment: ""
+ )
+ } else if let error = error as? SettingsMigrationError,
+ error.underlyingError is REST.Error
+ {
+ return NSLocalizedString(
+ "NETWORK_ERROR",
+ tableName: "SettingsMigrationUI",
+ value: "Network error occurred. Settings will be reset to defaults.",
+ comment: ""
+ )
+ } else {
+ return NSLocalizedString(
+ "INTERNAL_ERROR",
+ tableName: "SettingsMigrationUI",
+ value: "Internal error occurred. Settings will be reset to defaults.",
+ comment: ""
+ )
+ }
+ }
}
diff --git a/ios/MullvadVPN/SettingsMigrationUIHandler.swift b/ios/MullvadVPN/SettingsMigrationUIHandler.swift
new file mode 100644
index 0000000000..949458e394
--- /dev/null
+++ b/ios/MullvadVPN/SettingsMigrationUIHandler.swift
@@ -0,0 +1,13 @@
+//
+// SettingsMigrationUIHandler.swift
+// MullvadVPN
+//
+// Created by pronebird on 24/11/2022.
+// Copyright © 2022 Mullvad VPN AB. All rights reserved.
+//
+
+import Foundation
+
+protocol SettingsMigrationUIHandler {
+ func showMigrationError(_ error: Error, completionHandler: @escaping () -> Void)
+}