aboutsummaryrefslogtreecommitdiffstats
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
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.xcodeproj/project.pbxproj4
-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
5 files changed, 25 insertions, 26 deletions
diff --git a/WireGuard/WireGuard.xcodeproj/project.pbxproj b/WireGuard/WireGuard.xcodeproj/project.pbxproj
index 7ad1bbf5..e9a9a213 100644
--- a/WireGuard/WireGuard.xcodeproj/project.pbxproj
+++ b/WireGuard/WireGuard.xcodeproj/project.pbxproj
@@ -118,6 +118,7 @@
6FBA104321D6BC250051C35F /* ErrorPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FBA104121D6BC210051C35F /* ErrorPresenter.swift */; };
6FBA104621D7EBFA0051C35F /* TunnelsListTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FBA104521D7EBFA0051C35F /* TunnelsListTableViewController.swift */; };
6FCD99AA21E0E14700BA4C82 /* NoTunnelsDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FCD99A821E0E0C700BA4C82 /* NoTunnelsDetailViewController.swift */; };
+ 6FCD99AF21E0EA1700BA4C82 /* ImportPanelPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FCD99AE21E0EA1700BA4C82 /* ImportPanelPresenter.swift */; };
6FDB3C3B21DCF47400A0C0BF /* TunnelDetailTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FDB3C3A21DCF47400A0C0BF /* TunnelDetailTableViewController.swift */; };
6FDB3C3C21DCF6BB00A0C0BF /* TunnelViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F628C3C217F09E9003482A3 /* TunnelViewModel.swift */; };
6FDEF7E421846C1A00D8FBF6 /* libwg-go.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6FDEF7E321846C1A00D8FBF6 /* libwg-go.a */; };
@@ -272,6 +273,7 @@
6FBA104121D6BC210051C35F /* ErrorPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorPresenter.swift; sourceTree = "<group>"; };
6FBA104521D7EBFA0051C35F /* TunnelsListTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TunnelsListTableViewController.swift; sourceTree = "<group>"; };
6FCD99A821E0E0C700BA4C82 /* NoTunnelsDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoTunnelsDetailViewController.swift; sourceTree = "<group>"; };
+ 6FCD99AE21E0EA1700BA4C82 /* ImportPanelPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImportPanelPresenter.swift; sourceTree = "<group>"; };
6FDB3C3A21DCF47400A0C0BF /* TunnelDetailTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TunnelDetailTableViewController.swift; sourceTree = "<group>"; };
6FDEF7E321846C1A00D8FBF6 /* libwg-go.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = "libwg-go.a"; sourceTree = BUILT_PRODUCTS_DIR; };
6FDEF7E52185EFAF00D8FBF6 /* QRScanViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QRScanViewController.swift; sourceTree = "<group>"; };
@@ -494,6 +496,7 @@
6FB1BD5F21D2607A00A991BF /* AppDelegate.swift */,
6FBA101621D655340051C35F /* StatusMenu.swift */,
6FBA104121D6BC210051C35F /* ErrorPresenter.swift */,
+ 6FCD99AE21E0EA1700BA4C82 /* ImportPanelPresenter.swift */,
6FB1BD6121D2607E00A991BF /* Assets.xcassets */,
6FB1BD6621D2607E00A991BF /* Info.plist */,
6FB1BD6721D2607E00A991BF /* WireGuard.entitlements */,
@@ -1066,6 +1069,7 @@
6FB1BDD321D50F5300A991BF /* ZipArchive.swift in Sources */,
6FB1BDD421D50F5300A991BF /* ioapi.c in Sources */,
6FDB3C3C21DCF6BB00A0C0BF /* TunnelViewModel.swift in Sources */,
+ 6FCD99AF21E0EA1700BA4C82 /* ImportPanelPresenter.swift in Sources */,
6FB1BDD521D50F5300A991BF /* unzip.c in Sources */,
6FB1BDD621D50F5300A991BF /* zip.c in Sources */,
6FDB3C3B21DCF47400A0C0BF /* TunnelDetailTableViewController.swift in Sources */,
diff --git a/WireGuard/WireGuard/UI/macOS/ImportPanelPresenter.swift b/WireGuard/WireGuard/UI/macOS/ImportPanelPresenter.swift
new file mode 100644
index 00000000..b1ed2f5c
--- /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 b8693c91..39c0f32b 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 059403a6..ac574221 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 dff583a5..0937453e 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() {