mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-08-20 21:33:57 -07:00
put node ID into the main menu.
Clicking on the menu item copies the node ID into the clipboard.
This commit is contained in:
parent
fe725f9995
commit
a156fec25a
5 changed files with 130 additions and 2 deletions
|
@ -27,7 +27,12 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
|
||||
var networks = [Network]()
|
||||
|
||||
var status: NodeStatus? = nil
|
||||
|
||||
var pasteboard = NSPasteboard.generalPasteboard()
|
||||
|
||||
func applicationDidFinishLaunching(aNotification: NSNotification) {
|
||||
pasteboard.declareTypes([NSPasteboardTypeString], owner: nil)
|
||||
|
||||
let defaults = NSUserDefaults.standardUserDefaults()
|
||||
let defaultsDict = ["firstRun": true]
|
||||
|
@ -47,10 +52,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
let nc = NSNotificationCenter.defaultCenter()
|
||||
nc.addObserver(self, selector: #selector(onNetworkListUpdated(_:)), name: networkUpdateKey, object: nil)
|
||||
nc.addObserver(self, selector: #selector(onNodeStatusUpdated(_:)), name: statusUpdateKey, object: nil)
|
||||
|
||||
statusItem.image = NSImage(named: "MenuBarIconMac")
|
||||
|
||||
|
@ -161,9 +165,21 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
buildMenu()
|
||||
}
|
||||
|
||||
func onNodeStatusUpdated(note: NSNotification) {
|
||||
let status = note.userInfo!["status"] as! NodeStatus
|
||||
self.status = status
|
||||
|
||||
buildMenu()
|
||||
}
|
||||
|
||||
func buildMenu() {
|
||||
let menu = NSMenu()
|
||||
|
||||
if let s = self.status {
|
||||
menu.addItem(NSMenuItem(title: "Node ID: \(s.address)", action: #selector(AppDelegate.copyNodeID), keyEquivalent: ""))
|
||||
menu.addItem(NSMenuItem.separatorItem())
|
||||
}
|
||||
|
||||
menu.addItem(NSMenuItem(title: "Network Details...", action: #selector(AppDelegate.showNetworks), keyEquivalent: "n"))
|
||||
menu.addItem(NSMenuItem(title: "Join Network...", action: #selector(AppDelegate.joinNetwork), keyEquivalent: "j"))
|
||||
menu.addItem(NSMenuItem.separatorItem())
|
||||
|
@ -224,5 +240,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
ServiceCom.joinNetwork(id)
|
||||
}
|
||||
}
|
||||
|
||||
func copyNodeID() {
|
||||
if let s = self.status {
|
||||
pasteboard.setString(s.address, forType: NSPasteboardTypeString)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue