Skip to content

Commit 4c1d34e

Browse files
committed
Merge pull request nwjs#1769 from ribrain/master
Fix for issue 934: added URL scheme support for MAC.
2 parents b6903a4 + 00b7a54 commit 4c1d34e

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/browser/app_controller_mac.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
#import <Cocoa/Cocoa.h>
2525

2626
@interface AppController : NSObject<NSApplicationDelegate> {
27+
BOOL appReady;
2728
}
29+
30+
@property(nonatomic) BOOL appReady;
31+
2832
@end
2933

3034
#endif // CONTENT_NW_SRC_BROWSER_APP_CONTROLLER_MAC_H_

src/browser/app_controller_mac.mm

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
@implementation AppController
3333

34+
@synthesize appReady;
35+
3436
- (BOOL)application:(NSApplication*)sender
3537
openFile:(NSString*)filename {
3638
if (content::Shell::windows().size() == 0) {
@@ -52,6 +54,15 @@ - (BOOL)application:(NSApplication*)sender
5254
return FALSE;
5355
}
5456

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+
5566
- (void) applicationDidFinishLaunching: (NSNotification *) note {
5667
// Initlialize everything here
5768
content::ShellContentBrowserClient* browser_client =
@@ -74,6 +85,7 @@ - (void) applicationDidFinishLaunching: (NSNotification *) note {
7485
standard_menus.BuildEditMenu();
7586
standard_menus.BuildWindowMenu();
7687
#endif
88+
self.appReady = TRUE;
7789
}
7890

7991
- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication
@@ -82,6 +94,22 @@ - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication
8294
return YES;
8395
}
8496

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+
85113
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)app {
86114
// The termination procedure is completely and gracefully handled by node-webkit
87115
// (triggered by CloseAllWindows, app exits when last window closes) so we

0 commit comments

Comments
 (0)