Extract WireGuardGo version at build time.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
@@ -12,26 +12,6 @@ enum GoVersionCoordinatorError: Error {
|
||||
}
|
||||
|
||||
extension AppCoordinator: SettingsTableViewControllerDelegate {
|
||||
func goVersionInformation() -> Promise<String> {
|
||||
return Promise(resolver: { (resolver) in
|
||||
guard let session = self.providerManagers?.first(where: { $0.isEnabled })?.connection as? NETunnelProviderSession else {
|
||||
resolver.reject(GoVersionCoordinatorError.noEnabledSession)
|
||||
return
|
||||
}
|
||||
do {
|
||||
try session.sendProviderMessage(ExtensionMessage.requestVersion.data, responseHandler: { (data) in
|
||||
guard let data = data, let responseString = String(data: data, encoding: .utf8) else {
|
||||
resolver.reject(GoVersionCoordinatorError.noResponse)
|
||||
return
|
||||
}
|
||||
resolver.fulfill(responseString)
|
||||
})
|
||||
} catch {
|
||||
resolver.reject(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func exportTunnels(settingsTableViewController: SettingsTableViewController, sourceView: UIView) {
|
||||
self.exportConfigs(sourceView: sourceView)
|
||||
}
|
||||
|
||||
@@ -329,7 +329,9 @@ class AppCoordinator: RootViewCoordinator { // swiftlint:disable:this type_body_
|
||||
|
||||
func connect(tunnel: Tunnel) {
|
||||
_ = refreshProviderManagers().then { () -> Promise<Void> in
|
||||
let manager = self.providerManager(for: tunnel)!
|
||||
guard let manager = self.providerManager(for: tunnel) else {
|
||||
return Promise.value(())
|
||||
}
|
||||
let block = {
|
||||
switch manager.connection.status {
|
||||
case .invalid, .disconnected:
|
||||
@@ -411,6 +413,26 @@ class AppCoordinator: RootViewCoordinator { // swiftlint:disable:this type_body_
|
||||
return tunnelIdentifier == tunnel.tunnelIdentifier
|
||||
}
|
||||
}
|
||||
|
||||
func extensionGoVersionInformation() -> Promise<String> {
|
||||
return Promise(resolver: { (resolver) in
|
||||
guard let session = self.providerManagers?.first(where: { $0.isEnabled })?.connection as? NETunnelProviderSession else {
|
||||
resolver.reject(GoVersionCoordinatorError.noEnabledSession)
|
||||
return
|
||||
}
|
||||
do {
|
||||
try session.sendProviderMessage(ExtensionMessage.requestVersion.data, responseHandler: { (data) in
|
||||
guard let data = data, let responseString = String(data: data, encoding: .utf8) else {
|
||||
resolver.reject(GoVersionCoordinatorError.noResponse)
|
||||
return
|
||||
}
|
||||
resolver.fulfill(responseString)
|
||||
})
|
||||
} catch {
|
||||
resolver.reject(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
class AppDocumentPickerDelegate: NSObject, UIDocumentPickerDelegate {
|
||||
|
||||
@@ -67,6 +67,8 @@
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>WireGuardGoVersion</key>
|
||||
<string>unknown</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
|
||||
@@ -11,7 +11,6 @@ enum GoVersionError: Error {
|
||||
|
||||
protocol SettingsTableViewControllerDelegate: class {
|
||||
func exportTunnels(settingsTableViewController: SettingsTableViewController, sourceView: UIView)
|
||||
func goVersionInformation() -> Promise<String>
|
||||
}
|
||||
|
||||
class SettingsTableViewController: UITableViewController {
|
||||
@@ -27,24 +26,7 @@ class SettingsTableViewController: UITableViewController {
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
versionInfoLabel.text = versionInformation
|
||||
_ = 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({ (error) in
|
||||
switch error {
|
||||
case GoVersionCoordinatorError.noEnabledSession:
|
||||
self.goVersionInfoLabel.text = NSLocalizedString("Unavailable", comment: "")
|
||||
self.showNotEnabledAlert()
|
||||
default:
|
||||
self.goVersionInfoLabel.text = NSLocalizedString("Unknown", comment: "")
|
||||
}
|
||||
|
||||
})
|
||||
goVersionInfoLabel.text = goVersionInformation
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
@@ -72,8 +54,8 @@ class SettingsTableViewController: UITableViewController {
|
||||
return versionElements.joined(separator: " ")
|
||||
}
|
||||
|
||||
func goVersionInformation() -> Promise<String> {
|
||||
return self.delegate?.goVersionInformation() ?? Promise(error: GoVersionError.noDelegate)
|
||||
var goVersionInformation: String {
|
||||
return Bundle.main.infoDictionary!["WireGuardGoVersion"] as? String ?? "Unknown!!!"
|
||||
}
|
||||
|
||||
private func showNotEnabledAlert() {
|
||||
|
||||
Reference in New Issue
Block a user