diff options
author | Roopesh Chander <roop@roopc.net> | 2018-12-28 19:29:09 +0530 |
---|---|---|
committer | Roopesh Chander <roop@roopc.net> | 2019-01-14 14:52:29 +0530 |
commit | b5751b63214b51f2b576eb40694f6bb7f9bcd7d4 (patch) | |
tree | 11d8d008b27709b1e66fbb91df0def63763aa411 /WireGuard/WireGuard/UI/macOS/AppDelegate.swift | |
parent | macOS: Add status bar icon (diff) | |
download | wireguard-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 '')
-rw-r--r-- | WireGuard/WireGuard/UI/macOS/AppDelegate.swift | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/AppDelegate.swift b/WireGuard/WireGuard/UI/macOS/AppDelegate.swift index 9630135..ba3e902 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 +} |