Parcourir la source

Merge pull request #543 from deltachat/manage_keys

Manage keys
bjoern il y a 5 ans
Parent
commit
50fa7ad4dd

+ 43 - 12
deltachat-ios/Controller/SettingsController.swift

@@ -9,6 +9,8 @@ internal final class SettingsViewController: QuickTableViewController {
     private let rowProfile = 0
     private let rowProfile = 0
     private var dcContext: DcContext
     private var dcContext: DcContext
 
 
+    private let externalPathDescr = "File Sharing/Delta Chat"
+
     let documentInteractionController = UIDocumentInteractionController()
     let documentInteractionController = UIDocumentInteractionController()
     var backupProgressObserver: Any?
     var backupProgressObserver: Any?
     var configureProgressObserver: Any?
     var configureProgressObserver: Any?
@@ -217,14 +219,16 @@ internal final class SettingsViewController: QuickTableViewController {
                                 }
                                 }
                     }),
                     }),
                     TapActionRow(text: String.localized("autocrypt_send_asm_title"), action: { [weak self] in self?.sendAsm($0) }),
                     TapActionRow(text: String.localized("autocrypt_send_asm_title"), action: { [weak self] in self?.sendAsm($0) }),
+                    TapActionRow(text: String.localized("menu_advanced"),
+                                  action: { [weak self] in self?.showKeyManagementDialog($0) }),
                 ],
                 ],
                 footer: String.localized("autocrypt_explain")
                 footer: String.localized("autocrypt_explain")
             ),
             ),
 
 
             Section(
             Section(
-                title: String.localized("pref_backup"),
+                title: nil,
                 rows: [
                 rows: [
-                    TapActionRow(text: String.localized("export_backup_desktop"), action: { [weak self] in self?.createBackup($0) }),
+                    TapActionRow(text: String.localized("pref_backup"), action: { [weak self] in self?.createBackup($0) }),
                 ],
                 ],
                 footer: String.localized("pref_backup_explain")
                 footer: String.localized("pref_backup_explain")
             ),
             ),
@@ -239,20 +243,47 @@ internal final class SettingsViewController: QuickTableViewController {
         ]
         ]
     }
     }
 
 
+    private func startImex(what: Int32) {
+        let documents = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
+        if !documents.isEmpty {
+            self.hudHandler.showHud(String.localized("one_moment"))
+            DispatchQueue.main.async {
+                self.dcContext.imex(what: what, directory: documents[0])
+            }
+        } else {
+            logger.error("document directory not found")
+        }
+    }
+
     private func createBackup(_: Row) {
     private func createBackup(_: Row) {
         let alert = UIAlertController(title: String.localized("pref_backup_export_explain"), message: nil, preferredStyle: .safeActionSheet)
         let alert = UIAlertController(title: String.localized("pref_backup_export_explain"), message: nil, preferredStyle: .safeActionSheet)
         alert.addAction(UIAlertAction(title: String.localized("pref_backup_export_start_button"), style: .default, handler: { _ in
         alert.addAction(UIAlertAction(title: String.localized("pref_backup_export_start_button"), style: .default, handler: { _ in
             self.dismiss(animated: true, completion: nil)
             self.dismiss(animated: true, completion: nil)
-            let documents = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
-            if !documents.isEmpty {
-                logger.info("create backup in \(documents)")
-                self.hudHandler.showHud(String.localized("one_moment"))
-                DispatchQueue.main.async {
-                    dc_imex(mailboxPointer, DC_IMEX_EXPORT_BACKUP, documents[0], nil)
-                }
-            } else {
-                logger.error("document directory not found")
-            }
+            self.startImex(what: DC_IMEX_EXPORT_BACKUP)
+        }))
+        alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
+        present(alert, animated: true, completion: nil)
+    }
+
+    private func showKeyManagementDialog(_: Row) {
+        let alert = UIAlertController(title: String.localized("pref_manage_keys"), message: nil, preferredStyle: .safeActionSheet)
+        alert.addAction(UIAlertAction(title: String.localized("pref_managekeys_export_secret_keys"), style: .default, handler: { _ in
+            let msg = String.localizedStringWithFormat(String.localized("pref_managekeys_export_explain"), self.externalPathDescr)
+            let alert = UIAlertController(title: nil, message: msg, preferredStyle: .alert)
+            alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: { _ in
+              self.startImex(what: DC_IMEX_EXPORT_SELF_KEYS)
+            }))
+            alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
+            self.present(alert, animated: true, completion: nil)
+        }))
+        alert.addAction(UIAlertAction(title: String.localized("pref_managekeys_import_secret_keys"), style: .default, handler: { _ in
+            let msg = String.localizedStringWithFormat(String.localized("pref_managekeys_import_explain"), self.externalPathDescr)
+            let alert = UIAlertController(title: nil, message: msg, preferredStyle: .alert)
+            alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: { _ in
+                self.startImex(what: DC_IMEX_IMPORT_SELF_KEYS)
+            }))
+            alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
+            self.present(alert, animated: true, completion: nil)
         }))
         }))
         alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
         alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
         present(alert, animated: true, completion: nil)
         present(alert, animated: true, completion: nil)

+ 4 - 0
deltachat-ios/DC/Wrapper.swift

@@ -208,6 +208,10 @@ class DcContext {
         guard let dcProviderPointer = dc_provider_new_from_email(contextPointer, addr) else { return nil }
         guard let dcProviderPointer = dc_provider_new_from_email(contextPointer, addr) else { return nil }
         return DcProvider(dcProviderPointer)
         return DcProvider(dcProviderPointer)
     }
     }
+
+    func imex(what: Int32, directory: String) {
+        dc_imex(contextPointer, what, directory, nil)
+    }
 }
 }
 
 
 class DcConfig {
 class DcConfig {

+ 2 - 0
deltachat-ios/Handler/HudHandler.swift

@@ -47,6 +47,8 @@ class HudHandler {
         let delay = 1.0
         let delay = 1.0
 
 
         if let hud = self.backupHud {
         if let hud = self.backupHud {
+            hud.setProgress(1.0, animated: true)
+            hud.detailTextLabel.text = "100%"
             DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(500)) {
             DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(500)) {
                 UIView.animate(
                 UIView.animate(
                     withDuration: 0.1, animations: {
                     withDuration: 0.1, animations: {