ソースを参照

move account encryption option to the welcome screen

cyberta 3 年 前
コミット
57f81eb28f

+ 1 - 1
deltachat-ios/AppDelegate.swift

@@ -77,7 +77,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
             }
         }
 
-        if dcAccounts.getAll().isEmpty, dcAccounts.addClosedAccount() == 0 {
+        if dcAccounts.getAll().isEmpty, dcAccounts.add() == 0 {
            fatalError("Could not initialize a new account.")
         }
 

+ 0 - 29
deltachat-ios/Controller/AccountSetupController.swift

@@ -6,7 +6,6 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
     private var dcContext: DcContext
     private let dcAccounts: DcAccounts
     private var skipOauth = false
-    private var accountEncryption: Bool?
     private var backupProgressObserver: NSObjectProtocol?
     var progressObserver: NSObjectProtocol?
     var onProgressSuccess: VoidFunction? // not needed here
@@ -29,7 +28,6 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
     private let tagCertCheckCell = 12
     private let tagRestoreCell = 14
     private let tagViewLogCell = 15
-    private let tagAccountEncryptionCell = 16
 
     private let tagTextFieldEmail = 100
     private let tagTextFieldPassword = 200
@@ -53,7 +51,6 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
     private lazy var restoreCells: [UITableViewCell] = [restoreCell]
     private lazy var advancedSectionCells: [UITableViewCell] = [
         advancedShowCell,
-        accountEncryptionCell,
         imapSecurityCell,
         imapUserCell,
         imapServerCell,
@@ -123,17 +120,6 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
         return cell
     }()
 
-    lazy var accountEncryptionCell: SwitchCell = {
-        let isEditable = !dcContext.isConfigured() && !dcContext.isOpen()
-        let cell = SwitchCell(textLabel: String.localized("account_encryption"), on: false, action: { [weak self] cell in
-            self?.accountEncryption = cell.isOn
-        })
-        cell.isHidden = !isEditable
-        cell.isUserInteractionEnabled = isEditable
-        cell.tag = tagAccountEncryptionCell
-        return cell
-    }()
-
     lazy var imapServerCell: TextFieldCell = {
         let cell = TextFieldCell(
             descriptionID: "login_imap_server",
@@ -537,17 +523,6 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
         }
 
         let password = passwordCell.getText() ?? "" // empty passwords are ok -> for oauth there is no password needed
-        var dbPassphrase: String?
-        if !dcContext.isOpen() {
-            if let encryptionEnabled = accountEncryption, encryptionEnabled {
-                do {
-                    dbPassphrase = try KeychainManager.getDBSecret()
-                } catch {
-                    logger.error("failed to obtain db secret: \(error)")
-                }
-            }
-            dcContext.open(passphrase: dbPassphrase)
-        }
 
         login(emailAddress: emailAddress, password: password)
     }
@@ -791,10 +766,6 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
         imapSecurityCell.detailTextLabel?.text = SecurityConverter.getSocketName(value: Int32(dcContext.getConfigInt("mail_security")))
         smtpSecurityCell.detailTextLabel?.text = SecurityConverter.getSocketName(value: Int32(dcContext.getConfigInt("send_security")))
         certCheckCell.detailTextLabel?.text = CertificateCheckController.ValueConverter.convertHexToString(value: dcContext.certificateChecks)
-        if dcContext.isConfigured() || dcContext.isOpen() {
-            // remove account selection option
-            advancedSectionCells.remove(at: 1)
-        }
     }
 
     private func resignFirstResponderOnAllCells() {

+ 2 - 2
deltachat-ios/Controller/SettingsController.swift

@@ -556,7 +556,7 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
         menu.addAction(UIAlertAction(title: String.localized("add_account"), style: .default, handler: { [weak self] _ in
             guard let self = self else { return }
             prefs.setValue(selectedAccountId, forKey: Constants.Keys.lastSelectedAccountKey)
-            _ = self.dcAccounts.addClosedAccount()
+            _ = self.dcAccounts.add()
             appDelegate.reloadDcContext()
         }))
 
@@ -574,7 +574,7 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
                     _ = self.dcAccounts.remove(id: selectedAccountId)
                     INInteraction.delete(with: "\(selectedAccountId)", completion: nil)
                     if self.dcAccounts.getAll().isEmpty {
-                        _ = self.dcAccounts.addClosedAccount()
+                        _ = self.dcAccounts.add()
                     } else {
                         let lastSelectedAccountId = prefs.integer(forKey: Constants.Keys.lastSelectedAccountKey)
                         if lastSelectedAccountId != 0 {

+ 35 - 8
deltachat-ios/Controller/WelcomeViewController.swift

@@ -17,14 +17,7 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler {
         let view = WelcomeContentView()
         view.onLogin = { [weak self] in
             guard let self = self else { return }
-            let accountSetupController = AccountSetupController(dcAccounts: self.dcAccounts, editView: false)
-            accountSetupController.onLoginSuccess = {
-                [weak self] in
-                if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
-                    appDelegate.reloadDcContext()
-                }
-            }
-            self.navigationController?.pushViewController(accountSetupController, animated: true)
+            self.showAccountSetupController()
         }
         view.onScanQRCode  = { [weak self] in
             guard let self = self else { return }
@@ -46,6 +39,10 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler {
         return UIBarButtonItem(title: String.localized("cancel"), style: .plain, target: self, action: #selector(cancelButtonPressed))
     }()
 
+    private lazy var moreButton: UIBarButtonItem = {
+        return UIBarButtonItem(title: String.localized("more"), style: .plain, target: self, action: #selector(moreButtonPressed))
+    }()
+
     private var qrCodeReader: QrCodeReaderController?
     weak var progressAlert: UIAlertController?
 
@@ -77,6 +74,7 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler {
         if canCancel {
             navigationItem.leftBarButtonItem = cancelButton
         }
+        navigationItem.rightBarButtonItem = moreButton
     }
 
     override func viewDidLayoutSubviews() {
@@ -163,6 +161,35 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler {
         present(alert, animated: true)
     }
 
+    @objc private func moreButtonPressed() {
+        let alert = UIAlertController(title: nil, message: nil, preferredStyle: .safeActionSheet)
+        let encryptedAccountAction = UIAlertAction(title: String.localized("Create encrypted account"), style: .default, handler: switchToEncrypted(_:))
+        let cancelAction = UIAlertAction(title: String.localized("cancel"), style: .destructive, handler: nil)
+        alert.addAction(encryptedAccountAction)
+        alert.addAction(cancelAction)
+        self.present(alert, animated: true, completion: nil)
+    }
+
+    private func switchToEncrypted(_ action: UIAlertAction) {
+        let lastContextId = dcContext.id
+        let newContextId = dcAccounts.addClosedAccount()
+        _ = dcAccounts.remove(id: lastContextId)
+        _ = dcAccounts.select(id: newContextId)
+        let selected = dcAccounts.getSelected()
+        selected.open(passphrase: try? KeychainManager.getDBSecret())
+        showAccountSetupController()
+    }
+
+    private func showAccountSetupController() {
+        let accountSetupController = AccountSetupController(dcAccounts: self.dcAccounts, editView: false)
+        accountSetupController.onLoginSuccess = {
+            if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
+                appDelegate.reloadDcContext()
+            }
+        }
+        self.navigationController?.pushViewController(accountSetupController, animated: true)
+    }
+
     @objc private func cancelButtonPressed() {
         guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
         // take a bit care on account removal: