Преглед на файлове

open welcome-screen from add-account

B. Petersen преди 5 години
родител
ревизия
cc82ff2289

+ 9 - 2
DcCore/DcCore/Helper/AccountManager.swift

@@ -57,8 +57,9 @@ public class AccountManager {
     private func resetDcContext() {
         // create an empty DcContext object - this will be set up then, starting with
         // getSelectedAccount()
-
-        // TODO
+        DcContext.shared.stopIo()
+        DcContext.shared.closeDatabase()
+        DcContext.shared = DcContext()
     }
 
 
@@ -113,4 +114,10 @@ public class AccountManager {
         resetDcContext()
         return true
     }
+
+    public func canRollbackAccountCreation() -> Bool {
+        guard let userDefaults = UserDefaults.shared else { return false }
+        let prevDbName = userDefaults.string(forKey: UserDefaults.prevAccountDbName) ?? ""
+        return !prevDbName.isEmpty
+    }
 }

+ 4 - 3
deltachat-ios/Controller/SettingsController.swift

@@ -461,10 +461,11 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
 
         // add account
         alert.addAction(UIAlertAction(title: String.localized("add_account"), style: .default, handler: { [weak self] _ in
-            if !AccountManager().beginAccountCreation() {
-                self?.presentError(message: "Cannot begin account creation.")
+            if AccountManager().beginAccountCreation(), let appDelegate = UIApplication.shared.delegate as? AppDelegate {
+                appDelegate.installEventHandler()
+                appDelegate.appCoordinator.presentWelcomeController()
             } else {
-                // TODO
+                self?.presentError(message: "Cannot begin account creation.")
             }
         }))
 

+ 12 - 1
deltachat-ios/Controller/WelcomeViewController.swift

@@ -42,7 +42,15 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler {
     init(dcContext: DcContext) {
         self.dcContext = dcContext
         super.init(nibName: nil, bundle: nil)
-        self.navigationItem.title = String.localized("welcome_desktop")
+
+        let canRollback = AccountManager().canRollbackAccountCreation()
+        self.navigationItem.title = canRollback ? String.localized("add_account") : String.localized("welcome_desktop")
+        if canRollback {
+            navigationItem.leftBarButtonItem = UIBarButtonItem.init(barButtonSystemItem: UIBarButtonItem.SystemItem.cancel,
+                target: self,
+                action: #selector(rollbackButton))
+        }
+
         onProgressSuccess = { [weak self] in
             let profileInfoController = ProfileInfoViewController(context: dcContext)
             profileInfoController.onClose = {
@@ -131,6 +139,9 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler {
         alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default))
         present(alert, animated: true)
     }
+
+    @objc func rollbackButton() {
+    }
 }
 
 extension WelcomeViewController: QrCodeReaderDelegate {