diff options
author | Jeroen Leenarts <jeroen.leenarts@gmail.com> | 2018-09-26 11:26:52 +0200 |
---|---|---|
committer | Jeroen Leenarts <jeroen.leenarts@gmail.com> | 2018-09-26 11:26:52 +0200 |
commit | 18d82d07af9b8b40aff2cad0acb9f249f1dbf6ca (patch) | |
tree | db1f1dd8737bd9721e1c23556562974bb6fd4b9b /WireGuard | |
parent | Fixe base 64 regex format. (diff) | |
download | wireguard-apple-18d82d07af9b8b40aff2cad0acb9f249f1dbf6ca.tar.xz wireguard-apple-18d82d07af9b8b40aff2cad0acb9f249f1dbf6ca.zip |
Use message to extension to obtain version info.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'WireGuard')
-rw-r--r-- | WireGuard/Coordinators/AppCoordinator+SettingsTableViewControllerDelegate.swift | 15 | ||||
-rw-r--r-- | WireGuard/ViewControllers/SetttingsTableViewController.swift | 24 |
2 files changed, 35 insertions, 4 deletions
diff --git a/WireGuard/Coordinators/AppCoordinator+SettingsTableViewControllerDelegate.swift b/WireGuard/Coordinators/AppCoordinator+SettingsTableViewControllerDelegate.swift index 0e09386..5784f5d 100644 --- a/WireGuard/Coordinators/AppCoordinator+SettingsTableViewControllerDelegate.swift +++ b/WireGuard/Coordinators/AppCoordinator+SettingsTableViewControllerDelegate.swift @@ -11,6 +11,21 @@ enum GoVersionCoordinatorError: Error { } extension AppCoordinator: SettingsTableViewControllerDelegate { + func goVersionInformation() -> Promise<String> { + return Promise(resolver: { (resolver) in + guard let session = self.providerManagers?.first?.connection as? NETunnelProviderSession else { + resolver.reject(GoVersionCoordinatorError.noSession) + return + } + try session.sendProviderMessage(ExtensionMessage.requestVersion.data, responseHandler: { (data) in + guard let responseString = String(data: data!, encoding: .utf8) else { + return + } + resolver.fulfill(responseString) + }) + }) + } + func exportTunnels(settingsTableViewController: SettingsTableViewController, sourceView: UIView) { self.exportConfigs(sourceView: sourceView) } diff --git a/WireGuard/ViewControllers/SetttingsTableViewController.swift b/WireGuard/ViewControllers/SetttingsTableViewController.swift index a009403..0421815 100644 --- a/WireGuard/ViewControllers/SetttingsTableViewController.swift +++ b/WireGuard/ViewControllers/SetttingsTableViewController.swift @@ -3,9 +3,15 @@ // import UIKit +import PromiseKit + +enum GoVersionError: Error { + case noDelegate +} protocol SettingsTableViewControllerDelegate: class { func exportTunnels(settingsTableViewController: SettingsTableViewController, sourceView: UIView) + func goVersionInformation() -> Promise<String> } class SettingsTableViewController: UITableViewController { @@ -21,14 +27,24 @@ class SettingsTableViewController: UITableViewController { override func viewDidLoad() { super.viewDidLoad() versionInfoLabel.text = versionInformation - goVersionInfoLabel.text = goVersionInformation + _ = firstly { () -> Promise<String> in + self.goVersionInfoLabel.text = NSLocalizedString("Loading...", comment: "") + return goVersionInformation() + }.then { (goVersion: String) -> Guarantee<Void> in + if let label = self.goVersionInfoLabel { + label.text = goVersion + } + return Guarantee.value(()) + }.recover({ (_) in + self.goVersionInfoLabel.text = NSLocalizedString("Unknown", comment: "") + }) } 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") + UIPasteboard.general.string = ["WireGuard for iOS:", versionInformation, "Go userspace backend:", goVersionInfoLabel.text ?? ""].joined(separator: "\n") showCopyConfirmation() case exportCell: delegate?.exportTunnels(settingsTableViewController: self, sourceView: exportCell) @@ -49,8 +65,8 @@ class SettingsTableViewController: UITableViewController { return versionElements.joined(separator: " ") } - var goVersionInformation: String { - return wgVersion().flatMap { String(cString: $0) } ?? "" + func goVersionInformation() -> Promise<String> { + return self.delegate?.goVersionInformation() ?? Promise(error: GoVersionError.noDelegate) } private func showCopyConfirmation() { |