aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-01-04 16:25:57 +0530
committerRoopesh Chander <roop@roopc.net>2019-01-14 14:52:32 +0530
commit361830a69e9fe0fdfb638971dff87660644531d8 (patch)
tree769e002bebe620e3146cf54d058b3022fe445f11 /WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
parentmacOS: Xcode: Add ablity to save files (diff)
downloadwireguard-apple-361830a69e9fe0fdfb638971dff87660644531d8.tar.xz
wireguard-apple-361830a69e9fe0fdfb638971dff87660644531d8.zip
macOS: Manage tunnels: Export tunnels pulldown menu implementation
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift21
1 files changed, 20 insertions, 1 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
index 310d13ab..9bdcceae 100644
--- a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
+++ b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
@@ -146,8 +146,27 @@ class TunnelsListTableViewController: NSViewController {
@objc func exportLogClicked() {
print("exportLogClicked")
}
+
@objc func exportTunnelsClicked() {
- print("exportTunnelsClicked")
+ guard let window = view.window else { return }
+ let savePanel = NSSavePanel()
+ savePanel.allowedFileTypes = ["zip"]
+ savePanel.prompt = "Save"
+ savePanel.nameFieldLabel = "Export tunnels to"
+ savePanel.nameFieldStringValue = "wireguard-export.zip"
+ savePanel.beginSheetModal(for: window) { [weak tunnelsManager] response in
+ guard let tunnelsManager = tunnelsManager else { return }
+ guard response == .OK else { return }
+ guard let destinationURL = savePanel.url else { return }
+ let count = tunnelsManager.numberOfTunnels()
+ let tunnelConfigurations = (0 ..< count).compactMap { tunnelsManager.tunnel(at: $0).tunnelConfiguration }
+ ZipExporter.exportConfigFiles(tunnelConfigurations: tunnelConfigurations, to: destinationURL) { [weak self] error in
+ if let error = error {
+ ErrorPresenter.showErrorAlert(error: error, from: self)
+ return
+ }
+ }
+ }
}
@discardableResult