Add settings screen. Move export as zip to settings screen.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// Copyright © 2018 WireGuard LLC. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
protocol SettingsTableViewControllerDelegate: class {
|
||||
func exportTunnels(settingsTableViewController: SettingsTableViewController, sourceView: UIView)
|
||||
}
|
||||
|
||||
class SettingsTableViewController: UITableViewController {
|
||||
|
||||
weak var delegate: SettingsTableViewControllerDelegate?
|
||||
@IBOutlet weak var versionInfoCell: UITableViewCell!
|
||||
@IBOutlet weak var goVersionInfoCell: UITableViewCell!
|
||||
@IBOutlet weak var exportCell: UITableViewCell!
|
||||
|
||||
@IBOutlet weak var versionInfoLabel: UILabel!
|
||||
@IBOutlet weak var goVersionInfoLabel: UILabel!
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
versionInfoLabel.text = versionInformation
|
||||
goVersionInfoLabel.text = goVersionInformation
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
if let cell = tableView.cellForRow(at: indexPath) {
|
||||
switch cell {
|
||||
case versionInfoCell, goVersionInfoCell:
|
||||
UIPasteboard.general.string = ["WireGuard for iOS:", versionInformation, "Go userspace backend:", goVersionInformation].joined(separator: "\n")
|
||||
showCopyConfirmation()
|
||||
case exportCell:
|
||||
delegate?.exportTunnels(settingsTableViewController: self, sourceView: exportCell)
|
||||
default:
|
||||
()
|
||||
}
|
||||
tableView.deselectRow(at: indexPath, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
var versionInformation: String {
|
||||
var versionElements: [String] = []
|
||||
if let appBuildNumber = Bundle.main.infoDictionary!["CFBundleVersion"] as? String, let appVersion = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as? String {
|
||||
versionElements.append(appVersion)
|
||||
versionElements.append("(\(appBuildNumber))")
|
||||
}
|
||||
|
||||
return versionElements.joined(separator: " ")
|
||||
}
|
||||
|
||||
var goVersionInformation: String {
|
||||
return wgVersion().flatMap { String(cString: $0) } ?? ""
|
||||
}
|
||||
|
||||
private func showCopyConfirmation() {
|
||||
let confirmationAlertController = UIAlertController(title: NSLocalizedString("Copied version information", comment: ""), message: UIPasteboard.general.string, preferredStyle: .alert)
|
||||
confirmationAlertController.addAction(UIAlertAction(title: NSLocalizedString("Ok", comment: "Generic OK button"), style: .default, handler: nil))
|
||||
|
||||
present(confirmationAlertController, animated: true, completion: nil)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
extension SettingsTableViewController: Identifyable {}
|
||||
@@ -9,13 +9,12 @@ import PromiseKit
|
||||
|
||||
protocol TunnelConfigurationTableViewControllerDelegate: class {
|
||||
func didSave(tunnel: Tunnel, tunnelConfigurationTableViewController: TunnelConfigurationTableViewController)
|
||||
func export(tunnel: Tunnel, barButtonItem: UIBarButtonItem)
|
||||
func showSettings()
|
||||
}
|
||||
|
||||
class TunnelConfigurationTableViewController: UITableViewController {
|
||||
|
||||
@IBOutlet weak var saveButton: UIBarButtonItem!
|
||||
@IBOutlet weak var exportButton: UIBarButtonItem!
|
||||
|
||||
private var viewContext: NSManagedObjectContext!
|
||||
private weak var delegate: TunnelConfigurationTableViewControllerDelegate?
|
||||
@@ -41,6 +40,10 @@ class TunnelConfigurationTableViewController: UITableViewController {
|
||||
return tunnel
|
||||
}
|
||||
|
||||
@IBAction func showSettings(_ sender: Any) {
|
||||
delegate?.showSettings()
|
||||
}
|
||||
|
||||
@IBAction func addPeer(_ sender: Any) {
|
||||
if let moc = tunnel.managedObjectContext {
|
||||
tableView.beginUpdates()
|
||||
@@ -55,10 +58,6 @@ class TunnelConfigurationTableViewController: UITableViewController {
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func exportTunnel(_ sender: UIBarButtonItem) {
|
||||
self.delegate?.export(tunnel: tunnel, barButtonItem: sender)
|
||||
}
|
||||
|
||||
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||
return 3
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import PromiseKit
|
||||
|
||||
protocol TunnelInfoTableViewControllerDelegate: class {
|
||||
func configure(tunnel: Tunnel, tunnelInfoTableViewController: TunnelInfoTableViewController)
|
||||
func showSettings()
|
||||
}
|
||||
|
||||
class TunnelInfoTableViewController: UITableViewController {
|
||||
@@ -63,6 +64,10 @@ class TunnelInfoTableViewController: UITableViewController {
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func showSettings(_ sender: Any) {
|
||||
delegate?.showSettings()
|
||||
}
|
||||
|
||||
@IBAction func editTunnelConfiguration(_ sender: Any) {
|
||||
delegate?.configure(tunnel: self.tunnel, tunnelInfoTableViewController: self)
|
||||
}
|
||||
|
||||
@@ -10,13 +10,13 @@ import BNRCoreDataStack
|
||||
import NetworkExtension
|
||||
|
||||
protocol TunnelsTableViewControllerDelegate: class {
|
||||
func exportTunnels(tunnelsTableViewController: TunnelsTableViewController, barButtonItem: UIBarButtonItem)
|
||||
func addProvider(tunnelsTableViewController: TunnelsTableViewController)
|
||||
func connect(tunnel: Tunnel, tunnelsTableViewController: TunnelsTableViewController)
|
||||
func disconnect(tunnel: Tunnel, tunnelsTableViewController: TunnelsTableViewController)
|
||||
func info(tunnel: Tunnel, tunnelsTableViewController: TunnelsTableViewController)
|
||||
func delete(tunnel: Tunnel, tunnelsTableViewController: TunnelsTableViewController)
|
||||
func status(for tunnel: Tunnel, tunnelsTableViewController: TunnelsTableViewController) -> NEVPNStatus
|
||||
func showSettings()
|
||||
}
|
||||
|
||||
class TunnelsTableViewController: UITableViewController {
|
||||
@@ -66,8 +66,8 @@ class TunnelsTableViewController: UITableViewController {
|
||||
tableView.tableFooterView = UIView(frame: CGRect.zero)
|
||||
}
|
||||
|
||||
@IBAction func exportTunnels(_ sender: UIBarButtonItem) {
|
||||
delegate?.exportTunnels(tunnelsTableViewController: self, barButtonItem: sender)
|
||||
@IBAction func showSettings(_ sender: Any) {
|
||||
delegate?.showSettings()
|
||||
}
|
||||
|
||||
@IBAction func addProvider(_ sender: UIBarButtonItem) {
|
||||
|
||||
Reference in New Issue
Block a user