macOS: Add About dialog

Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
Roopesh Chander 2019-01-12 00:20:02 +05:30
parent cd5427ef92
commit 26ea353933
2 changed files with 24 additions and 0 deletions

View File

@ -232,6 +232,7 @@
"macMenuAddEmptyTunnel" = "Add empty tunnel...";
"macMenuExportLog" = "Export log to file...";
"macMenuExportTunnels" = "Export tunnels to zip...";
"macMenuAbout" = "About WireGuard";
"macMenuQuit" = "Quit";
// Mac manage tunnels window
@ -292,3 +293,8 @@
"macAlertInfoUnrecognizedPeerKey" = "Valid keys are: 'PublicKey', 'PresharedKey', 'AllowedIPs', 'Endpoint' and 'PersistentKeepalive'";
"macAlertMultipleEntriesForKey (%@)" = "There should be only one entry per section for key '%@'";
// Mac about dialog
"macAppVersion (%@)" = "App version: %@";
"macGoBackendVersion (%@)" = "Go backend version: %@";

View File

@ -123,6 +123,9 @@ class StatusMenu: NSMenu {
}
func addApplicationItems() {
let aboutItem = NSMenuItem(title: tr("macMenuAbout"), action: #selector(aboutClicked), keyEquivalent: "")
aboutItem.target = self
addItem(aboutItem)
let quitItem = NSMenuItem(title: tr("macMenuQuit"), action: #selector(NSApplication.terminate), keyEquivalent: "")
quitItem.target = NSApp
addItem(quitItem)
@ -148,6 +151,21 @@ class StatusMenu: NSMenu {
manageTunnelsWindow.makeKeyAndOrderFront(self)
ImportPanelPresenter.presentImportPanel(tunnelsManager: tunnelsManager, sourceVC: manageTunnelsRootVC!)
}
@objc func aboutClicked() {
var appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "Unknown"
if let appBuild = Bundle.main.infoDictionary?["CFBundleVersion"] as? String {
appVersion += " (\(appBuild))"
}
let appVersionString = [
tr(format: "macAppVersion (%@)", appVersion),
tr(format: "macGoBackendVersion (%@)", WIREGUARD_GO_VERSION)
].joined(separator: "\n")
NSApp.orderFrontStandardAboutPanel(options: [
.applicationVersion: appVersionString,
.version: ""
])
}
}
extension StatusMenu {