mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-08-20 13:24:09 -07:00
Pass authtoken in from user, and add a wrapper for web UI on Mac.
This commit is contained in:
parent
e58047eaa0
commit
5b54612d91
68 changed files with 7537 additions and 1 deletions
128
ext/mac-ui-macgap1-wrapper/MacGap/Classes/Commands/App.m
Normal file
128
ext/mac-ui-macgap1-wrapper/MacGap/Classes/Commands/App.m
Normal file
|
@ -0,0 +1,128 @@
|
|||
#import "App.h"
|
||||
|
||||
#import "JSEventHelper.h"
|
||||
|
||||
@implementation App
|
||||
|
||||
@synthesize webView;
|
||||
|
||||
- (id) initWithWebView:(WebView *) view{
|
||||
self = [super init];
|
||||
|
||||
if (self) {
|
||||
self.webView = view;
|
||||
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: self
|
||||
selector: @selector(receiveSleepNotification:)
|
||||
name: NSWorkspaceWillSleepNotification object: NULL];
|
||||
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: self
|
||||
selector: @selector(receiveWakeNotification:)
|
||||
name: NSWorkspaceDidWakeNotification object: NULL];
|
||||
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: self
|
||||
selector: @selector(receiveActivateNotification:)
|
||||
name: NSWorkspaceDidActivateApplicationNotification object: NULL];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) terminate {
|
||||
[NSApp terminate:nil];
|
||||
}
|
||||
|
||||
- (void) activate {
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
}
|
||||
|
||||
- (void) hide {
|
||||
[NSApp hide:nil];
|
||||
}
|
||||
|
||||
- (void) unhide {
|
||||
[NSApp unhide:nil];
|
||||
}
|
||||
|
||||
- (void)beep {
|
||||
NSBeep();
|
||||
}
|
||||
|
||||
- (void) bounce {
|
||||
[NSApp requestUserAttention:NSInformationalRequest];
|
||||
}
|
||||
|
||||
- (void)setCustomUserAgent:(NSString *)userAgentString {
|
||||
[self.webView setCustomUserAgent: userAgentString];
|
||||
}
|
||||
|
||||
- (void) open:(NSString*)url {
|
||||
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:url]];
|
||||
}
|
||||
|
||||
- (void) launch:(NSString *)name {
|
||||
[[NSWorkspace sharedWorkspace] launchApplication:name];
|
||||
}
|
||||
|
||||
- (void)receiveSleepNotification:(NSNotification*)note{
|
||||
[JSEventHelper triggerEvent:@"sleep" forWebView:self.webView];
|
||||
}
|
||||
|
||||
- (void) receiveWakeNotification:(NSNotification*)note{
|
||||
[JSEventHelper triggerEvent:@"wake" forWebView:self.webView];
|
||||
}
|
||||
|
||||
- (void) receiveActivateNotification:(NSNotification*)notification{
|
||||
NSDictionary* userInfo = [notification userInfo];
|
||||
NSRunningApplication* runningApplication = [userInfo objectForKey:NSWorkspaceApplicationKey];
|
||||
if (runningApplication) {
|
||||
NSMutableDictionary* applicationDidGetFocusDict = [[NSMutableDictionary alloc] initWithCapacity:2];
|
||||
[applicationDidGetFocusDict setObject:runningApplication.localizedName
|
||||
forKey:@"localizedName"];
|
||||
[applicationDidGetFocusDict setObject:[runningApplication.bundleURL absoluteString]
|
||||
forKey:@"bundleURL"];
|
||||
|
||||
[JSEventHelper triggerEvent:@"appActivated" withArgs:applicationDidGetFocusDict forWebView:self.webView];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
To get the elapsed time since the previous input event—keyboard, mouse, or tablet—specify kCGAnyInputEventType.
|
||||
*/
|
||||
- (NSNumber*)systemIdleTime {
|
||||
CFTimeInterval timeSinceLastEvent = CGEventSourceSecondsSinceLastEventType(kCGEventSourceStateHIDSystemState, kCGAnyInputEventType);
|
||||
|
||||
return [NSNumber numberWithDouble:timeSinceLastEvent];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+ (NSString*) webScriptNameForSelector:(SEL)selector
|
||||
{
|
||||
id result = nil;
|
||||
|
||||
if (selector == @selector(open:)) {
|
||||
result = @"open";
|
||||
} else if (selector == @selector(launch:)) {
|
||||
result = @"launch";
|
||||
} else if (selector == @selector(setCustomUserAgent:)) {
|
||||
result = @"setCustomUserAgent";
|
||||
} else if (selector == @selector(systemIdleTime)) {
|
||||
result = @"systemIdleTime";
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
+ (BOOL) isSelectorExcludedFromWebScript:(SEL)selector
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
+ (BOOL) isKeyExcludedFromWebScript:(const char*)name
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
Loading…
Add table
Add a link
Reference in a new issue