aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-01-05 19:16:16 +0530
committerRoopesh Chander <roop@roopc.net>2019-01-14 14:52:33 +0530
commitcb778fe7e0bb27c33f2f4efc83d03e5f696c979f (patch)
tree9f13a1ed4548a35b98ee3af02f40e3b4139c64fd /WireGuard/WireGuard/UI
parentmacOS: Manage tunnels: Handle the case when there are no tunnels (diff)
downloadwireguard-apple-cb778fe7e0bb27c33f2f4efc83d03e5f696c979f.tar.xz
wireguard-apple-cb778fe7e0bb27c33f2f4efc83d03e5f696c979f.zip
macOS: Consolidate presenting of the import panel
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuard/UI/macOS/ImportPanelPresenter.swift18
-rw-r--r--WireGuard/WireGuard/UI/macOS/StatusMenu.swift9
-rw-r--r--WireGuard/WireGuard/UI/macOS/ViewController/NoTunnelsDetailViewController.swift10
-rw-r--r--WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift10
4 files changed, 21 insertions, 26 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/ImportPanelPresenter.swift b/WireGuard/WireGuard/UI/macOS/ImportPanelPresenter.swift
new file mode 100644
index 0000000..b1ed2f5
--- /dev/null
+++ b/WireGuard/WireGuard/UI/macOS/ImportPanelPresenter.swift
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: MIT
+// Copyright © 2018 WireGuard LLC. All Rights Reserved.
+
+import Cocoa
+
+class ImportPanelPresenter {
+ static func presentImportPanel(tunnelsManager: TunnelsManager, sourceVC: NSViewController) {
+ guard let window = sourceVC.view.window else { return }
+ let openPanel = NSOpenPanel()
+ openPanel.allowedFileTypes = ["conf", "zip"]
+ openPanel.beginSheetModal(for: window) { [weak tunnelsManager] response in
+ guard let tunnelsManager = tunnelsManager else { return }
+ guard response == .OK else { return }
+ guard let url = openPanel.url else { return }
+ TunnelImporter.importFromFile(url: url, into: tunnelsManager, sourceVC: sourceVC, errorPresenterType: ErrorPresenter.self)
+ }
+ }
+}
diff --git a/WireGuard/WireGuard/UI/macOS/StatusMenu.swift b/WireGuard/WireGuard/UI/macOS/StatusMenu.swift
index b8693c9..39c0f32 100644
--- a/WireGuard/WireGuard/UI/macOS/StatusMenu.swift
+++ b/WireGuard/WireGuard/UI/macOS/StatusMenu.swift
@@ -132,14 +132,7 @@ class StatusMenu: NSMenu {
@objc func importTunnelsClicked() {
NSApp.activate(ignoringOtherApps: true)
manageTunnelsWindow.makeKeyAndOrderFront(self)
- let openPanel = NSOpenPanel()
- openPanel.allowedFileTypes = ["conf", "zip"]
- openPanel.beginSheetModal(for: manageTunnelsWindow) { [weak tunnelsManager] response in
- guard let tunnelsManager = tunnelsManager else { return }
- guard response == .OK else { return }
- guard let url = openPanel.url else { return }
- TunnelImporter.importFromFile(url: url, into: tunnelsManager, sourceVC: nil, errorPresenterType: ErrorPresenter.self)
- }
+ ImportPanelPresenter.presentImportPanel(tunnelsManager: tunnelsManager, sourceVC: manageTunnelsRootVC!)
}
}
diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/NoTunnelsDetailViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/NoTunnelsDetailViewController.swift
index 059403a..ac57422 100644
--- a/WireGuard/WireGuard/UI/macOS/ViewController/NoTunnelsDetailViewController.swift
+++ b/WireGuard/WireGuard/UI/macOS/ViewController/NoTunnelsDetailViewController.swift
@@ -40,14 +40,6 @@ class NoTunnelsDetailViewController: NSViewController {
}
@objc func importTunnelClicked() {
- guard let window = view.window else { return }
- let openPanel = NSOpenPanel()
- openPanel.allowedFileTypes = ["conf", "zip"]
- openPanel.beginSheetModal(for: window) { [weak tunnelsManager] response in
- guard let tunnelsManager = tunnelsManager else { return }
- guard response == .OK else { return }
- guard let url = openPanel.url else { return }
- TunnelImporter.importFromFile(url: url, into: tunnelsManager, sourceVC: nil, errorPresenterType: ErrorPresenter.self)
- }
+ ImportPanelPresenter.presentImportPanel(tunnelsManager: tunnelsManager, sourceVC: self)
}
}
diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
index dff583a..0937453 100644
--- a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
+++ b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
@@ -131,15 +131,7 @@ class TunnelsListTableViewController: NSViewController {
}
@objc func importTunnelClicked() {
- guard let window = view.window else { return }
- let openPanel = NSOpenPanel()
- openPanel.allowedFileTypes = ["conf", "zip"]
- openPanel.beginSheetModal(for: window) { [weak tunnelsManager] response in
- guard let tunnelsManager = tunnelsManager else { return }
- guard response == .OK else { return }
- guard let url = openPanel.url else { return }
- TunnelImporter.importFromFile(url: url, into: tunnelsManager, sourceVC: nil, errorPresenterType: ErrorPresenter.self)
- }
+ ImportPanelPresenter.presentImportPanel(tunnelsManager: tunnelsManager, sourceVC: self)
}
@objc func removeTunnelClicked() {