Don't crash on failure to obtain version info and inform user on what is needed to be able to retrieve version info from the Go client.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jeroen Leenarts
2018-10-01 15:37:15 +02:00
parent 86646448ac
commit 33cdc14070
3 changed files with 34 additions and 12 deletions
@@ -35,8 +35,15 @@ class SettingsTableViewController: UITableViewController {
label.text = goVersion
}
return Guarantee.value(())
}.recover({ (_) in
self.goVersionInfoLabel.text = NSLocalizedString("Unknown", comment: "")
}.recover({ (error) in
switch error {
case GoVersionCoordinatorError.noEnabledSession:
self.goVersionInfoLabel.text = NSLocalizedString("Unavailable", comment: "")
self.showNotEnabledAlert()
default:
self.goVersionInfoLabel.text = NSLocalizedString("Unknown", comment: "")
}
})
}
@@ -69,6 +76,13 @@ class SettingsTableViewController: UITableViewController {
return self.delegate?.goVersionInformation() ?? Promise(error: GoVersionError.noDelegate)
}
private func showNotEnabledAlert() {
let notEnabledAlertController = UIAlertController(title: NSLocalizedString("Go version", comment: ""), message: NSLocalizedString("Enable a WireGuard config by connecting or by selecting one in the VPN section of the device Settings app.", comment: ""), preferredStyle: .alert)
notEnabledAlertController.addAction(UIAlertAction(title: NSLocalizedString("Ok", comment: "Generic OK button"), style: .default, handler: nil))
present(notEnabledAlertController, animated: true, completion: nil)
}
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))