Skip to content

Commit

Permalink
Allow internal builds to access cloud backup file export/import
Browse files Browse the repository at this point in the history
  • Loading branch information
harry-signal committed Oct 20, 2023
1 parent 28da6b9 commit b1b1f8c
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,88 @@ class TestingViewController: OWSTableViewController2 {
}
}

if FeatureFlags.cloudBackupFileAlpha {
let section = OWSTableSection()
section.footerTitle = "Backup File (pre-pre-pre-alpha)"
section.add(OWSTableItem.actionItem(withText: LocalizationNotNeeded("Create backup file")) {
Self.createCloudBackupProto()
})
section.add(OWSTableItem.actionItem(withText: LocalizationNotNeeded("Import backup file")) { [weak self] in
self?.importCloudBackupProto()
})
contents.add(section)
}

self.contents = contents
}
}

extension TestingViewController {

private static func createCloudBackupProto() {
let vc = UIApplication.shared.frontmostViewController!
ModalActivityIndicatorViewController.present(fromViewController: vc, canCancel: false, backgroundBlock: { modal in
Task {
do {
let fileUrl = try await DependenciesBridge.shared.cloudBackupManager.createBackup()
await MainActor.run {
let activityVC = UIActivityViewController(
activityItems: [fileUrl],
applicationActivities: nil
)
let vc = UIApplication.shared.frontmostViewController!
activityVC.popoverPresentationController?.sourceView = vc.view
activityVC.completionWithItemsHandler = { _, _, _, _ in
modal.dismiss()
}
vc.present(activityVC, animated: true)
}
} catch {
// Do nothing
modal.dismiss()
}
}
})
}

private func importCloudBackupProto() {
let vc = UIApplication.shared.frontmostViewController!
guard #available(iOS 14.0, *) else {
return
}
let documentPicker = UIDocumentPickerViewController(forOpeningContentTypes: [.item], asCopy: true)
documentPicker.delegate = self
documentPicker.allowsMultipleSelection = false
vc.present(documentPicker, animated: true)
}
}

extension TestingViewController: UIDocumentPickerDelegate {

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
guard let fileUrl = urls.first else {
return
}
let vc = UIApplication.shared.frontmostViewController!
ModalActivityIndicatorViewController.present(fromViewController: vc, canCancel: false, backgroundBlock: { modal in
Task {
do {
try await DependenciesBridge.shared.cloudBackupManager.importBackup(fileUrl: fileUrl)
await MainActor.run {
modal.dismiss {
let vc = UIApplication.shared.frontmostViewController!
vc.presentToast(text: "Done!")
}
}
} catch {
await MainActor.run {
modal.dismiss {
let vc = UIApplication.shared.frontmostViewController!
vc.presentToast(text: "Failed!")
}
}
}
}
})
}
}
77 changes: 1 addition & 76 deletions Signal/src/ViewControllers/DebugUI/DebugUIMisc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class DebugUIMisc: NSObject, DebugUIPage, Dependencies {
OWSActionSheets.showConfirmationAlert(
title: "Re-register?",
message: "If you proceed, you will not lose any of your current messages, " +
"but your account will be deactivated until you complete re-registration.",
"but your account will be deactivated until you complete re-registration.",
proceedTitle: "Proceed",
proceedAction: { _ in
DebugUIMisc.reregister()
Expand Down Expand Up @@ -179,14 +179,6 @@ class DebugUIMisc: NSObject, DebugUIPage, Dependencies {

OWSTableItem(title: "Enable edit send education prompt", actionBlock: {
DebugUIMisc.enableEditMessagePromptMessage()
}),

OWSTableItem(title: "Create cloud backup proto", actionBlock: {
DebugUIMisc.createCloudBackupProto()
}),

OWSTableItem(title: "Import cloud backup proto", actionBlock: { [weak self] in
self?.importCloudBackupProto()
})
]
return OWSTableSection(title: name, items: items)
Expand Down Expand Up @@ -519,73 +511,6 @@ class DebugUIMisc: NSObject, DebugUIPage, Dependencies {
)
}
}

private static func createCloudBackupProto() {
let vc = UIApplication.shared.frontmostViewController!
ModalActivityIndicatorViewController.present(fromViewController: vc, canCancel: false, backgroundBlock: { modal in
Task {
do {
let fileUrl = try await DependenciesBridge.shared.cloudBackupManager.createBackup()
await MainActor.run {
let activityVC = UIActivityViewController(
activityItems: [fileUrl],
applicationActivities: nil
)
let vc = UIApplication.shared.frontmostViewController!
activityVC.popoverPresentationController?.sourceView = vc.view
activityVC.completionWithItemsHandler = { _, _, _, _ in
modal.dismiss()
}
vc.present(activityVC, animated: true)
}
} catch {
// Do nothing
await modal.dismiss()
}
}
})
}

private func importCloudBackupProto() {
let vc = UIApplication.shared.frontmostViewController!
guard #available(iOS 14.0, *) else {
return
}
let documentPicker = UIDocumentPickerViewController(forOpeningContentTypes: [.item], asCopy: true)
documentPicker.delegate = self
documentPicker.allowsMultipleSelection = false
vc.present(documentPicker, animated: true)
}
}

extension DebugUIMisc: UIDocumentPickerDelegate {

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
guard let fileUrl = urls.first else {
return
}
let vc = UIApplication.shared.frontmostViewController!
ModalActivityIndicatorViewController.present(fromViewController: vc, canCancel: false, backgroundBlock: { modal in
Task {
do {
try await DependenciesBridge.shared.cloudBackupManager.importBackup(fileUrl: fileUrl)
await MainActor.run {
modal.dismiss {
let vc = UIApplication.shared.frontmostViewController!
vc.presentToast(text: "Done!")
}
}
} catch {
await MainActor.run {
modal.dismiss {
let vc = UIApplication.shared.frontmostViewController!
vc.presentToast(text: "Failed!")
}
}
}
}
})
}
}

#endif

0 comments on commit b1b1f8c

Please sign in to comment.