macOS: Manage tunnels: Handle the case when there are no tunnels
This commit is contained in:
parent
eddfee90f1
commit
4b4fa6519a
|
@ -117,6 +117,7 @@
|
||||||
6FBA104021D6B7040051C35F /* ErrorPresenterProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FBA103A21D6B4280051C35F /* ErrorPresenterProtocol.swift */; };
|
6FBA104021D6B7040051C35F /* ErrorPresenterProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FBA103A21D6B4280051C35F /* ErrorPresenterProtocol.swift */; };
|
||||||
6FBA104321D6BC250051C35F /* ErrorPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FBA104121D6BC210051C35F /* ErrorPresenter.swift */; };
|
6FBA104321D6BC250051C35F /* ErrorPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FBA104121D6BC210051C35F /* ErrorPresenter.swift */; };
|
||||||
6FBA104621D7EBFA0051C35F /* TunnelsListTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FBA104521D7EBFA0051C35F /* TunnelsListTableViewController.swift */; };
|
6FBA104621D7EBFA0051C35F /* TunnelsListTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FBA104521D7EBFA0051C35F /* TunnelsListTableViewController.swift */; };
|
||||||
|
6FCD99AA21E0E14700BA4C82 /* NoTunnelsDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FCD99A821E0E0C700BA4C82 /* NoTunnelsDetailViewController.swift */; };
|
||||||
6FDB3C3B21DCF47400A0C0BF /* TunnelDetailTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FDB3C3A21DCF47400A0C0BF /* TunnelDetailTableViewController.swift */; };
|
6FDB3C3B21DCF47400A0C0BF /* TunnelDetailTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FDB3C3A21DCF47400A0C0BF /* TunnelDetailTableViewController.swift */; };
|
||||||
6FDB3C3C21DCF6BB00A0C0BF /* TunnelViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F628C3C217F09E9003482A3 /* TunnelViewModel.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 */; };
|
6FDEF7E421846C1A00D8FBF6 /* libwg-go.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6FDEF7E321846C1A00D8FBF6 /* libwg-go.a */; };
|
||||||
|
@ -270,6 +271,7 @@
|
||||||
6FBA103D21D6B6D70051C35F /* TunnelImporter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TunnelImporter.swift; sourceTree = "<group>"; };
|
6FBA103D21D6B6D70051C35F /* TunnelImporter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TunnelImporter.swift; sourceTree = "<group>"; };
|
||||||
6FBA104121D6BC210051C35F /* ErrorPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorPresenter.swift; sourceTree = "<group>"; };
|
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>"; };
|
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>"; };
|
||||||
6FDB3C3A21DCF47400A0C0BF /* TunnelDetailTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TunnelDetailTableViewController.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; };
|
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>"; };
|
6FDEF7E52185EFAF00D8FBF6 /* QRScanViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QRScanViewController.swift; sourceTree = "<group>"; };
|
||||||
|
@ -506,6 +508,7 @@
|
||||||
6FBA104521D7EBFA0051C35F /* TunnelsListTableViewController.swift */,
|
6FBA104521D7EBFA0051C35F /* TunnelsListTableViewController.swift */,
|
||||||
6F4DD16D21DBEA0700690EAE /* ManageTunnelsRootViewController.swift */,
|
6F4DD16D21DBEA0700690EAE /* ManageTunnelsRootViewController.swift */,
|
||||||
6FDB3C3A21DCF47400A0C0BF /* TunnelDetailTableViewController.swift */,
|
6FDB3C3A21DCF47400A0C0BF /* TunnelDetailTableViewController.swift */,
|
||||||
|
6FCD99A821E0E0C700BA4C82 /* NoTunnelsDetailViewController.swift */,
|
||||||
);
|
);
|
||||||
path = ViewController;
|
path = ViewController;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
@ -1086,6 +1089,7 @@
|
||||||
6FB1BDC121D50F0200A991BF /* String+ArrayConversion.swift in Sources */,
|
6FB1BDC121D50F0200A991BF /* String+ArrayConversion.swift in Sources */,
|
||||||
6FB1BDC221D50F0300A991BF /* LegacyConfigMigration.swift in Sources */,
|
6FB1BDC221D50F0300A991BF /* LegacyConfigMigration.swift in Sources */,
|
||||||
6FBA104021D6B7040051C35F /* ErrorPresenterProtocol.swift in Sources */,
|
6FBA104021D6B7040051C35F /* ErrorPresenterProtocol.swift in Sources */,
|
||||||
|
6FCD99AA21E0E14700BA4C82 /* NoTunnelsDetailViewController.swift in Sources */,
|
||||||
6FB1BDC321D50F0300A991BF /* TunnelConfiguration.swift in Sources */,
|
6FB1BDC321D50F0300A991BF /* TunnelConfiguration.swift in Sources */,
|
||||||
6FB1BDC421D50F0300A991BF /* IPAddressRange.swift in Sources */,
|
6FB1BDC421D50F0300A991BF /* IPAddressRange.swift in Sources */,
|
||||||
6FBA104321D6BC250051C35F /* ErrorPresenter.swift in Sources */,
|
6FBA104321D6BC250051C35F /* ErrorPresenter.swift in Sources */,
|
||||||
|
|
|
@ -242,6 +242,8 @@
|
||||||
"macDeleteTunnelConfirmationAlertButtonTitleDelete" = "Delete";
|
"macDeleteTunnelConfirmationAlertButtonTitleDelete" = "Delete";
|
||||||
"macDeleteTunnelConfirmationAlertButtonTitleCancel" = "Cancel";
|
"macDeleteTunnelConfirmationAlertButtonTitleCancel" = "Cancel";
|
||||||
|
|
||||||
|
"macButtonImportTunnels" = "Import tunnel(s) from file";
|
||||||
|
|
||||||
// Mac detail view fields
|
// Mac detail view fields
|
||||||
|
|
||||||
"macDetailFieldKey (%@)" = "%@:";
|
"macDetailFieldKey (%@)" = "%@:";
|
||||||
|
|
|
@ -82,7 +82,8 @@ extension ManageTunnelsRootViewController: TunnelsListTableViewControllerDelegat
|
||||||
setTunnelDetailContentVC(tunnelDetailVC)
|
setTunnelDetailContentVC(tunnelDetailVC)
|
||||||
}
|
}
|
||||||
|
|
||||||
func tunnelListEmpty() {
|
func tunnelsListEmpty() {
|
||||||
// TODO
|
let noTunnelsVC = NoTunnelsDetailViewController(tunnelsManager: tunnelsManager)
|
||||||
|
setTunnelDetailContentVC(noTunnelsVC)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
|
import Cocoa
|
||||||
|
|
||||||
|
class NoTunnelsDetailViewController: NSViewController {
|
||||||
|
|
||||||
|
let tunnelsManager: TunnelsManager
|
||||||
|
|
||||||
|
let importButton: NSButton = {
|
||||||
|
let button = NSButton()
|
||||||
|
button.title = tr("macButtonImportTunnels")
|
||||||
|
button.setButtonType(.momentaryPushIn)
|
||||||
|
button.bezelStyle = .rounded
|
||||||
|
return button
|
||||||
|
}()
|
||||||
|
|
||||||
|
init(tunnelsManager: TunnelsManager) {
|
||||||
|
self.tunnelsManager = tunnelsManager
|
||||||
|
super.init(nibName: nil, bundle: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder: NSCoder) {
|
||||||
|
fatalError("init(coder:) has not been implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override func loadView() {
|
||||||
|
let view = NSView()
|
||||||
|
|
||||||
|
importButton.target = self
|
||||||
|
importButton.action = #selector(importTunnelClicked)
|
||||||
|
|
||||||
|
view.addSubview(importButton)
|
||||||
|
importButton.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
NSLayoutConstraint.activate([
|
||||||
|
importButton.centerXAnchor.constraint(equalTo: view.centerXAnchor),
|
||||||
|
importButton.centerYAnchor.constraint(equalTo: view.centerYAnchor)
|
||||||
|
])
|
||||||
|
self.view = view
|
||||||
|
}
|
||||||
|
|
||||||
|
@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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,7 +5,7 @@ import Cocoa
|
||||||
|
|
||||||
protocol TunnelsListTableViewControllerDelegate: class {
|
protocol TunnelsListTableViewControllerDelegate: class {
|
||||||
func tunnelSelected(tunnel: TunnelContainer)
|
func tunnelSelected(tunnel: TunnelContainer)
|
||||||
func tunnelListEmpty()
|
func tunnelsListEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
class TunnelsListTableViewController: NSViewController {
|
class TunnelsListTableViewController: NSViewController {
|
||||||
|
@ -61,7 +61,10 @@ class TunnelsListTableViewController: NSViewController {
|
||||||
override func loadView() {
|
override func loadView() {
|
||||||
tableView.dataSource = self
|
tableView.dataSource = self
|
||||||
tableView.delegate = self
|
tableView.delegate = self
|
||||||
selectTunnel(at: 0)
|
let isSelected = selectTunnel(at: 0)
|
||||||
|
if !isSelected {
|
||||||
|
delegate?.tunnelsListEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
let scrollView = NSScrollView()
|
let scrollView = NSScrollView()
|
||||||
scrollView.hasVerticalScroller = true
|
scrollView.hasVerticalScroller = true
|
||||||
|
@ -246,6 +249,9 @@ extension TunnelsListTableViewController {
|
||||||
|
|
||||||
func tunnelRemoved(at index: Int) {
|
func tunnelRemoved(at index: Int) {
|
||||||
tableView.removeRows(at: IndexSet(integer: index), withAnimation: .slideLeft)
|
tableView.removeRows(at: IndexSet(integer: index), withAnimation: .slideLeft)
|
||||||
|
if tunnelsManager.numberOfTunnels() == 0 {
|
||||||
|
delegate?.tunnelsListEmpty()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,12 +269,7 @@ extension TunnelsListTableViewController: NSTableViewDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
func tableViewSelectionDidChange(_ notification: Notification) {
|
func tableViewSelectionDidChange(_ notification: Notification) {
|
||||||
guard tableView.selectedRow >= 0 else {
|
guard tableView.selectedRow >= 0 else { return }
|
||||||
if tunnelsManager.numberOfTunnels() == 0 {
|
|
||||||
delegate?.tunnelListEmpty()
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
let selectedTunnel = tunnelsManager.tunnel(at: tableView.selectedRow)
|
let selectedTunnel = tunnelsManager.tunnel(at: tableView.selectedRow)
|
||||||
delegate?.tunnelSelected(tunnel: selectedTunnel)
|
delegate?.tunnelSelected(tunnel: selectedTunnel)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue