mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-08-14 10:37:33 -07:00
Initial start of the menu bar app.
Has menu items to join/leave networks which currently displays an empty popover from the icon (icon needs to be made still)
This commit is contained in:
parent
0582338015
commit
225c2b095b
13 changed files with 195 additions and 6 deletions
|
@ -14,8 +14,34 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
@IBOutlet weak var window: NSWindow!
|
||||
|
||||
|
||||
let statusItem = NSStatusBar.systemStatusBar().statusItemWithLength(-2.0)
|
||||
|
||||
let networkListPopover = NSPopover()
|
||||
let joinNetworkPopover = NSPopover()
|
||||
|
||||
var transientMonitor: AnyObject? = nil
|
||||
|
||||
func applicationDidFinishLaunching(aNotification: NSNotification) {
|
||||
// Insert code here to initialize your application
|
||||
|
||||
|
||||
statusItem.image = NSImage(named: "MenuBarIconMac")
|
||||
|
||||
let menu = NSMenu()
|
||||
|
||||
menu.addItem(NSMenuItem(title: "Show Networks", action: #selector(AppDelegate.showNetworks), keyEquivalent: "n"))
|
||||
menu.addItem(NSMenuItem(title: "Join Network", action: #selector(AppDelegate.joinNetwork), keyEquivalent: "j"))
|
||||
menu.addItem(NSMenuItem.separatorItem())
|
||||
menu.addItem(NSMenuItem(title: "Quit ZeroTier One", action: #selector(AppDelegate.quit), keyEquivalent: "q"))
|
||||
|
||||
statusItem.menu = menu
|
||||
|
||||
joinNetworkPopover.contentViewController = JoinNetworkViewController(
|
||||
nibName: "JoinNetworkViewController", bundle: nil)
|
||||
joinNetworkPopover.behavior = .Transient
|
||||
|
||||
networkListPopover.contentViewController = ShowNetworksViewController(
|
||||
nibName: "ShowNetworksViewController", bundle: nil)
|
||||
networkListPopover.behavior = .Transient
|
||||
}
|
||||
|
||||
func applicationWillTerminate(aNotification: NSNotification) {
|
||||
|
@ -23,5 +49,41 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
}
|
||||
|
||||
|
||||
func showNetworks() {
|
||||
if let button = statusItem.button {
|
||||
networkListPopover.showRelativeToRect(button.bounds, ofView: button, preferredEdge: .MinY)
|
||||
|
||||
if transientMonitor == nil {
|
||||
transientMonitor = NSEvent.addGlobalMonitorForEventsMatchingMask(
|
||||
[.LeftMouseDownMask, .RightMouseDownMask, .OtherMouseDownMask]) { (event: NSEvent) -> Void in
|
||||
|
||||
NSEvent.removeMonitor(self.transientMonitor!)
|
||||
self.transientMonitor = nil
|
||||
self.networkListPopover.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func joinNetwork() {
|
||||
if let button = statusItem.button {
|
||||
joinNetworkPopover.showRelativeToRect(button.bounds, ofView: button, preferredEdge: .MinY)
|
||||
|
||||
if transientMonitor == nil {
|
||||
transientMonitor = NSEvent.addGlobalMonitorForEventsMatchingMask(
|
||||
[.LeftMouseDownMask, .RightMouseDownMask, .OtherMouseDownMask]) { (event: NSEvent) -> Void in
|
||||
|
||||
NSEvent.removeMonitor(self.transientMonitor!)
|
||||
self.transientMonitor = nil
|
||||
self.joinNetworkPopover.close()
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func quit() {
|
||||
NSApp.performSelector(#selector(NSApp.terminate(_:)), withObject: nil, afterDelay: 0.0)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue