Skip to content

Commit

Permalink
call receiveBackup for transferring backups via QR code
Browse files Browse the repository at this point in the history
  • Loading branch information
r10s committed Mar 19, 2023
1 parent 43003db commit c964088
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
4 changes: 4 additions & 0 deletions DcCore/DcCore/DC/Wrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
43 changes: 41 additions & 2 deletions deltachat-ios/Controller/AccountSetup/WelcomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion deltachat-ios/Controller/QrPageController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions deltachat-ios/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -964,3 +964,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 change: 1 addition & 0 deletions scripts/untranslated.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit c964088

Please sign in to comment.