macOS: Manage tunnels: Export tunnels pulldown menu implementation
Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
parent
f6ea25573b
commit
361830a69e
|
@ -146,8 +146,27 @@ class TunnelsListTableViewController: NSViewController {
|
||||||
@objc func exportLogClicked() {
|
@objc func exportLogClicked() {
|
||||||
print("exportLogClicked")
|
print("exportLogClicked")
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func exportTunnelsClicked() {
|
@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
|
@discardableResult
|
||||||
|
|
Loading…
Reference in New Issue