From 28bd8ea459c7c499841154725de1326905f70a41 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 11 Sep 2012 17:38:27 -0700 Subject: [PATCH] wip --- Rakefile | 9 ++++--- native/atom_application.mm | 5 ++++ native/mac/info.plist | 46 ++++++++++++++++++---------------- native/main_mac.mm | 51 +++++++++++++++++++++++++++++++++++++- 4 files changed, 84 insertions(+), 27 deletions(-) diff --git a/Rakefile b/Rakefile index 9262384a5..76ec0c76b 100644 --- a/Rakefile +++ b/Rakefile @@ -7,8 +7,8 @@ desc "Create xcode project from gpy file" task "create-project" do `rm -rf atom.xcodeproj` `python tools/gyp/gyp --depth=. atom.gyp` - `killall -c Xcode -9` - `open atom.xcodeproj` # In order for the xcodebuild to know about the schemes, the project needs to have been opened once. This is xcode bullshit and is a bug on Apple's end (No radar has been file because I have no faith in radar's) + # `killall -c Xcode -9` + # `open atom.xcodeproj` # In order for the xcodebuild to know about the schemes, the project needs to have been opened once. This is xcode bullshit and is a bug on Apple's end (No radar has been file because I have no faith in radar's) sleep 0 while `xcodebuild -list` =~ /This project contains no schemes./ # Give xcode some time to open end @@ -47,7 +47,8 @@ task :install => :build do usr_bin_exists = ENV["PATH"].split(":").include?(usr_bin) if usr_bin_exists cli_path = "#{usr_bin}/atom" - `echo '#!/bin/sh\nopen #{path.strip} --args $@' > #{cli_path} && chmod 755 #{cli_path}` + # `echo '#!/bin/sh\nopen #{path.strip} --args $@' > #{cli_path} && chmod 755 #{cli_path}` + `echo '#!/bin/sh\n#{path}/Contents/MacOS/Atom $@' > #{cli_path} && chmod 755 #{cli_path}` else stderr.puts "ERROR: Did not add cli tool for `atom` because /usr/local/bin does not exist" end @@ -119,5 +120,5 @@ def application_path $stderr.puts "Error: No .xcodebuild-info file found. This file is created when the `build` raketask is run" end - return path + return path.strip() end diff --git a/native/atom_application.mm b/native/atom_application.mm index 3cf3391b7..e38da41be 100644 --- a/native/atom_application.mm +++ b/native/atom_application.mm @@ -137,6 +137,11 @@ CefShutdown(); } +- (BOOL)applicationShouldHandleReopen:(NSApplication *)application hasVisibleWindows:(BOOL)flag { + NSLog(@"%@", @"OK OK OK"); + return YES; +} + # pragma mark CefAppProtocol - (BOOL)isHandlingSendEvent { diff --git a/native/mac/info.plist b/native/mac/info.plist index b21953721..e7d56bf78 100644 --- a/native/mac/info.plist +++ b/native/mac/info.plist @@ -2,27 +2,29 @@ - CFBundleDevelopmentRegion - English - CFBundleExecutable - ${EXECUTABLE_NAME} - CFBundleIconFile - atom.icns - CFBundleIdentifier - com.github.atom - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - ${PRODUCT_NAME} - CFBundlePackageType - APPL - CFBundleSignature - ???? - CFBundleVersion - 1.0 - NSMainNibFile - MainMenu - NSPrincipalClass - AtomApp + LSMultipleInstancesProhibited + + CFBundleDevelopmentRegion + English + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIconFile + atom.icns + CFBundleIdentifier + com.github.atom + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + APPL + CFBundleSignature + ???? + CFBundleVersion + 1.0 + NSMainNibFile + MainMenu + NSPrincipalClass + AtomApp diff --git a/native/main_mac.mm b/native/main_mac.mm index bbed2bd8a..7857e6b86 100644 --- a/native/main_mac.mm +++ b/native/main_mac.mm @@ -1,16 +1,65 @@ #import "include/cef_application_mac.h" #import "native/atom_application.h" +#include +#include +#include int main(int argc, char* argv[]) { @autoreleasepool { + int fd = socket(AF_UNIX, SOCK_STREAM, 0); + struct sockaddr_un addr = { 0, AF_UNIX }; + NSString *socketPath = [NSString stringWithFormat:@"/tmp/atom-%d.sock", getuid()]; + strcpy(addr.sun_path, [socketPath UTF8String]); + addr.sun_len = SUN_LEN(&addr); + + for (NSRunningApplication *app in [[NSWorkspace sharedWorkspace] runningApplications]) { + if ([[app bundleIdentifier] isEqualToString:[[NSBundle mainBundle] bundleIdentifier]]) { + NSLog(@"%@", @"Well fuck dude, there are two apps open, better send the other one a message!"); + + struct sockaddr to_addr; + to_addr.sa_family = AF_UNIX; + strcpy(to_addr.sa_data, [socketPath UTF8String]); + + char buf[] = "WE JUMPED THE PROCESS"; + if (sendto(fd, buf, sizeof(buf), 0, &to_addr, sizeof(to_addr)) < 0) { + NSLog(@"Send failure"); + exit(1); + } + exit(0); + } + } + + if (connect(fd, (sockaddr*)&addr, sizeof(addr)) < 0) { + NSLog(@"EVERYTHING FUCKED UP"); + } + else { + NSLog(@"I AM LISTENING"); + + dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); + dispatch_async(queue, ^{ + char buf[1000]; + struct sockaddr from_addr; + from_addr.sa_family = AF_UNIX; + strcpy(from_addr.sa_data, [socketPath UTF8String]); + + if (recvfrom(fd, &buf, sizeof(buf), 0, &from_addr, sizeof(from_addr)) < 0) { + NSLog(@"NO GOOD, RECEIVE FAILURE"); + } + else { + NSLog(@"GOOD! Got %s", buf); + } + }); + } + NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; AtomApplication *application = [AtomApplication applicationWithArguments:argv count:argc]; NSString *mainNibName = [infoDictionary objectForKey:@"NSMainNibFile"]; NSNib *mainNib = [[NSNib alloc] initWithNibNamed:mainNibName bundle:[NSBundle mainBundle]]; [mainNib instantiateNibWithOwner:application topLevelObjects:nil]; - + CefRunMessageLoop(); + close(fd); } return 0;