Quellcode durchsuchen

show progress alert earlier. Improves the responsiveness after allowing to create a new account from dcaccount url scheme

cyberta vor 3 Jahren
Ursprung
Commit
e30e80145a

+ 7 - 13
deltachat-ios/Controller/WelcomeViewController.swift

@@ -154,20 +154,21 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler {
         let accountId = dcAccounts.getSelected().id
 
         if accountId != 0 {
-            self.dcContext = dcAccounts.get(id: accountId)
+            dcContext = dcAccounts.get(id: accountId)
+            addProgressAlertListener(dcAccounts: self.dcAccounts,
+                                     progressName: dcNotificationConfigureProgress,
+                                     onSuccess: self.handleLoginSuccess)
+            showProgressAlert(title: String.localized("login_header"), dcContext: self.dcContext)
             DispatchQueue.global().async { [weak self] in
                 guard let self = self else { return }
                 let success = self.dcContext.setConfigFromQR(qrCode: qrCode)
                 DispatchQueue.main.async {
                     if success {
-                        self.addProgressAlertListener(dcAccounts: self.dcAccounts,
-                                                      progressName: dcNotificationConfigureProgress,
-                                                      onSuccess: self.handleLoginSuccess)
-                        self.showProgressAlert(title: String.localized("login_header"), dcContext: self.dcContext)
                         self.dcAccounts.stopIo()
                         self.dcContext.configure()
                     } else {
-                        self.accountCreationErrorAlert()
+                        self.updateProgressAlert(error: self.dcContext.lastErrorString,
+                                                 completion: self.accountCode != nil ? self.cancelAccountCreation : nil)
                     }
                 }
             }
@@ -194,13 +195,6 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler {
         }
     }
 
-    private func accountCreationErrorAlert() {
-        let title = dcContext.lastErrorString
-        let alert = UIAlertController(title: title, message: nil, preferredStyle: .alert)
-        alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default))
-        present(alert, animated: true)
-    }
-
     @objc private func moreButtonPressed() {
         let alert = UIAlertController(title: "Encrypted Account (experimental)",
                                       message: "Do you want to encrypt your account database? This cannot be undone.",

+ 5 - 3
deltachat-ios/Handler/ProgressAlertHandler.swift

@@ -6,7 +6,7 @@ protocol ProgressAlertHandler: UIViewController {
     var progressObserver: NSObjectProtocol? { get set } // set to nil in viewDidDisappear
     func showProgressAlert(title: String, dcContext: DcContext)
     func updateProgressAlertValue(value: Int?)
-    func updateProgressAlert(error: String?)
+    func updateProgressAlert(error: String?, completion: VoidFunction?)
     func updateProgressAlertSuccess(completion: VoidFunction?)
     func addProgressAlertListener(dcAccounts: DcAccounts, progressName: Notification.Name, onSuccess: @escaping VoidFunction)
 }
@@ -39,7 +39,7 @@ extension ProgressAlertHandler {
         }
     }
 
-    func updateProgressAlert(error message: String?) {
+    func updateProgressAlert(error message: String?, completion onComplete: VoidFunction? = nil) {
         DispatchQueue.main.async(execute: {
             // CAVE: show the new alert in the dismiss-done-handler of the previous one -
             // otherwise we get the error "Attempt to present <UIAlertController: ...> while a presentation is in progress."
@@ -47,7 +47,9 @@ extension ProgressAlertHandler {
             // (when animated is true, that works also sequentially, however better not rely on that, also we do not want an animation here)
             self.progressAlert?.dismiss(animated: false) {
                 let errorAlert = UIAlertController(title: String.localized("error"), message: message, preferredStyle: .alert)
-                errorAlert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: nil))
+                errorAlert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: { _ in
+                    onComplete?()
+                }))
                 // sometimes error messages are not shown and we get the same error as above
                 // as a workaround we disable animated here as well
                 self.present(errorAlert, animated: false, completion: nil)