aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/macOS/AppDelegate.swift
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-12-28 19:29:09 +0530
committerRoopesh Chander <roop@roopc.net>2019-01-14 14:52:29 +0530
commitb5751b63214b51f2b576eb40694f6bb7f9bcd7d4 (patch)
tree11d8d008b27709b1e66fbb91df0def63763aa411 /WireGuard/WireGuard/UI/macOS/AppDelegate.swift
parentmacOS: Add status bar icon (diff)
downloadwireguard-apple-b5751b63214b51f2b576eb40694f6bb7f9bcd7d4.tar.xz
wireguard-apple-b5751b63214b51f2b576eb40694f6bb7f9bcd7d4.zip
macOS: Create status bar with tunnel names
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard/UI/macOS/AppDelegate.swift')
-rw-r--r--WireGuard/WireGuard/UI/macOS/AppDelegate.swift24
1 files changed, 18 insertions, 6 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/AppDelegate.swift b/WireGuard/WireGuard/UI/macOS/AppDelegate.swift
index 96301350..ba3e902f 100644
--- a/WireGuard/WireGuard/UI/macOS/AppDelegate.swift
+++ b/WireGuard/WireGuard/UI/macOS/AppDelegate.swift
@@ -6,14 +6,26 @@ import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
+ var statusItem: NSStatusItem?
+
func applicationDidFinishLaunching(_ aNotification: Notification) {
- // Insert code here to initialize your application
- }
+ TunnelsManager.create { [weak self] result in
+ guard let self = self else { return }
+ guard result.isSuccess else { return } // TODO: Show alert
- func applicationWillTerminate(_ aNotification: Notification) {
- // Insert code here to tear down your application
+ let tunnelsManager: TunnelsManager = result.value!
+ let statusMenu = StatusMenu(tunnelsManager: tunnelsManager)
+ self.statusItem = createStatusBarItem(with: statusMenu)
+ }
}
-
-
}
+func createStatusBarItem(with statusMenu: StatusMenu) -> NSStatusItem {
+ let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)
+ if let statusBarImage = NSImage(named: "WireGuardMacStatusBarIcon") {
+ statusBarImage.isTemplate = true
+ statusItem.button?.image = statusBarImage
+ }
+ statusItem.menu = statusMenu
+ return statusItem
+}