Atom cli can be called multiple times. Successive calls will open the given path in the existing Atom process.

This commit is contained in:
Corey Johnson & Nathan Sobo 2012-09-12 17:06:28 -07:00
parent e2700395cf
commit ff07710556
3 changed files with 13 additions and 3 deletions

View File

@ -9,6 +9,7 @@ class AtomCefClient;
BOOL handlingSendEvent_;
}
+ (AtomApplication *)sharedApplication;
+ (id)applicationWithArguments:(char **)argv count:(int)argc;
+ (CefSettings)createCefSettings;
+ (NSDictionary *)parseArguments:(char **)argv count:(int)argc;

View File

@ -9,8 +9,12 @@
@synthesize arguments=_arguments;
+ (AtomApplication *)sharedApplication {
return (AtomApplication *)[super sharedApplication];
}
+ (id)applicationWithArguments:(char **)argv count:(int)argc {
AtomApplication *application = (AtomApplication *)[super sharedApplication];
AtomApplication *application = [self sharedApplication];
CefInitialize(CefMainArgs(argc, argv), [self createCefSettings], new AtomCefApp);
application.arguments = [self parseArguments:argv count:argc];

View File

@ -67,18 +67,23 @@ void listenForPathToOpen(int fd, NSString *socketPath) {
else {
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
char buf[1000];
char buf[MAXPATHLEN];
struct sockaddr_un listen_addr;
listen_addr.sun_family = AF_UNIX;
strcpy(listen_addr.sun_path, [socketPath UTF8String]);
socklen_t listen_addr_length;
while(true) {
memset(buf, 0, MAXPATHLEN);
if (recvfrom(fd, &buf, sizeof(buf), 0, (sockaddr *)&listen_addr, &listen_addr_length) < 0) {
perror("ERROR: Receiving from socket");
}
else {
NSLog(@"You should open the path %s", buf);
NSString *path = [NSString stringWithUTF8String:buf];
dispatch_queue_t mainQueue = dispatch_get_main_queue();
dispatch_async(mainQueue, ^{
[[AtomApplication sharedApplication] open:path];
});
}
}
});