31
31
32
32
@implementation AppController
33
33
34
+ @synthesize appReady;
35
+
34
36
- (BOOL )application : (NSApplication *)sender
35
37
openFile : (NSString *)filename {
36
38
if (content::Shell::windows ().size () == 0 ) {
@@ -52,6 +54,15 @@ - (BOOL)application:(NSApplication*)sender
52
54
return FALSE ;
53
55
}
54
56
57
+ - (void ) applicationWillFinishLaunching : (NSNotification *) note {
58
+ self.appReady = FALSE ;
59
+ NSAppleEventManager *eventManager = [NSAppleEventManager sharedAppleEventManager ];
60
+ [eventManager setEventHandler: self
61
+ andSelector: @selector (handleGetURLEvent:withReplyEvent: )
62
+ forEventClass: kInternetEventClass
63
+ andEventID: kAEGetURL ];
64
+ }
65
+
55
66
- (void ) applicationDidFinishLaunching : (NSNotification *) note {
56
67
// Initlialize everything here
57
68
content::ShellContentBrowserClient* browser_client =
@@ -74,6 +85,7 @@ - (void) applicationDidFinishLaunching: (NSNotification *) note {
74
85
standard_menus.BuildEditMenu();
75
86
standard_menus.BuildWindowMenu();
76
87
#endif
88
+ self.appReady = TRUE ;
77
89
}
78
90
79
91
- (BOOL )applicationShouldHandleReopen : (NSApplication *)theApplication
@@ -82,6 +94,22 @@ - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication
82
94
return YES ;
83
95
}
84
96
97
+ - (void )handleGetURLEvent : (NSAppleEventDescriptor *)event withReplyEvent : (NSAppleEventDescriptor *)replyEvent
98
+ {
99
+ NSString *urlString = [[event paramDescriptorForKeyword: keyDirectObject] stringValue ];
100
+ if (self.appReady ) {
101
+ // Immediate handle of get url event
102
+ nwapi::App::EmitOpenEvent ([urlString UTF8String ]);
103
+ } else {
104
+ // App is not ready yet, add the URL to the command line arguments.
105
+ // This happens when the app is started by opening a link with the registered URL.
106
+ if (content::Shell::windows ().size () == 0 ) {
107
+ CommandLine::ForCurrentProcess ()->AppendArg ([urlString UTF8String ]);
108
+ CommandLine::ForCurrentProcess ()->FixOrigArgv4Finder ([urlString UTF8String ]);
109
+ }
110
+ }
111
+ }
112
+
85
113
- (NSApplicationTerminateReply )applicationShouldTerminate : (NSApplication *)app {
86
114
// The termination procedure is completely and gracefully handled by node-webkit
87
115
// (triggered by CloseAllWindows, app exits when last window closes) so we
0 commit comments