From 68d620fca339c1ed67af18cbd7c81b6054e0fbbc Mon Sep 17 00:00:00 2001 From: dante ruiz Date: Tue, 25 Jun 2019 13:37:45 -0700 Subject: [PATCH 1/2] fix crash --- launchers/darwin/src/LatestBuildRequest.m | 19 +++++++++++++------ launchers/darwin/src/main.mm | 10 +++++----- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/launchers/darwin/src/LatestBuildRequest.m b/launchers/darwin/src/LatestBuildRequest.m index 7e836548af..fd233afd0e 100644 --- a/launchers/darwin/src/LatestBuildRequest.m +++ b/launchers/darwin/src/LatestBuildRequest.m @@ -6,12 +6,18 @@ @implementation LatestBuildRequest - (NSInteger) getCurrentVersion { - NSString* interfaceAppPath = [[Launcher.sharedLauncher getAppPath] stringByAppendingString:@"interface.app"]; - NSError * error = nil; - Interface * interface = [[Interface alloc] initWith:interfaceAppPath]; - NSInteger currentVersion = [interface getVersion:&error]; - if (currentVersion == 0 && error != nil) { - NSLog(@"can't get version from interface, falling back to settings: %@", error); + NSInteger currentVersion; + @try { + NSString* interfaceAppPath = [[Launcher.sharedLauncher getAppPath] stringByAppendingString:@"interface.app"]; + NSError * error = nil; + Interface * interface = [[Interface alloc] initWith:interfaceAppPath]; + currentVersion = [interface getVersion:&error]; + if (currentVersion == 0 && error != nil) { + NSLog(@"can't get version from interface, falling back to settings: %@", error); + currentVersion = [Settings.sharedSettings latestBuildVersion]; + } + } @catch (NSException *exception) { + NSLog(@"an exception was thrown"); currentVersion = [Settings.sharedSettings latestBuildVersion]; } return currentVersion; @@ -58,6 +64,7 @@ BOOL appDirectoryExist = [fileManager fileExistsAtPath:[[sharedLauncher getAppPath] stringByAppendingString:@"interface.app"]]; dispatch_async(dispatch_get_main_queue(), ^{ + NSInteger currentVersion = [self getCurrentVersion]; NSLog(@"Latest Build Request -> does build directory exist: %@", appDirectoryExist ? @"TRUE" : @"FALSE"); NSLog(@"Latest Build Request -> current version: %ld", currentVersion); diff --git a/launchers/darwin/src/main.mm b/launchers/darwin/src/main.mm index 7feab64d86..b6555aad87 100644 --- a/launchers/darwin/src/main.mm +++ b/launchers/darwin/src/main.mm @@ -5,13 +5,13 @@ void redirectLogToDocuments() { NSString* filePath = [[NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingString:@"/Launcher/"]; - + if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) { NSError * error = nil; [[NSFileManager defaultManager] createDirectoryAtPath:filePath withIntermediateDirectories:TRUE attributes:nil error:&error]; } NSString *pathForLog = [filePath stringByAppendingPathComponent:@"log.txt"]; - + freopen([pathForLog cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr); } @@ -23,12 +23,12 @@ int main(int argc, const char* argv[]) { NSLog(@"launcher is already running"); return 0; } - + [NSApplication sharedApplication]; Launcher* sharedLauncher = [Launcher sharedLauncher]; [Settings sharedSettings]; [NSApp setDelegate: sharedLauncher]; - + // Referenced from https://stackoverflow.com/questions/9155015/handle-cmd-q-in-cocoa-application-and-menu-item-quit-application-programmatic id menubar = [[NSMenu new] autorelease]; id appMenuItem = [[NSMenuItem new] autorelease]; @@ -40,7 +40,7 @@ int main(int argc, const char* argv[]) { id quitMenuItem = [[[NSMenuItem alloc] initWithTitle:quitTitle action:@selector(terminate:) keyEquivalent:@"q"] autorelease]; [appMenu addItem:quitMenuItem]; [appMenuItem setSubmenu:appMenu]; - + [[NSApplication sharedApplication] activateIgnoringOtherApps:TRUE]; return NSApplicationMain(argc, argv); } From 1e38e7b7eb000714e616b7455e2f0e99e3890309 Mon Sep 17 00:00:00 2001 From: dante ruiz Date: Tue, 25 Jun 2019 14:11:41 -0700 Subject: [PATCH 2/2] print out exception error --- launchers/darwin/src/LatestBuildRequest.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launchers/darwin/src/LatestBuildRequest.m b/launchers/darwin/src/LatestBuildRequest.m index fd233afd0e..0c136dce3c 100644 --- a/launchers/darwin/src/LatestBuildRequest.m +++ b/launchers/darwin/src/LatestBuildRequest.m @@ -17,7 +17,7 @@ currentVersion = [Settings.sharedSettings latestBuildVersion]; } } @catch (NSException *exception) { - NSLog(@"an exception was thrown"); + NSLog(@"an exception was thrown: %@", exception); currentVersion = [Settings.sharedSettings latestBuildVersion]; } return currentVersion;