macOS: Manage tunnels: Export tunnels pulldown menu implementation

Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
Roopesh Chander 2019-01-04 16:25:57 +05:30
parent f6ea25573b
commit 361830a69e
1 changed files with 20 additions and 1 deletions

View File

@ -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