فهرست منبع

always handle dcaccount in WelcomeViewController

cyberta 3 سال پیش
والد
کامیت
c3c92be9c2

+ 3 - 3
deltachat-ios/AppDelegate.swift

@@ -188,7 +188,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
 
         switch url.scheme?.lowercased() {
         case "dcaccount":
-            self.reloadDcContext(accountCode: url.absoluteString)
+            appCoordinator.handleQRCode(url.absoluteString)
             return true
         case "openpgp4fpr":
             // Hack to format url properly
@@ -196,10 +196,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
                            .replacingOccurrences(of: "openpgp4fpr", with: "OPENPGP4FPR", options: .literal, range: nil)
                            .replacingOccurrences(of: "%23", with: "#", options: .literal, range: nil)
 
-            self.appCoordinator.handleQRCodeForCurrentAccount(urlString)
+            appCoordinator.handleQRCode(urlString)
             return true
         case "mailto":
-            return self.appCoordinator.handleMailtoURL(url)
+            return appCoordinator.handleMailtoURL(url)
         default:
             return false
         }

+ 2 - 12
deltachat-ios/Controller/QrPageController.swift

@@ -212,18 +212,8 @@ extension QrPageController: QrCodeReaderDelegate {
             present(alert, animated: true, completion: nil)
 
         case DC_QR_ACCOUNT:
-            if let domain = qrParsed.text1 {
-                let title = String.localizedStringWithFormat(String.localized("qraccount_ask_create_and_login_another"), domain)
-                let alert = UIAlertController(title: title, message: nil, preferredStyle: .alert)
-                alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .default))
-                alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: { [weak self] _ in
-                    guard let self = self else { return }
-                    if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
-                        _ = self.dcAccounts.add()
-                        appDelegate.reloadDcContext(accountCode: code)
-                    }
-                }))
-                present(alert, animated: true)
+            if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
+                appDelegate.appCoordinator.presentWelcomeController(accountCode: code)
             }
 
         case DC_QR_WEBRTC_INSTANCE:

+ 18 - 5
deltachat-ios/Controller/WelcomeViewController.swift

@@ -42,7 +42,7 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler {
     }()
 
     private lazy var cancelButton: UIBarButtonItem = {
-        return UIBarButtonItem(title: String.localized("cancel"), style: .plain, target: self, action: #selector(cancelButtonPressed))
+        return UIBarButtonItem(title: String.localized("cancel"), style: .plain, target: self, action: #selector(cancelAccountCreation))
     }()
 
     private lazy var moreButton: UIBarButtonItem = {
@@ -92,7 +92,7 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler {
         }
         navigationItem.rightBarButtonItem = moreButton
         if let accountCode = accountCode {
-            createAccountFromQRCode(qrCode: accountCode)
+            handleQrCode(accountCode)
         }
     }
 
@@ -243,7 +243,7 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler {
         self.navigationController?.pushViewController(accountSetupController, animated: true)
     }
 
-    @objc private func cancelButtonPressed() {
+    @objc private func cancelAccountCreation() {
         guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
         // take a bit care on account removal:
         // remove only openend and unconfigured and make sure, there is another account
@@ -347,7 +347,13 @@ extension WelcomeViewController: QrCodeReaderDelegate {
             title: String.localized("cancel"),
             style: .cancel,
             handler: { [weak self] _ in
-                self?.dismissQRReader()
+                guard let self = self else { return }
+                self.dismissQRReader()
+                // if an injected accountCode exists, the WelcomeViewController was only opened to handle that
+                // cancelling the action should also dismiss the whole controller
+                if self.accountCode != nil {
+                    self.cancelAccountCreation()
+                }
             }
         )
 
@@ -367,7 +373,14 @@ extension WelcomeViewController: QrCodeReaderDelegate {
             title: String.localized("ok"),
             style: .default,
             handler: { [weak self] _ in
-                self?.qrCodeReader?.startSession()
+                guard let self = self else { return }
+                if self.accountCode != nil {
+                    // if an injected accountCode exists, the WelcomeViewController was only opened to handle that
+                    // if the action failed the whole controller should be dismissed
+                    self.cancelAccountCreation()
+                } else {
+                    self.qrCodeReader?.startSession()
+                }
             }
         )
         alert.addAction(okAction)

+ 10 - 6
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -132,12 +132,16 @@ class AppCoordinator {
         return false
     }
 
-    func handleQRCodeForCurrentAccount(_ code: String) {
-        showTab(index: qrTab)
-        if let navController = self.tabBarController.selectedViewController as? UINavigationController,
-           let topViewController = navController.topViewController,
-            let qrPageController = topViewController as? QrPageController {
-            qrPageController.handleQrCode(code)
+    func handleQRCode(_ code: String) {
+        if code.lowercased().starts(with: "dcaccount:") {
+            presentWelcomeController(accountCode: code)
+        } else {
+            showTab(index: qrTab)
+            if let navController = self.tabBarController.selectedViewController as? UINavigationController,
+               let topViewController = navController.topViewController,
+                let qrPageController = topViewController as? QrPageController {
+                qrPageController.handleQrCode(code)
+            }
         }
     }