aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-12-08 01:21:46 +0530
committerRoopesh Chander <roop@roopc.net>2018-12-08 02:17:55 +0530
commit71568d1899d9f0802c6e75a1c58b1545c6da9274 (patch)
treeecbbc3c81da076ca850ff1e0710692829eb02ae4 /WireGuard/WireGuard/UI
parentOn-Demand: TunnelViewModel: Make activate-on-demand methods static (diff)
downloadwireguard-apple-71568d1899d9f0802c6e75a1c58b1545c6da9274.tar.xz
wireguard-apple-71568d1899d9f0802c6e75a1c58b1545c6da9274.zip
Settings: Export log: Perform file operations in a background thread
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard/UI')
-rw-r--r--WireGuard/WireGuard/UI/iOS/SettingsTableViewController.swift57
1 files changed, 31 insertions, 26 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/SettingsTableViewController.swift b/WireGuard/WireGuard/UI/iOS/SettingsTableViewController.swift
index 6623f79..d9675bb 100644
--- a/WireGuard/WireGuard/UI/iOS/SettingsTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/SettingsTableViewController.swift
@@ -96,37 +96,42 @@ class SettingsTableViewController: UITableViewController {
let timeStampString = dateFormatter.string(from: Date())
let destinationURL = destinationDir.appendingPathComponent("wireguard-log-\(timeStampString).txt")
- if (FileManager.default.fileExists(atPath: destinationURL.path)) {
- let isDeleted = FileManager.deleteFile(at: destinationURL)
- if (!isDeleted) {
- ErrorPresenter.showErrorAlert(title: "No log available", message: "The pre-existing log could not be cleared", from: self)
- return
+ DispatchQueue.global(qos: .userInitiated).async {
+
+ if (FileManager.default.fileExists(atPath: destinationURL.path)) {
+ let isDeleted = FileManager.deleteFile(at: destinationURL)
+ if (!isDeleted) {
+ ErrorPresenter.showErrorAlert(title: "No log available", message: "The pre-existing log could not be cleared", from: self)
+ return
+ }
}
- }
- guard let networkExtensionLogFileURL = FileManager.networkExtensionLogFileURL,
- FileManager.default.fileExists(atPath: networkExtensionLogFileURL.path) else {
- ErrorPresenter.showErrorAlert(title: "No log available", message: "Please activate a tunnel and then export the log", from: self)
- return
- }
+ guard let networkExtensionLogFileURL = FileManager.networkExtensionLogFileURL,
+ FileManager.default.fileExists(atPath: networkExtensionLogFileURL.path) else {
+ ErrorPresenter.showErrorAlert(title: "No log available", message: "Please activate a tunnel and then export the log", from: self)
+ return
+ }
- do {
- try FileManager.default.copyItem(at: networkExtensionLogFileURL, to: destinationURL)
- } catch {
- os_log("Failed to copy file: %{public}@ to %{public}@: %{public}@", log: OSLog.default, type: .error, networkExtensionLogFileURL.absoluteString, destinationURL.absoluteString, error.localizedDescription)
- ErrorPresenter.showErrorAlert(title: "Log export failed", message: "The log could not be copied", from: self)
- return
- }
+ do {
+ try FileManager.default.copyItem(at: networkExtensionLogFileURL, to: destinationURL)
+ } catch {
+ os_log("Failed to copy file: %{public}@ to %{public}@: %{public}@", log: OSLog.default, type: .error, networkExtensionLogFileURL.absoluteString, destinationURL.absoluteString, error.localizedDescription)
+ ErrorPresenter.showErrorAlert(title: "Log export failed", message: "The log could not be copied", from: self)
+ return
+ }
- let activityVC = UIActivityViewController(activityItems: [destinationURL], applicationActivities: nil)
- // popoverPresentationController shall be non-nil on the iPad
- activityVC.popoverPresentationController?.sourceView = sourceView
- activityVC.popoverPresentationController?.sourceRect = sourceView.bounds
- activityVC.completionWithItemsHandler = { (_, _, _, _) in
- // Remove the exported log file after the activity has completed
- _ = FileManager.deleteFile(at: destinationURL)
+ DispatchQueue.main.async {
+ let activityVC = UIActivityViewController(activityItems: [destinationURL], applicationActivities: nil)
+ // popoverPresentationController shall be non-nil on the iPad
+ activityVC.popoverPresentationController?.sourceView = sourceView
+ activityVC.popoverPresentationController?.sourceRect = sourceView.bounds
+ activityVC.completionWithItemsHandler = { (_, _, _, _) in
+ // Remove the exported log file after the activity has completed
+ _ = FileManager.deleteFile(at: destinationURL)
+ }
+ self.present(activityVC, animated: true)
+ }
}
- self.present(activityVC, animated: true)
}
}