Use message to extension to obtain version info.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jeroen Leenarts
2018-09-26 11:26:52 +02:00
parent 47a75bbd57
commit 18d82d07af
5 changed files with 73 additions and 14 deletions
@@ -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() {