Skip to content

Commit

Permalink
Merge pull request jimbojsb#18 from jimbojsb/jimbojsbgh-18
Browse files Browse the repository at this point in the history
Add debug logging
  • Loading branch information
jimbojsb committed Feb 19, 2014
2 parents 7fa9af4 + b2b432b commit f78cd42
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions LaunchRocket/LaunchRocket.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ @implementation LaunchRocket

- (void)mainViewDidLoad
{
NSLog(@"%@", @"Initialzing LaunchRocket");
ServiceManager *sm = [[ServiceManager alloc] initWithView:self.serviceParent];
[sm cleanServicesFile];
[self.homebrewScan setTarget:sm];
[self.homebrewScan setAction:@selector(handleHomebrewScanClick:)];
[self.addPlist setTarget:sm];
[self.addPlist setAction:@selector(handleAddPlistClick:)];

NSLog(@"%@", @"Setting fonts");
self.launchRocketLabel.font = [OpenSansFont getFontWithSize:16];
self.versionNumber.font = [OpenSansFont getFontWithSize:13];
[sm renderList];
Expand Down
5 changes: 5 additions & 0 deletions LaunchRocket/Process.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
@implementation Process

-(NSString *) execute:(NSString *)command {
NSLog(@"%@%@", @"Executing command: ", command);

NSString *sudoHelperPath = [NSString stringWithFormat:@"%@%@", [[NSBundle bundleForClass:[self class]] resourcePath], @"/sudo.app"];
NSMutableString *scriptSource = [NSMutableString stringWithFormat:@"tell application \"%@\"\n exec(\"%@\")\n end tell\n", sudoHelperPath, command];
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:scriptSource];
Expand All @@ -20,6 +22,8 @@ -(NSString *) execute:(NSString *)command {
}

-(NSString *) executeSudo:(NSString *)command {
NSLog(@"%@%@", @"Executing command with sudo: ", command);

NSString *sudoHelperPath = [NSString stringWithFormat:@"%@%@", [[NSBundle bundleForClass:[self class]] resourcePath], @"/sudo.app"];
NSMutableString *scriptSource = [NSMutableString stringWithFormat:@"tell application \"%@\"\n execsudo(\"%@\")\n end tell\n", sudoHelperPath, command];
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:scriptSource];
Expand All @@ -29,6 +33,7 @@ -(NSString *) executeSudo:(NSString *)command {
}

+(void) killSudoHelper {
NSLog(@"%@", @"Killing helper");
NSString *sudoHelperPath = [NSString stringWithFormat:@"%@%@", [[NSBundle bundleForClass:[self class]] resourcePath], @"/sudo.app"];
NSString *scriptSource = [NSString stringWithFormat:@"tell application \"%@\"\n stopscript()\n end tell\n", sudoHelperPath];
NSAppleScript *script = [[NSAppleScript new] initWithSource:scriptSource];
Expand Down
3 changes: 3 additions & 0 deletions LaunchRocket/ServiceController.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ @implementation ServiceController
@synthesize serviceManager;

-(id) initWithService:(Service *)theService {

NSLog(@"%@%@", @"Initializing service ", theService.identifier);

self = [super init];

self.service = theService;
Expand Down
27 changes: 27 additions & 0 deletions LaunchRocket/ServiceManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ @implementation ServiceManager
@synthesize serviceParent;

-(id) initWithView:(NSScrollView *)sv {

NSLog(@"%@", @"Initializing service mananger");
self = [super init];
self.serviceControllers = [[NSMutableArray alloc] init];
self.bundle = [NSBundle bundleForClass:[self class]];
Expand All @@ -32,13 +34,17 @@ -(id) initWithView:(NSScrollView *)sv {
}

-(void) createServicesFile {

NSFileManager *fm = [[NSFileManager alloc] init];
if (![fm fileExistsAtPath:self.servicesFilePath]) {
NSLog(@"%@", @"Creating preferences file");
[[[NSMutableDictionary alloc] init] writeToFile:self.servicesFilePath atomically:YES];
}
}

-(void) cleanServicesFile {

NSLog(@"%@", @"Removing non-existent services from preferences");
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:self.servicesFilePath];
NSFileManager *fm = [[NSFileManager alloc] init];
NSMutableArray *servicesToRemove = [[NSMutableArray alloc] init];
Expand All @@ -59,6 +65,7 @@ -(IBAction) handleHomebrewScanClick:(id)sender {
Process *p = [[Process alloc] init];
NSFileManager *fm = [[NSFileManager alloc] init];

NSLog(@"%@", @"Discovering bash profile files");
// try the most common way to get your homebrew prefix
NSArray *filesToMaybeSource = @[@".bash_profile", @".bashrc", @".profile"];
NSMutableArray *filesToSource = [[NSMutableArray alloc] init];
Expand All @@ -68,12 +75,19 @@ -(IBAction) handleHomebrewScanClick:(id)sender {
[filesToSource addObject:[NSString stringWithFormat:@"source %@", filePath]];
}
}

NSString *homebrewBashCommand = [NSString stringWithFormat:@"%@ && brew --prefix", [filesToSource componentsJoinedByString:@" && "]];
NSLog(@"%@%@", @"Resolved homebrew path command: ", homebrewBashCommand);


NSString *homebrewPath = [p execute:homebrewBashCommand];
NSLog(@"%@%@", @"Homebrew prefix: ", homebrewPath);


//if that doesn't work, we need the path to your brew executable
if ([homebrewPath isEqualToString:@""]) {

NSLog(@"%@", @"Homebrew path not found on initial attempt");
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"OK"];
[alert addButtonWithTitle:@"Cancel"];
Expand All @@ -83,6 +97,7 @@ -(IBAction) handleHomebrewScanClick:(id)sender {
return;
}

NSLog(@"%@", @"Waiting for file selection");
NSOpenPanel *brewPicker = [NSOpenPanel openPanel];
[brewPicker setCanChooseDirectories:NO];
[brewPicker setCanChooseFiles:YES];
Expand All @@ -92,7 +107,10 @@ -(IBAction) handleHomebrewScanClick:(id)sender {
NSInteger clicked = [brewPicker runModal];
if (clicked == NSFileHandlingPanelOKButton) {
NSString *brew = [[brewPicker URL] path];
NSLog(@"%@%@", @"Path to brew: ", homebrewPath);

homebrewPath = [p execute:[NSString stringWithFormat:@"%@%@", brew, @" --prefix"]];
NSLog(@"%@%@", @"Homebrew prefix: ", homebrewPath);
}
}

Expand All @@ -103,6 +121,8 @@ -(IBAction) handleHomebrewScanClick:(id)sender {
[alert setMessageText:@"We couldn't find your homebrew prefix using your Bash profile or the file you selected."];
[alert setAlertStyle:NSWarningAlertStyle];
[alert beginSheetModalForWindow:[self.serviceParent window] completionHandler:nil];
NSLog(@"%@", @"Unable to find Homebrew path");

}


Expand Down Expand Up @@ -148,6 +168,7 @@ -(IBAction) handleAddPlistClick:(id)sender {
}

-(void) addService:(NSString *)plistFile {
NSLog(@"%@%@", @"Adding services", plistFile);
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
NSArray *pathComponents = [plistFile componentsSeparatedByString:@"/"];
NSArray *filenameComponents = [[pathComponents lastObject] componentsSeparatedByString:@"."];
Expand All @@ -159,24 +180,28 @@ -(void) addService:(NSString *)plistFile {
NSMutableDictionary *servicesList = [[NSMutableDictionary alloc] initWithContentsOfFile:self.servicesFilePath];
[servicesList setObject:dict forKey:identifier];
[servicesList writeToFile:self.servicesFilePath atomically:YES];
NSLog(@"%@", @"Wrote services file");
}

-(void) saveService:(Service *)service {
NSMutableDictionary *servicesList = [[NSMutableDictionary alloc] initWithContentsOfFile:self.servicesFilePath];
[servicesList setObject:[service getPlistData] forKey:service.identifier];
[servicesList writeToFile:self.servicesFilePath atomically:YES];
NSLog(@"%@", @"Wrote services file");
}

-(void) removeService:(Service *)service {
NSMutableDictionary *servicesList = [[NSMutableDictionary alloc] initWithContentsOfFile:self.servicesFilePath];
[servicesList removeObjectForKey:service.identifier];
[servicesList writeToFile:self.servicesFilePath atomically:YES];
NSLog(@"%@", @"Wrote services file");
[self loadServicesFromPlist];
[self renderList];
}


-(void) loadServicesFromPlist {
NSLog(@"%@", @"Attempting to load services from plist");
[self.serviceControllers release];
self.serviceControllers = [[NSMutableArray alloc] init];
NSDictionary *plistData = [NSDictionary dictionaryWithContentsOfFile:self.servicesFilePath];
Expand All @@ -188,6 +213,8 @@ -(void) loadServicesFromPlist {
sc.service = service;
[self.serviceControllers addObject:sc];
}
NSLog(@"%@", @"Successfully loaded services from plist");

}


Expand Down

0 comments on commit f78cd42

Please sign in to comment.