aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/macOS/AppDelegate.swift
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-01-16 01:00:42 +0530
committerRoopesh Chander <roop@roopc.net>2019-01-16 01:26:10 +0530
commite29cf19fddc6878f7e24c442f83d6ff0d23fa6b8 (patch)
tree6b7a098cd40dda417d1827af5245669bc883fa88 /WireGuard/WireGuard/UI/macOS/AppDelegate.swift
parentmacOS: Add About dialog (diff)
downloadwireguard-apple-e29cf19fddc6878f7e24c442f83d6ff0d23fa6b8.tar.xz
wireguard-apple-e29cf19fddc6878f7e24c442f83d6ff0d23fa6b8.zip
macOS: Different status bar icon looks for different states
- Looks dimmed when no tunnel is active - Looks normal when a tunnel is active - Animates when a tunnel is activating 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.swift23
1 files changed, 11 insertions, 12 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/AppDelegate.swift b/WireGuard/WireGuard/UI/macOS/AppDelegate.swift
index a08f9dc0..3f089875 100644
--- a/WireGuard/WireGuard/UI/macOS/AppDelegate.swift
+++ b/WireGuard/WireGuard/UI/macOS/AppDelegate.swift
@@ -6,7 +6,8 @@ import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
- var statusItem: NSStatusItem?
+ var statusItemController: StatusItemController?
+ var currentTunnelStatusObserver: AnyObject?
func applicationDidFinishLaunching(_ aNotification: Notification) {
Logger.configureGlobal(withFilePath: FileManager.appLogFileURL?.path)
@@ -19,21 +20,19 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
let tunnelsManager: TunnelsManager = result.value!
+ let statusItemController = StatusItemController()
+
let statusMenu = StatusMenu(tunnelsManager: tunnelsManager)
- self.statusItem = createStatusBarItem(with: statusMenu)
+
+ statusItemController.statusItem.menu = statusMenu
+ statusItemController.currentTunnel = statusMenu.currentTunnel
+ self.currentTunnelStatusObserver = statusMenu.observe(\.currentTunnel) { statusMenu, _ in
+ statusItemController.currentTunnel = statusMenu.currentTunnel
+ }
+ self.statusItemController = statusItemController
tunnelsManager.tunnelsListDelegate = statusMenu
tunnelsManager.activationDelegate = 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
-}