aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-03-17 02:26:56 +0530
committerRoopesh Chander <roop@roopc.net>2019-03-17 02:27:46 +0530
commite23c221aff77f7d6dfd6b06bc1199ca0e4bc676c (patch)
tree32293930a29d8fa1c4b758f7424cd20a7ee83986
parentmacOS: Tunnel detail: Show the status in the list view (diff)
downloadwireguard-apple-e23c221aff77f7d6dfd6b06bc1199ca0e4bc676c.tar.xz
wireguard-apple-e23c221aff77f7d6dfd6b06bc1199ca0e4bc676c.zip
macOS: Tunnel detail: Activate / Deactivate is now a button
Signed-off-by: Roopesh Chander <roop@roopc.net>
-rw-r--r--WireGuard/WireGuard/Base.lproj/Localizable.strings8
-rw-r--r--WireGuard/WireGuard/UI/macOS/ViewController/TunnelDetailTableViewController.swift60
2 files changed, 33 insertions, 35 deletions
diff --git a/WireGuard/WireGuard/Base.lproj/Localizable.strings b/WireGuard/WireGuard/Base.lproj/Localizable.strings
index 68a81eb2..55610aaf 100644
--- a/WireGuard/WireGuard/Base.lproj/Localizable.strings
+++ b/WireGuard/WireGuard/Base.lproj/Localizable.strings
@@ -47,6 +47,14 @@
"tunnelStatusRestarting" = "Restarting";
"tunnelStatusWaiting" = "Waiting";
+"macToggleStatusButtonActivate" = "Activate";
+"macToggleStatusButtonActivating" = "Activating…";
+"macToggleStatusButtonDeactivate" = "Deactivate";
+"macToggleStatusButtonDeactivating" = "Deactivating…";
+"macToggleStatusButtonReasserting" = "Reactivating…";
+"macToggleStatusButtonRestarting" = "Restarting…";
+"macToggleStatusButtonWaiting" = "Waiting…";
+
"tunnelSectionTitleInterface" = "Interface";
"tunnelInterfaceName" = "Name";
diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelDetailTableViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelDetailTableViewController.swift
index 82f7706c..fc747a87 100644
--- a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelDetailTableViewController.swift
+++ b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelDetailTableViewController.swift
@@ -51,13 +51,14 @@ class TunnelDetailTableViewController: NSViewController {
return tableView
}()
- let statusCheckbox: NSButton = {
- let checkbox = NSButton()
- checkbox.title = ""
- checkbox.setButtonType(.switch)
- checkbox.state = .off
- checkbox.toolTip = "Toggle status (⌘T)"
- return checkbox
+ let toggleStatusButton: NSButton = {
+ let button = NSButton()
+ button.title = ""
+ button.setButtonType(.momentaryPushIn)
+ button.bezelStyle = .rounded
+ button.toolTip = "Toggle status (⌘T)"
+ button.widthAnchor.constraint(greaterThanOrEqualToConstant: 100).isActive = true
+ return button
}()
let editButton: NSButton = {
@@ -113,8 +114,8 @@ class TunnelDetailTableViewController: NSViewController {
tableView.dataSource = self
tableView.delegate = self
- statusCheckbox.target = self
- statusCheckbox.action = #selector(statusCheckboxToggled(sender:))
+ toggleStatusButton.target = self
+ toggleStatusButton.action = #selector(handleToggleActiveStatusAction)
editButton.target = self
editButton.action = #selector(handleEditTunnelAction)
@@ -133,11 +134,11 @@ class TunnelDetailTableViewController: NSViewController {
containerView.addLayoutGuide(bottomControlsContainer)
containerView.addSubview(box)
containerView.addSubview(scrollView)
- containerView.addSubview(statusCheckbox)
+ containerView.addSubview(toggleStatusButton)
containerView.addSubview(editButton)
box.translatesAutoresizingMaskIntoConstraints = false
scrollView.translatesAutoresizingMaskIntoConstraints = false
- statusCheckbox.translatesAutoresizingMaskIntoConstraints = false
+ toggleStatusButton.translatesAutoresizingMaskIntoConstraints = false
editButton.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
@@ -149,10 +150,10 @@ class TunnelDetailTableViewController: NSViewController {
bottomControlsContainer.heightAnchor.constraint(equalToConstant: 32),
scrollView.bottomAnchor.constraint(equalTo: bottomControlsContainer.topAnchor),
bottomControlsContainer.bottomAnchor.constraint(equalTo: containerView.bottomAnchor),
- statusCheckbox.leadingAnchor.constraint(equalTo: bottomControlsContainer.leadingAnchor),
- bottomControlsContainer.bottomAnchor.constraint(equalTo: statusCheckbox.bottomAnchor, constant: 4),
+ toggleStatusButton.leadingAnchor.constraint(equalTo: bottomControlsContainer.leadingAnchor),
+ bottomControlsContainer.bottomAnchor.constraint(equalTo: toggleStatusButton.bottomAnchor, constant: 0),
editButton.trailingAnchor.constraint(equalTo: bottomControlsContainer.trailingAnchor),
- bottomControlsContainer.bottomAnchor.constraint(equalTo: editButton.bottomAnchor, constant: 4)
+ bottomControlsContainer.bottomAnchor.constraint(equalTo: editButton.bottomAnchor, constant: 0)
])
NSLayoutConstraint.activate([
@@ -203,28 +204,26 @@ class TunnelDetailTableViewController: NSViewController {
}
func updateStatus() {
- let statusText: String
+ let toggleStatusButtonText: String
switch tunnel.status {
case .waiting:
- statusText = tr("tunnelStatusWaiting")
+ toggleStatusButtonText = tr("macToggleStatusButtonWaiting")
case .inactive:
- statusText = tr("tunnelStatusInactive")
+ toggleStatusButtonText = tr("macToggleStatusButtonActivate")
case .activating:
- statusText = tr("tunnelStatusActivating")
+ toggleStatusButtonText = tr("macToggleStatusButtonActivating")
case .active:
- statusText = tr("tunnelStatusActive")
+ toggleStatusButtonText = tr("macToggleStatusButtonDeactivate")
case .deactivating:
- statusText = tr("tunnelStatusDeactivating")
+ toggleStatusButtonText = tr("macToggleStatusButtonDeactivating")
case .reasserting:
- statusText = tr("tunnelStatusReasserting")
+ toggleStatusButtonText = tr("macToggleStatusButtonReasserting")
case .restarting:
- statusText = tr("tunnelStatusRestarting")
+ toggleStatusButtonText = tr("macToggleStatusButtonRestarting")
}
- statusCheckbox.title = tr(format: "macStatus (%@)", statusText)
- let shouldBeChecked = (tunnel.status != .inactive && tunnel.status != .deactivating)
+ toggleStatusButton.title = toggleStatusButtonText
let shouldBeEnabled = (tunnel.status == .active || tunnel.status == .inactive)
- statusCheckbox.state = shouldBeChecked ? .on : .off
- statusCheckbox.isEnabled = shouldBeEnabled
+ toggleStatusButton.isEnabled = shouldBeEnabled
if tunnel.status == .active {
startUpdatingRuntimeConfiguration()
} else if tunnel.status == .inactive {
@@ -251,15 +250,6 @@ class TunnelDetailTableViewController: NSViewController {
}
}
- @objc func statusCheckboxToggled(sender: AnyObject?) {
- guard let statusCheckbox = sender as? NSButton else { return }
- if statusCheckbox.state == .on {
- tunnelsManager.startActivation(of: tunnel)
- } else if statusCheckbox.state == .off {
- tunnelsManager.startDeactivation(of: tunnel)
- }
- }
-
override func viewWillDisappear() {
super.viewWillDisappear()
if let tunnelEditVC = tunnelEditVC {