aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-01-04 18:11:49 +0530
committerRoopesh Chander <roop@roopc.net>2019-01-14 14:52:32 +0530
commit60cfceec4fe526214db184cc2175a7940d2b5251 (patch)
tree53fceaf38a5cff80f8dabf5353050669458848d1 /WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
parentmacOS: Manage tunnels: Export tunnels pulldown menu implementation (diff)
downloadwireguard-apple-60cfceec4fe526214db184cc2175a7940d2b5251.tar.xz
wireguard-apple-60cfceec4fe526214db184cc2175a7940d2b5251.zip
macOS: Manage tunnels: Export log pulldown menu implementation
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift31
1 files changed, 30 insertions, 1 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
index 9bdcceae..2d0b6fea 100644
--- a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
+++ b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
@@ -144,7 +144,36 @@ class TunnelsListTableViewController: NSViewController {
}
@objc func exportLogClicked() {
- print("exportLogClicked")
+ guard let window = view.window else { return }
+ let savePanel = NSSavePanel()
+ savePanel.prompt = "Save"
+ savePanel.nameFieldLabel = "Export log to"
+
+ let dateFormatter = ISO8601DateFormatter()
+ dateFormatter.formatOptions = [.withFullDate, .withTime, .withTimeZone] // Avoid ':' in the filename
+ let timeStampString = dateFormatter.string(from: Date())
+ savePanel.nameFieldStringValue = "wireguard-log-\(timeStampString).txt"
+
+ guard let networkExtensionLogFilePath = FileManager.networkExtensionLogFileURL?.path else {
+ ErrorPresenter.showErrorAlert(title: tr("alertUnableToFindExtensionLogPathTitle"), message: tr("alertUnableToFindExtensionLogPathMessage"), from: self)
+ return
+ }
+
+ savePanel.beginSheetModal(for: window) { response in
+ guard response == .OK else { return }
+ guard let destinationURL = savePanel.url else { return }
+
+ DispatchQueue.global(qos: .userInitiated).async {
+ let isWritten = Logger.global?.writeLog(called: "APP", mergedWith: networkExtensionLogFilePath, called: "NET", to: destinationURL.path) ?? false
+ guard isWritten else {
+ DispatchQueue.main.async { [weak self] in
+ ErrorPresenter.showErrorAlert(title: tr("alertUnableToWriteLogTitle"), message: tr("alertUnableToWriteLogMessage"), from: self)
+ }
+ return
+ }
+ }
+
+ }
}
@objc func exportTunnelsClicked() {