Переглянути джерело

call receiveBackup for transferring backups via QR code

B. Petersen 2 роки тому
батько
коміт
a2c6007387

+ 4 - 0
DcCore/DcCore/DC/Wrapper.swift

@@ -347,6 +347,10 @@ public class DcContext {
         return dc_set_config_from_qr(contextPointer, qrCode) != 0
     }
 
+    public func receiveBackup(qrCode: String) -> Bool {
+        return dc_receive_backup(contextPointer, qrCode) != 0
+    }
+
     public func stopOngoingProcess() {
         dc_stop_ongoing_process(contextPointer)
     }

+ 41 - 2
deltachat-ios/Controller/AccountSetup/WelcomeViewController.swift

@@ -305,7 +305,11 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler {
                         self.dcContext = self.dcAccounts.getSelected()
                         self.navigationItem.title = String.localized(self.canCancel ? "add_account" : "welcome_desktop")
                     }
-                    self.updateProgressAlert(error: ui["errorMessage"] as? String)
+                    var error = ui["errorMessage"] as? String ?? ""
+                    if error.isEmpty {
+                        error = self.dcContext.lastErrorString
+                    }
+                    self.updateProgressAlert(error: error)
                     self.stopAccessingSecurityScopedResource()
                     self.removeBackupProgressObserver()
                 } else if let done = ui["done"] as? Bool, done {
@@ -333,6 +337,8 @@ extension WelcomeViewController: QrCodeReaderDelegate {
                 String.localized(dcAccounts.getAll().count > 1 ? "qrlogin_ask_login_another" : "qrlogin_ask_login"),
                 email)
             confirmQrAccountAlert(title: title, qrCode: code)
+        } else if lot.state == DC_QR_BACKUP {
+             confirmSetupNewDevice(qrCode: code)
         } else {
             qrErrorAlert()
         }
@@ -374,6 +380,39 @@ extension WelcomeViewController: QrCodeReaderDelegate {
         }
     }
 
+    private func confirmSetupNewDevice(qrCode: String) {
+        // triggerLocalNetworkPrivacyAlert() // TODO: is that needed with new iroh?
+        let alert = UIAlertController(title: String.localized("add_another_device"),
+                                      message: String.localized("scan_other_device_explain"),
+                                      preferredStyle: .alert)
+        alert.addAction(UIAlertAction(
+             title: String.localized("ok"),
+             style: .default,
+             handler: { [weak self] _ in
+                 guard let self = self else { return }
+                 self.dismissQRReader()
+                 self.addProgressHudBackupListener()
+                 self.showProgressAlert(title: String.localized("add_another_device"), dcContext: self.dcContext)
+                 self.dcAccounts.stopIo() // TODO: is this needed?
+                 DispatchQueue.global(qos: .userInitiated).async { [weak self] in
+                     guard let self = self else { return }
+                     self.dcContext.logger?.info("##### receiveBackup() with qr: \(qrCode)")
+                     let res = self.dcContext.receiveBackup(qrCode: qrCode)
+                     self.dcContext.logger?.info("##### receiveBackup() done with result: \(res)")
+                 }
+             }
+        ))
+        alert.addAction(UIAlertAction(
+            title: String.localized("cancel"),
+            style: .cancel,
+            handler: { [weak self] _ in
+                self?.dcContext.stopOngoingProcess()
+                self?.dismissQRReader()
+            }
+        ))
+        qrCodeReader?.present(alert, animated: true)
+    }
+
     private func qrErrorAlert() {
         let title = String.localized("qraccount_qr_code_cannot_be_used")
         let alert = UIAlertController(title: title, message: dcContext.lastErrorString, preferredStyle: .alert)
@@ -470,7 +509,7 @@ class WelcomeContentView: UIView {
 
     private lazy var qrCodeButton: UIButton = {
         let button = UIButton()
-        let title = String.localized("scan_invitation_code")
+        let title = String.localized("qrscan_title")
         button.setTitleColor(UIColor.systemBlue, for: .normal)
         button.setTitle(title, for: .normal)
         button.addTarget(self, action: #selector(qrCodeButtonPressed(_:)), for: .touchUpInside)

+ 1 - 1
deltachat-ios/Controller/QrPageController.swift

@@ -233,7 +233,7 @@ extension QrPageController: QrCodeReaderDelegate {
             }))
             present(alert, animated: true, completion: nil)
 
-        case DC_QR_ACCOUNT, DC_QR_LOGIN:
+        case DC_QR_ACCOUNT, DC_QR_LOGIN, DC_QR_BACKUP:
             if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
                 appDelegate.appCoordinator.presentWelcomeController(accountCode: code)
             }

+ 1 - 0
deltachat-ios/en.lproj/Localizable.strings

@@ -994,3 +994,4 @@
 "backup_successful_explain_ios" = "You can find the backup in the \"Delta Chat\" folder using the \"Files\" app.\n\nMove the backup out of this folder to keep it when deleting Delta Chat.";
 "add_another_device" = "Add Another Device";
 "add_another_device_explain" = "Add another device for this account";
+"scan_other_device_explain" = "Copy the account from the other device to this device? The original device is not changed.";

+ 1 - 0
scripts/untranslated.xml

@@ -9,4 +9,5 @@
     <string name="backup_successful_explain_ios">You can find the backup in the \"Delta Chat\" folder using the \"Files\" app.\n\nMove the backup out of this folder to keep it when deleting Delta Chat.</string>
     <string name="add_another_device">Add Another Device</string>
     <string name="add_another_device_explain">Add another device for this account</string>
+    <string name="scan_other_device_explain">Copy the account from the other device to this device? The original device is not changed.</string>
 </resources>