mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-19 13:36:54 +02:00
Now translated. One minor crash to figure out.
This commit is contained in:
parent
5b13b282ed
commit
8d7f851b4e
8 changed files with 358 additions and 288 deletions
|
@ -10,7 +10,6 @@
|
|||
932D472F1D1CD499004BCFE2 /* ZeroTierIcon.icns in Resources */ = {isa = PBXBuildFile; fileRef = 932D472E1D1CD499004BCFE2 /* ZeroTierIcon.icns */; };
|
||||
932D47331D1CD861004BCFE2 /* PreferencesViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 932D47311D1CD861004BCFE2 /* PreferencesViewController.xib */; };
|
||||
932D47371D1CDC9B004BCFE2 /* AboutViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 932D47351D1CDC9B004BCFE2 /* AboutViewController.xib */; };
|
||||
93326BDC1CE7C816005CA2AC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93326BDB1CE7C816005CA2AC /* AppDelegate.swift */; };
|
||||
93326BDE1CE7C816005CA2AC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 93326BDD1CE7C816005CA2AC /* Assets.xcassets */; };
|
||||
93326BE11CE7C816005CA2AC /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 93326BDF1CE7C816005CA2AC /* MainMenu.xib */; };
|
||||
93326BEB1CE7D9B9005CA2AC /* JoinNetworkViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 93326BE91CE7D9B9005CA2AC /* JoinNetworkViewController.xib */; };
|
||||
|
@ -24,6 +23,8 @@
|
|||
93D167731D58093C00330C99 /* NetworkInfoCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D167721D58093C00330C99 /* NetworkInfoCell.m */; };
|
||||
93D167761D580C3500330C99 /* ShowNetworksViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D167751D580C3500330C99 /* ShowNetworksViewController.m */; };
|
||||
93D167791D5815E600330C99 /* JoinNetworkViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D167781D5815E600330C99 /* JoinNetworkViewController.m */; };
|
||||
93D1677C1D58228A00330C99 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D1677B1D58228A00330C99 /* AppDelegate.m */; };
|
||||
93D1679B1D58300F00330C99 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D1679A1D58300F00330C99 /* main.m */; };
|
||||
93DAFB271D3F0BEE004D5417 /* about.html in Resources */ = {isa = PBXBuildFile; fileRef = 93DAFB261D3F0BEE004D5417 /* about.html */; };
|
||||
93DAFE4B1CFE53CA00547CC4 /* AuthtokenCopy.m in Sources */ = {isa = PBXBuildFile; fileRef = 93DAFE4A1CFE53CA00547CC4 /* AuthtokenCopy.m */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
@ -33,7 +34,6 @@
|
|||
932D47311D1CD861004BCFE2 /* PreferencesViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PreferencesViewController.xib; sourceTree = "<group>"; };
|
||||
932D47351D1CDC9B004BCFE2 /* AboutViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AboutViewController.xib; sourceTree = "<group>"; };
|
||||
93326BD81CE7C816005CA2AC /* ZeroTier One.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "ZeroTier One.app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
93326BDB1CE7C816005CA2AC /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
93326BDD1CE7C816005CA2AC /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
93326BE01CE7C816005CA2AC /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = "<group>"; };
|
||||
93326BE21CE7C816005CA2AC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
|
@ -57,8 +57,10 @@
|
|||
93D167751D580C3500330C99 /* ShowNetworksViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ShowNetworksViewController.m; sourceTree = "<group>"; };
|
||||
93D167771D5815E600330C99 /* JoinNetworkViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JoinNetworkViewController.h; sourceTree = "<group>"; };
|
||||
93D167781D5815E600330C99 /* JoinNetworkViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JoinNetworkViewController.m; sourceTree = "<group>"; };
|
||||
93D1677A1D58228A00330C99 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
|
||||
93D1677B1D58228A00330C99 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
|
||||
93D1679A1D58300F00330C99 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
|
||||
93DAFB261D3F0BEE004D5417 /* about.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = about.html; sourceTree = "<group>"; };
|
||||
93DAFE491CFE53C900547CC4 /* ZeroTier One-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ZeroTier One-Bridging-Header.h"; sourceTree = "<group>"; };
|
||||
93DAFE4A1CFE53CA00547CC4 /* AuthtokenCopy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AuthtokenCopy.m; sourceTree = "<group>"; };
|
||||
93DAFE4C1CFE53DA00547CC4 /* AuthtokenCopy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AuthtokenCopy.h; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
@ -94,13 +96,11 @@
|
|||
isa = PBXGroup;
|
||||
children = (
|
||||
932D472E1D1CD499004BCFE2 /* ZeroTierIcon.icns */,
|
||||
93326BDB1CE7C816005CA2AC /* AppDelegate.swift */,
|
||||
93326BDD1CE7C816005CA2AC /* Assets.xcassets */,
|
||||
93326BDF1CE7C816005CA2AC /* MainMenu.xib */,
|
||||
93326BE21CE7C816005CA2AC /* Info.plist */,
|
||||
93DAFE4A1CFE53CA00547CC4 /* AuthtokenCopy.m */,
|
||||
93DAFE4C1CFE53DA00547CC4 /* AuthtokenCopy.h */,
|
||||
93DAFE491CFE53C900547CC4 /* ZeroTier One-Bridging-Header.h */,
|
||||
93D1676E1D57FD3800330C99 /* NetworkMonitor.h */,
|
||||
93D1676F1D57FD3800330C99 /* NetworkMonitor.m */,
|
||||
93DAFB261D3F0BEE004D5417 /* about.html */,
|
||||
|
@ -124,6 +124,9 @@
|
|||
93D167771D5815E600330C99 /* JoinNetworkViewController.h */,
|
||||
93D167781D5815E600330C99 /* JoinNetworkViewController.m */,
|
||||
93326BE91CE7D9B9005CA2AC /* JoinNetworkViewController.xib */,
|
||||
93D1677A1D58228A00330C99 /* AppDelegate.h */,
|
||||
93D1677B1D58228A00330C99 /* AppDelegate.m */,
|
||||
93D1679A1D58300F00330C99 /* main.m */,
|
||||
);
|
||||
path = "ZeroTier One";
|
||||
sourceTree = "<group>";
|
||||
|
@ -204,14 +207,15 @@
|
|||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
93D1679B1D58300F00330C99 /* main.m in Sources */,
|
||||
93D167621D541BC200330C99 /* ServiceCom.m in Sources */,
|
||||
93D167761D580C3500330C99 /* ShowNetworksViewController.m in Sources */,
|
||||
93326BDC1CE7C816005CA2AC /* AppDelegate.swift in Sources */,
|
||||
93DAFE4B1CFE53CA00547CC4 /* AuthtokenCopy.m in Sources */,
|
||||
93D167701D57FD3800330C99 /* NetworkMonitor.m in Sources */,
|
||||
93D1675F1D54191C00330C99 /* NodeStatus.m in Sources */,
|
||||
93D167691D57E7EA00330C99 /* AboutViewController.m in Sources */,
|
||||
93D1676D1D57EB8400330C99 /* PreferencesViewController.m in Sources */,
|
||||
93D1677C1D58228A00330C99 /* AppDelegate.m in Sources */,
|
||||
93D167731D58093C00330C99 /* NetworkInfoCell.m in Sources */,
|
||||
93D167661D54308200330C99 /* Network.m in Sources */,
|
||||
93D167791D5815E600330C99 /* JoinNetworkViewController.m in Sources */,
|
||||
|
|
51
ZeroTier One/AppDelegate.h
Normal file
51
ZeroTier One/AppDelegate.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
//
|
||||
// AppDelegate.h
|
||||
// ZeroTier One
|
||||
//
|
||||
// Created by Grant Limberg on 8/7/16.
|
||||
// Copyright © 2016 ZeroTier, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@class NetworkMonitor;
|
||||
@class Network;
|
||||
@class NodeStatus;
|
||||
|
||||
@interface AppDelegate : NSObject <NSApplicationDelegate, NSMenuDelegate>
|
||||
|
||||
@property (weak, nonatomic) IBOutlet NSWindow *window;
|
||||
|
||||
@property (nonatomic) NSStatusItem *statusItem;
|
||||
|
||||
@property (nonatomic) NSPopover *networkListPopover;
|
||||
@property (nonatomic) NSPopover *joinNetworkPopover;
|
||||
@property (nonatomic) NSPopover *preferencesPopover;
|
||||
@property (nonatomic) NSPopover *aboutPopover;
|
||||
|
||||
@property (nonatomic) id transientMonitor;
|
||||
|
||||
@property (nonatomic) NetworkMonitor *monitor;
|
||||
|
||||
@property (nonatomic) NSMutableArray<Network*> *networks;
|
||||
|
||||
@property (nonatomic) NodeStatus *status;
|
||||
|
||||
@property (nonatomic) NSPasteboard *pasteboard;
|
||||
|
||||
- (void)buildMenu;
|
||||
|
||||
- (void)onNetworkListUpdated:(NSNotification*)note;
|
||||
- (void)onNodeStatusUpdated:(NSNotification*)note;
|
||||
|
||||
- (void)showNetworks;
|
||||
- (void)joinNetwork;
|
||||
- (void)showPreferences;
|
||||
- (void)showAbout;
|
||||
- (void)quit;
|
||||
- (void)toggleNetwork:(NSMenuItem*)sender;
|
||||
- (void)copyNodeID;
|
||||
- (void)menuWillOpen:(NSMenu*)menu;
|
||||
- (void)menuDidClose:(NSMenu*)menu;
|
||||
|
||||
@end
|
281
ZeroTier One/AppDelegate.m
Normal file
281
ZeroTier One/AppDelegate.m
Normal file
|
@ -0,0 +1,281 @@
|
|||
//
|
||||
// AppDelegate.m
|
||||
// ZeroTier One
|
||||
//
|
||||
// Created by Grant Limberg on 8/7/16.
|
||||
// Copyright © 2016 ZeroTier, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import "AppDelegate.h"
|
||||
#import "NetworkMonitor.h"
|
||||
#import "Network.h"
|
||||
#import "NodeStatus.h"
|
||||
#import "JoinNetworkViewController.h"
|
||||
#import "ShowNetworksViewController.h"
|
||||
#import "PreferencesViewController.h"
|
||||
#import "AboutViewController.h"
|
||||
#import "ServiceCom.h"
|
||||
|
||||
@implementation AppDelegate
|
||||
|
||||
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
|
||||
self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:-2.0f];
|
||||
self.networkListPopover = [[NSPopover alloc] init];
|
||||
self.joinNetworkPopover = [[NSPopover alloc] init];
|
||||
self.preferencesPopover = [[NSPopover alloc] init];
|
||||
self.aboutPopover = [[NSPopover alloc] init];
|
||||
self.transientMonitor = nil;
|
||||
self.monitor = [[NetworkMonitor alloc] init];
|
||||
self.networks = [NSMutableArray<Network*> array];
|
||||
self.status = nil;
|
||||
self.pasteboard = [NSPasteboard generalPasteboard];
|
||||
|
||||
[self.pasteboard declareTypes:[NSArray arrayWithObject:NSPasteboardTypeString] owner:nil];
|
||||
|
||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
NSDictionary *defaultsDict = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:@"firstRun"];
|
||||
[defaults registerDefaults:defaultsDict];
|
||||
|
||||
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
||||
|
||||
[nc addObserver:self
|
||||
selector:@selector(onNetworkListUpdated:)
|
||||
name:NetworkUpdateKey
|
||||
object:nil];
|
||||
[nc addObserver:self
|
||||
selector:@selector(onNodeStatusUpdated:)
|
||||
name:StatusUpdateKey
|
||||
object:nil];
|
||||
|
||||
self.statusItem.image = [NSImage imageNamed:@"MenuBarIconMac"];
|
||||
|
||||
[self buildMenu];
|
||||
|
||||
self.joinNetworkPopover.contentViewController = [[JoinNetworkViewController alloc] initWithNibName:@"JoinNetworkViewController" bundle:nil];
|
||||
self.joinNetworkPopover.behavior = NSPopoverBehaviorTransient;
|
||||
|
||||
ShowNetworksViewController *showNetworksView = [[ShowNetworksViewController alloc] initWithNibName:@"ShowNetworksViewController" bundle:nil];
|
||||
showNetworksView.netMonitor = self.monitor;
|
||||
self.networkListPopover.contentViewController = showNetworksView;
|
||||
self.networkListPopover.behavior = NSPopoverBehaviorTransient;
|
||||
|
||||
PreferencesViewController *prefsView = [[PreferencesViewController alloc] initWithNibName:@"PreferencesViewController" bundle:nil];
|
||||
self.preferencesPopover.contentViewController = prefsView;
|
||||
self.preferencesPopover.behavior = NSPopoverBehaviorTransient;
|
||||
|
||||
self.aboutPopover.contentViewController = [[AboutViewController alloc] initWithNibName:@"AboutViewController" bundle:nil];
|
||||
self.aboutPopover.behavior = NSPopoverBehaviorTransient;
|
||||
|
||||
BOOL firstRun = [defaults boolForKey:@"firstRun"];
|
||||
|
||||
if(firstRun) {
|
||||
[defaults setBool:NO forKey:@"firstRun"];
|
||||
[defaults synchronize];
|
||||
|
||||
[prefsView setLaunchAtLoginEnabled:YES];
|
||||
|
||||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
||||
[self showAbout];
|
||||
}];
|
||||
}
|
||||
|
||||
[self.monitor updateNetworkInfo];
|
||||
[self.monitor start];
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(NSNotification *)aNotification {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
|
||||
- (void)showNetworks {
|
||||
if(self.statusItem.button != nil) {
|
||||
NSStatusBarButton *button = self.statusItem.button;
|
||||
[self.networkListPopover showRelativeToRect:button.bounds
|
||||
ofView:button
|
||||
preferredEdge:NSMinYEdge];
|
||||
|
||||
if(self.transientMonitor == nil) {
|
||||
self.transientMonitor =
|
||||
[NSEvent addGlobalMonitorForEventsMatchingMask:(NSLeftMouseDown|NSRightMouseDown|NSOtherMouseDown)
|
||||
handler:^(NSEvent * _Nonnull e) {
|
||||
[NSEvent removeMonitor:self.transientMonitor];
|
||||
self.transientMonitor = nil;
|
||||
[self.networkListPopover close];
|
||||
}];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)joinNetwork {
|
||||
if(self.statusItem.button != nil) {
|
||||
NSStatusBarButton *button = self.statusItem.button;
|
||||
[self.joinNetworkPopover showRelativeToRect:button.bounds
|
||||
ofView:button
|
||||
preferredEdge:NSMinYEdge];
|
||||
if(self.transientMonitor == nil) {
|
||||
self.transientMonitor =
|
||||
[NSEvent addGlobalMonitorForEventsMatchingMask:(NSLeftMouseDown|NSRightMouseDown|NSOtherMouseDown)
|
||||
handler:^(NSEvent * _Nonnull e) {
|
||||
[NSEvent removeMonitor:self.transientMonitor];
|
||||
self.transientMonitor = nil;
|
||||
[self.joinNetworkPopover close];
|
||||
}];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)showPreferences {
|
||||
if(self.statusItem.button != nil) {
|
||||
NSStatusBarButton *button = self.statusItem.button;
|
||||
[self.preferencesPopover showRelativeToRect:button.bounds
|
||||
ofView:button
|
||||
preferredEdge:NSMinYEdge];
|
||||
if(self.transientMonitor == nil) {
|
||||
[NSEvent addGlobalMonitorForEventsMatchingMask:(NSLeftMouseDown|NSRightMouseDown|NSOtherMouseDown)
|
||||
handler:^(NSEvent * _Nonnull e) {
|
||||
[NSEvent removeMonitor:self.transientMonitor];
|
||||
self.transientMonitor = nil;
|
||||
[self.preferencesPopover close];
|
||||
}];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)showAbout {
|
||||
if(self.statusItem.button != nil) {
|
||||
NSStatusBarButton *button = self.statusItem.button;
|
||||
[self.aboutPopover showRelativeToRect:button.bounds
|
||||
ofView:button
|
||||
preferredEdge:NSMinYEdge];
|
||||
if(self.transientMonitor == nil) {
|
||||
[NSEvent addGlobalMonitorForEventsMatchingMask:(NSLeftMouseDown|NSRightMouseDown|NSOtherMouseDown)
|
||||
handler:^(NSEvent * _Nonnull e) {
|
||||
[NSEvent removeMonitor:self.transientMonitor];
|
||||
self.transientMonitor = nil;
|
||||
[self.aboutPopover close];
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
- (void)quit {
|
||||
[NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:0.0];
|
||||
}
|
||||
|
||||
- (void)onNetworkListUpdated:(NSNotification*)note {
|
||||
NSArray<Network*> *netList = [note.userInfo objectForKey:@"networks"];
|
||||
[(ShowNetworksViewController*)self.networkListPopover.contentViewController setNetworks:netList];
|
||||
self.networks = [netList mutableCopy];
|
||||
|
||||
[self buildMenu];
|
||||
}
|
||||
|
||||
- (void)onNodeStatusUpdated:(NSNotification*)note {
|
||||
NodeStatus *status = [note.userInfo objectForKey:@"status"];
|
||||
self.status = status;
|
||||
|
||||
[self buildMenu];
|
||||
}
|
||||
|
||||
- (void)buildMenu {
|
||||
NSMenu *menu = [[NSMenu alloc] init];
|
||||
menu.delegate = self;
|
||||
|
||||
if(self.status != nil) {
|
||||
NSString *nodeId = @"Node ID: ";
|
||||
nodeId = [nodeId stringByAppendingString:self.status.address];
|
||||
[menu addItem:[[NSMenuItem alloc] initWithTitle:nodeId
|
||||
action:@selector(copyNodeID)
|
||||
keyEquivalent:@""]];
|
||||
[menu addItem:[NSMenuItem separatorItem]];
|
||||
}
|
||||
|
||||
[menu addItem:[[NSMenuItem alloc] initWithTitle:@"Network Details..."
|
||||
action:@selector(showNetworks)
|
||||
keyEquivalent:@"n"]];
|
||||
[menu addItem:[[NSMenuItem alloc] initWithTitle:@"Join Network..."
|
||||
action:@selector(joinNetwork)
|
||||
keyEquivalent:@"j"]];
|
||||
|
||||
[menu addItem:[NSMenuItem separatorItem]];
|
||||
|
||||
if([self.networks count] > 0) {
|
||||
for(Network *net in self.networks) {
|
||||
NSString *nwid = [NSString stringWithFormat:@"%10llx", net.nwid];
|
||||
NSString *networkName = @"";
|
||||
if([net.name lengthOfBytesUsingEncoding:NSUTF8StringEncoding] == 0) {
|
||||
networkName = nwid;
|
||||
}
|
||||
else {
|
||||
networkName = [NSString stringWithFormat:@"%@ (%@)", nwid, net.name];
|
||||
}
|
||||
|
||||
if(net.allowDefault && net.connected) {
|
||||
networkName = [networkName stringByAppendingString:@" [default]"];
|
||||
}
|
||||
|
||||
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:networkName
|
||||
action:@selector(toggleNetwork:)
|
||||
keyEquivalent:@""];
|
||||
if(net.connected) {
|
||||
item.state = NSOnState;
|
||||
}
|
||||
else {
|
||||
item.state = NSOffState;
|
||||
}
|
||||
|
||||
item.representedObject = net;
|
||||
|
||||
[menu addItem:item];
|
||||
}
|
||||
|
||||
[menu addItem:[NSMenuItem separatorItem]];
|
||||
}
|
||||
|
||||
[menu addItem:[[NSMenuItem alloc] initWithTitle:@"About ZeroTier One..."
|
||||
action:@selector(showAbout)
|
||||
keyEquivalent:@""]];
|
||||
[menu addItem:[[NSMenuItem alloc] initWithTitle:@"Preferences..."
|
||||
action:@selector(showPreferences)
|
||||
keyEquivalent:@""]];
|
||||
|
||||
[menu addItem:[NSMenuItem separatorItem]];
|
||||
|
||||
[menu addItem:[[NSMenuItem alloc] initWithTitle:@"Quit"
|
||||
action:@selector(quit)
|
||||
keyEquivalent:@"q"]];
|
||||
|
||||
self.statusItem.menu = menu;
|
||||
}
|
||||
|
||||
- (void)toggleNetwork:(NSMenuItem*)sender {
|
||||
Network *network = sender.representedObject;
|
||||
NSString *nwid = [NSString stringWithFormat:@"%10llx", network.nwid];
|
||||
|
||||
if(network.connected) {
|
||||
[[ServiceCom sharedInstance] leaveNetwork:nwid];
|
||||
}
|
||||
else {
|
||||
[[ServiceCom sharedInstance] joinNetwork:nwid
|
||||
allowManaged:network.allowManaged
|
||||
allowGlobal:network.allowGlobal
|
||||
allowDefault:(network.allowDefault && ![Network defaultRouteExists:self.networks])];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)copyNodeID {
|
||||
if(self.status != nil) {
|
||||
[self.pasteboard setString:self.status.address forType:NSPasteboardTypeString];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)menuWillOpen:(NSMenu*)menu {
|
||||
|
||||
}
|
||||
|
||||
- (void)menuDidClose:(NSMenu*)menu {
|
||||
|
||||
}
|
||||
|
||||
@end
|
|
@ -1,264 +0,0 @@
|
|||
//
|
||||
// AppDelegate.swift
|
||||
// ZeroTier One
|
||||
//
|
||||
// Created by Grant Limberg on 5/14/16.
|
||||
// Copyright © 2016 ZeroTier, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
|
||||
@NSApplicationMain
|
||||
class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
||||
|
||||
@IBOutlet weak var window: NSWindow!
|
||||
|
||||
|
||||
let statusItem = NSStatusBar.systemStatusBar().statusItemWithLength(-2.0)
|
||||
|
||||
let networkListPopover = NSPopover()
|
||||
let joinNetworkPopover = NSPopover()
|
||||
let preferencesPopover = NSPopover()
|
||||
let aboutPopover = NSPopover()
|
||||
|
||||
var transientMonitor: AnyObject? = nil
|
||||
|
||||
let monitor = NetworkMonitor()
|
||||
|
||||
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]
|
||||
defaults.registerDefaults(defaultsDict)
|
||||
|
||||
|
||||
|
||||
|
||||
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")
|
||||
|
||||
buildMenu()
|
||||
|
||||
joinNetworkPopover.contentViewController = JoinNetworkViewController(
|
||||
nibName: "JoinNetworkViewController", bundle: nil)
|
||||
joinNetworkPopover.behavior = .Transient
|
||||
|
||||
let showNetworksView = ShowNetworksViewController(
|
||||
nibName: "ShowNetworksViewController", bundle: nil)
|
||||
showNetworksView?.netMonitor = monitor
|
||||
|
||||
networkListPopover.contentViewController = showNetworksView
|
||||
networkListPopover.behavior = .Transient
|
||||
|
||||
let prefsView = PreferencesViewController(nibName: "PreferencesViewController", bundle: nil)
|
||||
preferencesPopover.contentViewController = prefsView
|
||||
preferencesPopover.behavior = .Transient
|
||||
|
||||
aboutPopover.contentViewController = AboutViewController(
|
||||
nibName: "AboutViewController", bundle: nil)
|
||||
aboutPopover.behavior = .Transient
|
||||
|
||||
let firstRun = defaults.boolForKey("firstRun")
|
||||
|
||||
if firstRun {
|
||||
defaults.setBool(false, forKey: "firstRun")
|
||||
defaults.synchronize()
|
||||
|
||||
prefsView?.setLaunchAtLoginEnabled(true)
|
||||
}
|
||||
|
||||
if firstRun {
|
||||
NSOperationQueue.mainQueue().addOperationWithBlock() {
|
||||
self.showAbout()
|
||||
}
|
||||
}
|
||||
|
||||
monitor.updateNetworkInfo()
|
||||
monitor.start()
|
||||
}
|
||||
|
||||
func applicationWillTerminate(aNotification: NSNotification) {
|
||||
// Insert code here to tear down your application
|
||||
let nc = NSNotificationCenter.defaultCenter()
|
||||
nc.removeObserver(self)
|
||||
}
|
||||
|
||||
|
||||
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 showPreferences() {
|
||||
if let button = statusItem.button {
|
||||
preferencesPopover.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.preferencesPopover.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func showAbout() {
|
||||
if let button = statusItem.button {
|
||||
aboutPopover.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.aboutPopover.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func quit() {
|
||||
NSApp.performSelector(#selector(NSApp.terminate(_:)), withObject: nil, afterDelay: 0.0)
|
||||
}
|
||||
|
||||
func onNetworkListUpdated(note: NSNotification) {
|
||||
let netList = note.userInfo!["networks"] as! [Network]
|
||||
(networkListPopover.contentViewController as! ShowNetworksViewController).setNetworks(netList)
|
||||
|
||||
self.networks = netList
|
||||
|
||||
buildMenu()
|
||||
}
|
||||
|
||||
func onNodeStatusUpdated(note: NSNotification) {
|
||||
let status = note.userInfo!["status"] as! NodeStatus
|
||||
self.status = status
|
||||
|
||||
buildMenu()
|
||||
}
|
||||
|
||||
func buildMenu() {
|
||||
let menu = NSMenu()
|
||||
menu.delegate = self
|
||||
|
||||
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())
|
||||
|
||||
if networks.count > 0 {
|
||||
for net in networks {
|
||||
let id = String(net.nwid, radix: 16)
|
||||
var networkName = ""
|
||||
if net.name.isEmpty {
|
||||
networkName = "\(id)"
|
||||
}
|
||||
else {
|
||||
networkName = "\(id) (\(net.name))"
|
||||
}
|
||||
|
||||
if net.allowDefault && net.connected {
|
||||
networkName += " [default]"
|
||||
}
|
||||
let item = NSMenuItem(title: networkName, action: #selector(AppDelegate.toggleNetwork(_:)), keyEquivalent: "")
|
||||
|
||||
if net.connected {
|
||||
item.state = NSOnState
|
||||
}
|
||||
else {
|
||||
item.state = NSOffState
|
||||
}
|
||||
|
||||
item.representedObject = net
|
||||
|
||||
menu.addItem(item)
|
||||
}
|
||||
|
||||
menu.addItem(NSMenuItem.separatorItem())
|
||||
}
|
||||
|
||||
menu.addItem(NSMenuItem(title: "About ZeroTier One...", action: #selector(AppDelegate.showAbout), keyEquivalent: ""))
|
||||
menu.addItem(NSMenuItem(title: "Preferences...", action: #selector(AppDelegate.showPreferences), keyEquivalent: ","))
|
||||
|
||||
menu.addItem(NSMenuItem.separatorItem())
|
||||
|
||||
menu.addItem(NSMenuItem(title: "Quit ZeroTier One", action: #selector(AppDelegate.quit), keyEquivalent: "q"))
|
||||
|
||||
statusItem.menu = menu
|
||||
}
|
||||
|
||||
func toggleNetwork(sender: NSMenuItem) {
|
||||
NSLog("\(sender.title)")
|
||||
|
||||
let network = sender.representedObject as! Network
|
||||
|
||||
let id = String(network.nwid, radix: 16)
|
||||
|
||||
if network.connected {
|
||||
ServiceCom.sharedInstance().leaveNetwork(id)
|
||||
}
|
||||
else {
|
||||
ServiceCom.sharedInstance().joinNetwork(id, allowManaged: true, allowGlobal: false, allowDefault: false)
|
||||
}
|
||||
}
|
||||
|
||||
func copyNodeID() {
|
||||
if let s = self.status {
|
||||
pasteboard.setString(s.address, forType: NSPasteboardTypeString)
|
||||
}
|
||||
}
|
||||
|
||||
func menuWillOpen(menu: NSMenu) {
|
||||
//monitor.updateNetworkInfo()
|
||||
}
|
||||
|
||||
func menuDidClose(menu: NSMenu) {
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10116" systemVersion="15G31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10116"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
|
@ -12,7 +11,7 @@
|
|||
</customObject>
|
||||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
|
||||
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
|
||||
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="ZeroTier_One" customModuleProvider="target">
|
||||
<customObject id="Voe-Tx-rLC" customClass="AppDelegate">
|
||||
<connections>
|
||||
<outlet property="window" destination="QvC-M9-y7g" id="gIp-Ho-8D9"/>
|
||||
</connections>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10116" systemVersion="15F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10116" systemVersion="15G31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10116"/>
|
||||
</dependencies>
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
//
|
||||
// Use this file to import your target's public headers that you would like to expose to Swift.
|
||||
//
|
||||
|
||||
#import "AuthtokenCopy.h"
|
||||
#import "NodeStatus.h"
|
||||
#import "Network.h"
|
||||
#import "ServiceCom.h"
|
||||
#import "AboutViewController.h"
|
||||
#import "PreferencesViewController.h"
|
||||
#import "NetworkMonitor.h"
|
||||
#import "NetworkInfoCell.h"
|
||||
#import "ShowNetworksViewController.h"
|
||||
#import "JoinNetworkViewController.h"
|
13
ZeroTier One/main.m
Normal file
13
ZeroTier One/main.m
Normal file
|
@ -0,0 +1,13 @@
|
|||
//
|
||||
// main.m
|
||||
// testapp
|
||||
//
|
||||
// Created by Grant Limberg on 8/7/16.
|
||||
// Copyright © 2016 ZeroTier, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
int main(int argc, const char * argv[]) {
|
||||
return NSApplicationMain(argc, argv);
|
||||
}
|
Loading…
Add table
Reference in a new issue