ui: add donation link

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2019-10-11 21:31:20 +02:00
parent f120a6aab0
commit 84ca7fcf40
3 changed files with 23 additions and 4 deletions

View File

@ -437,3 +437,7 @@
"macAppStoreUpdatingAlertMessage" = "App Store would like to update WireGuard"; "macAppStoreUpdatingAlertMessage" = "App Store would like to update WireGuard";
"macAppStoreUpdatingAlertInfoWithOnDemand (%@)" = "Please disable on-demand for tunnel %@, deactivate it, and then continue updating in App Store."; "macAppStoreUpdatingAlertInfoWithOnDemand (%@)" = "Please disable on-demand for tunnel %@, deactivate it, and then continue updating in App Store.";
"macAppStoreUpdatingAlertInfoWithoutOnDemand (%@)" = "Please deactivate tunnel %@ and then continue updating in App Store."; "macAppStoreUpdatingAlertInfoWithoutOnDemand (%@)" = "Please deactivate tunnel %@ and then continue updating in App Store.";
// Donation
"donateLink" = "♥ Donate to the WireGuard Project";

View File

@ -11,6 +11,7 @@ class SettingsTableViewController: UITableViewController {
case goBackendVersion case goBackendVersion
case exportZipArchive case exportZipArchive
case viewLog case viewLog
case donateLink
var localizedUIString: String { var localizedUIString: String {
switch self { switch self {
@ -18,12 +19,13 @@ class SettingsTableViewController: UITableViewController {
case .goBackendVersion: return tr("settingsVersionKeyWireGuardGoBackend") case .goBackendVersion: return tr("settingsVersionKeyWireGuardGoBackend")
case .exportZipArchive: return tr("settingsExportZipButtonTitle") case .exportZipArchive: return tr("settingsExportZipButtonTitle")
case .viewLog: return tr("settingsViewLogButtonTitle") case .viewLog: return tr("settingsViewLogButtonTitle")
case .donateLink: return tr("donateLink")
} }
} }
} }
let settingsFieldsBySection: [[SettingsFields]] = [ let settingsFieldsBySection: [[SettingsFields]] = [
[.iosAppVersion, .goBackendVersion], [.iosAppVersion, .goBackendVersion, .donateLink],
[.exportZipArchive], [.exportZipArchive],
[.viewLog] [.viewLog]
] ]
@ -160,14 +162,24 @@ extension SettingsTableViewController {
self?.exportConfigurationsAsZipFile(sourceView: cell.button) self?.exportConfigurationsAsZipFile(sourceView: cell.button)
} }
return cell return cell
} else { } else if field == .viewLog {
assert(field == .viewLog)
let cell: ButtonCell = tableView.dequeueReusableCell(for: indexPath) let cell: ButtonCell = tableView.dequeueReusableCell(for: indexPath)
cell.buttonText = field.localizedUIString cell.buttonText = field.localizedUIString
cell.onTapped = { [weak self] in cell.onTapped = { [weak self] in
self?.presentLogView() self?.presentLogView()
} }
return cell return cell
} else if field == .donateLink {
let cell: ButtonCell = tableView.dequeueReusableCell(for: indexPath)
cell.buttonText = field.localizedUIString
cell.onTapped = {
if let url = URL(string: "https://www.wireguard.com/donations/"), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:])
}
}
return cell
} else {
assert(false)
} }
} }
} }

View File

@ -210,10 +210,13 @@ extension AppDelegate {
tr(format: "macAppVersion (%@)", appVersion), tr(format: "macAppVersion (%@)", appVersion),
tr(format: "macGoBackendVersion (%@)", WIREGUARD_GO_VERSION) tr(format: "macGoBackendVersion (%@)", WIREGUARD_GO_VERSION)
].joined(separator: "\n") ].joined(separator: "\n")
let donateString = NSMutableAttributedString(string: tr("donateLink"))
donateString.addAttribute(.link, value: "https://www.wireguard.com/donations/", range: NSRange(location: 0, length: donateString.length))
NSApp.activate(ignoringOtherApps: true) NSApp.activate(ignoringOtherApps: true)
NSApp.orderFrontStandardAboutPanel(options: [ NSApp.orderFrontStandardAboutPanel(options: [
.applicationVersion: appVersionString, .applicationVersion: appVersionString,
.version: "" .version: "",
.credits: donateString
]) ])
} }
} }