diff --git a/launchers/darwin/CMakeLists.txt b/launchers/darwin/CMakeLists.txt index a3fc0dc7c1..0a7ef70461 100644 --- a/launchers/darwin/CMakeLists.txt +++ b/launchers/darwin/CMakeLists.txt @@ -27,6 +27,8 @@ set(src_files src/LatestBuildRequest.m src/OrganizationRequest.m src/OrganizationRequest.h + src/ImageView.m + src/ImageView.h src/Interface.h src/Interface.m src/ErrorViewController.h diff --git a/launchers/darwin/nib/DisplayNameScreen.xib b/launchers/darwin/nib/DisplayNameScreen.xib index 3ba3deba53..94fa739f8e 100644 --- a/launchers/darwin/nib/DisplayNameScreen.xib +++ b/launchers/darwin/nib/DisplayNameScreen.xib @@ -16,13 +16,13 @@ - + - + @@ -70,12 +70,12 @@ - + - - + + - + diff --git a/launchers/darwin/nib/ProcessScreen.xib b/launchers/darwin/nib/ProcessScreen.xib index c6bd8abbec..d6a1da91c9 100644 --- a/launchers/darwin/nib/ProcessScreen.xib +++ b/launchers/darwin/nib/ProcessScreen.xib @@ -16,7 +16,7 @@ - + diff --git a/launchers/darwin/nib/SplashScreen.xib b/launchers/darwin/nib/SplashScreen.xib index 3e2e37c81a..3bbed22a59 100644 --- a/launchers/darwin/nib/SplashScreen.xib +++ b/launchers/darwin/nib/SplashScreen.xib @@ -16,7 +16,7 @@ - + diff --git a/launchers/darwin/src/CredentialsRequest.h b/launchers/darwin/src/CredentialsRequest.h index 2e0807c5ba..d1ddfee2df 100644 --- a/launchers/darwin/src/CredentialsRequest.h +++ b/launchers/darwin/src/CredentialsRequest.h @@ -1,10 +1,7 @@ #import -@interface CredentialsRequest : NSObject { +@interface CredentialsRequest : NSObject { } -@property (nonatomic, retain) NSMutableData* webData; -@property (nonatomic, retain) NSString* jsonString; - - (void) confirmCredentials:(NSString*)username :(NSString*)password; @end diff --git a/launchers/darwin/src/CredentialsRequest.m b/launchers/darwin/src/CredentialsRequest.m index a5c24496ec..6d534447f1 100644 --- a/launchers/darwin/src/CredentialsRequest.m +++ b/launchers/darwin/src/CredentialsRequest.m @@ -2,6 +2,11 @@ #import "Launcher.h" #import "Settings.h" +@interface CredentialsRequest () +@property (nonatomic, assign) NSMutableData* receivedData; +@property (nonatomic, assign) NSInteger statusCode; +@end + @implementation CredentialsRequest - (void) confirmCredentials:(NSString*)username :(NSString*)password { @@ -21,77 +26,70 @@ [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody:postData]; - NSURLSession* session = [NSURLSession sharedSession]; - NSURLSessionDataTask* dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { - - NSLog(@"credentials request finished"); - NSMutableData* webData = [NSMutableData data]; - [webData appendData:data]; - NSString* jsonString = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[data length] encoding:NSUTF8StringEncoding]; - NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; - id json = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil]; - - Launcher* sharedLauncher = [Launcher sharedLauncher]; - if (json[@"error"] != nil) { - dispatch_async(dispatch_get_main_queue(), ^{ - [[Settings sharedSettings] login:FALSE]; - [sharedLauncher setLoginErrorState: CREDENTIALS]; - [sharedLauncher credentialsAccepted:FALSE]; - }); - } else { - dispatch_async(dispatch_get_main_queue(), ^{ - [[Settings sharedSettings] login:TRUE]; - [sharedLauncher setTokenString:jsonString]; - [sharedLauncher credentialsAccepted:TRUE]; - }); - } - - NSLog(@"credentials: connectionDidFinished completed"); - - }]; - + NSURLSession* session = [NSURLSession sessionWithConfiguration:NSURLSessionConfiguration.ephemeralSessionConfiguration delegate: self delegateQueue: [NSOperationQueue mainQueue]]; + NSURLSessionDataTask* dataTask = [session dataTaskWithRequest:request]; + [dataTask resume]; } -- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { - [self.webData appendData:data]; - NSLog(@"credentials connection received data"); -} -- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { - NSLog(@"credentials connection received response"); +- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSURLResponse *)response + completionHandler:(void (^)(NSURLSessionResponseDisposition disposition))completionHandler { + self.receivedData = nil; + self.receivedData = [[NSMutableData alloc] init]; + [self.receivedData setLength:0]; NSHTTPURLResponse *ne = (NSHTTPURLResponse *)response; - if([ne statusCode] == 200) { - NSLog(@"connection state is 200 - all okay"); - } else { - NSLog(@"connection state is NOT 200"); - [[Launcher sharedLauncher] displayErrorPage]; - } + self.statusCode = [ne statusCode]; + NSLog(@"Credentials Response status code: %ld", self.statusCode); + completionHandler(NSURLSessionResponseAllow); } --(void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { - NSLog(@"Conn Err: %@", [error localizedDescription]); - [[Launcher sharedLauncher] displayErrorPage]; + +-(void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask + didReceiveData:(NSData *)data { + + [self.receivedData appendData:data]; + NSLog(@"Credentials: did recieve data"); } -- (void)connectionDidFinishLoading:(NSURLConnection *)connection { - NSLog(@"credentials request finished"); - NSString* jsonString = [[NSString alloc] initWithBytes: [self.webData mutableBytes] length:[self.webData length] encoding:NSUTF8StringEncoding]; - NSData *data = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; - id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; - +- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error { Launcher* sharedLauncher = [Launcher sharedLauncher]; - if (json[@"error"] != nil) { - [[Settings sharedSettings] login:FALSE]; - [sharedLauncher setLoginErrorState: CREDENTIALS]; - [sharedLauncher credentialsAccepted:FALSE]; + if (error) { + NSLog(@"Credentials: Request completed with an error -> error: %@", error); + [sharedLauncher displayErrorPage]; } else { - [[Settings sharedSettings] login:TRUE]; - [sharedLauncher setTokenString:jsonString]; - [sharedLauncher credentialsAccepted:TRUE]; - } - - NSLog(@"credentials: connectionDidFinished completed"); -} + if (self.statusCode == 200) { + NSString* jsonString = [[NSString alloc] initWithBytes: [self.receivedData mutableBytes] length:[self.receivedData length] encoding:NSUTF8StringEncoding]; + NSData* jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; + NSError* jsonError = nil; + id json = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&jsonError]; + if (jsonError) { + NSLog(@"Credentials: Failed to parse json -> error: %@", jsonError); + NSLog(@"Credentials: JSON string from data: %@", jsonString); + [sharedLauncher displayErrorPage]; + return; + } + + if (json[@"error"] != nil) { + NSLog(@"Credentials: Login failed -> error: %@", json[@"error"]); + [[Settings sharedSettings] login:FALSE]; + [sharedLauncher setLoginErrorState: CREDENTIALS]; + [sharedLauncher credentialsAccepted:FALSE]; + } else { + NSLog(@"Credentials: Login succeeded"); + [[Settings sharedSettings] login:TRUE]; + [sharedLauncher setTokenString:jsonString]; + [sharedLauncher credentialsAccepted:TRUE]; + } + } else if (self.statusCode == 403 || self.statusCode == 404 || self.statusCode == 401) { + NSLog(@"Credentials: Log failed with statusCode: %ld", self.statusCode); + [[Settings sharedSettings] login:FALSE]; + [sharedLauncher setLoginErrorState: CREDENTIALS]; + [sharedLauncher credentialsAccepted:FALSE]; + } else { + [sharedLauncher displayErrorPage]; + } + } +} @end diff --git a/launchers/darwin/src/DownloadDomainContent.m b/launchers/darwin/src/DownloadDomainContent.m index 65878db356..170ee1d43b 100644 --- a/launchers/darwin/src/DownloadDomainContent.m +++ b/launchers/darwin/src/DownloadDomainContent.m @@ -8,7 +8,7 @@ NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:domainContentUrl] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; - + NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: self delegateQueue: [NSOperationQueue mainQueue]]; NSURLSessionDownloadTask *downloadTask = [defaultSession downloadTaskWithRequest:request]; @@ -18,7 +18,7 @@ -(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite { CGFloat prog = (float)totalBytesWritten/totalBytesExpectedToWrite; NSLog(@"domain content downloaded %d%%", (int)(100.0*prog)); - + } -(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didResumeAtOffset:(int64_t)fileOffset expectedTotalBytes:(int64_t)expectedTotalBytes { @@ -27,7 +27,7 @@ -(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location { NSLog(@"Did finish downloading to url"); - NSError *error; + NSError *error = nil; NSFileManager *fileManager = [NSFileManager defaultManager]; NSString *destinationFileName = downloadTask.originalRequest.URL.lastPathComponent; NSString* finalFilePath = [[[Launcher sharedLauncher] getDownloadPathForContentAndScripts] stringByAppendingPathComponent:destinationFileName]; @@ -36,18 +36,28 @@ { [fileManager removeItemAtURL:destinationURL error:nil]; } - - NSLog(@"%@", location.path); - NSLog(@"%@", destinationURL); + + NSLog(@"location: %@", location.path); + NSLog(@"destination: %@", destinationURL); BOOL success = [fileManager moveItemAtURL:location toURL:destinationURL error:&error]; - - + + NSLog(success ? @"TRUE" : @"FALSE"); Launcher* sharedLauncher = [Launcher sharedLauncher]; + + if (error) { + NSLog(@"DownlodDomainContent: failed to move file to destintation -> error: %@", error); + [sharedLauncher displayErrorPage]; + return; + } [sharedLauncher setDownloadContextFilename:destinationFileName]; NSLog(@"extracting domain content file"); - [sharedLauncher extractZipFileAtDestination:[[sharedLauncher getDownloadPathForContentAndScripts] stringByAppendingString:@"content"] :[[sharedLauncher getDownloadPathForContentAndScripts] stringByAppendingString:[sharedLauncher getDownloadContentFilename]]]; - + BOOL extractionSuccessful = [sharedLauncher extractZipFileAtDestination:[[sharedLauncher getDownloadPathForContentAndScripts] stringByAppendingString:@"content"] :[[sharedLauncher getDownloadPathForContentAndScripts] stringByAppendingString:[sharedLauncher getDownloadContentFilename]]]; + + if (!extractionSuccessful) { + [sharedLauncher displayErrorPage]; + return; + } NSLog(@"finished extracting content file"); [sharedLauncher domainContentDownloadFinished]; } diff --git a/launchers/darwin/src/DownloadInterface.m b/launchers/darwin/src/DownloadInterface.m index 7a8abf2e0a..28980310c5 100644 --- a/launchers/darwin/src/DownloadInterface.m +++ b/launchers/darwin/src/DownloadInterface.m @@ -9,18 +9,18 @@ NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:downloadUrl] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; - + NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: self delegateQueue: [NSOperationQueue mainQueue]]; NSURLSessionDownloadTask *downloadTask = [defaultSession downloadTaskWithRequest:request]; - + [downloadTask resume]; } -(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite { CGFloat prog = (float)totalBytesWritten/totalBytesExpectedToWrite; NSLog(@"interface downloaded %d%%", (int)(100.0*prog)); - + } -(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didResumeAtOffset:(int64_t)fileOffset expectedTotalBytes:(int64_t)expectedTotalBytes { @@ -29,7 +29,7 @@ -(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location { NSLog(@"Did finish downloading to url"); - NSError *error; + NSError *error = nil; NSFileManager *fileManager = [NSFileManager defaultManager]; NSString *destinationFileName = downloadTask.originalRequest.URL.lastPathComponent; NSString* finalFilePath = [[[Launcher sharedLauncher] getAppPath] stringByAppendingPathComponent:destinationFileName]; @@ -39,34 +39,44 @@ [fileManager removeItemAtURL:destinationURL error:nil]; } [fileManager moveItemAtURL:location toURL:destinationURL error:&error]; - + Launcher* sharedLauncher = [Launcher sharedLauncher]; + + if (error) { + NSLog(@"Download Interface: failed to move file to destination -> error: %@", error); + [sharedLauncher displayErrorPage]; + return; + } [sharedLauncher setDownloadFilename:destinationFileName]; NSString* appPath = [sharedLauncher getAppPath]; NSString* downloadFileName = [sharedLauncher getDownloadFilename]; - + NSLog(@"extract interface zip"); - [sharedLauncher extractZipFileAtDestination:appPath :[appPath stringByAppendingString:downloadFileName]]; + BOOL success = [sharedLauncher extractZipFileAtDestination:appPath :[appPath stringByAppendingString:downloadFileName]]; + if (!success) { + [sharedLauncher displayErrorPage]; + return; + } NSLog(@"finished extracting interface zip"); - + NSLog(@"starting xattr"); NSTask* quaratineTask = [[NSTask alloc] init]; quaratineTask.launchPath = @"/usr/bin/xattr"; quaratineTask.arguments = @[@"-d", @"com.apple.quarantine", [appPath stringByAppendingString:@"interface.app"]]; - + [quaratineTask launch]; [quaratineTask waitUntilExit]; NSLog(@"finished xattr"); - + NSString* launcherPath = [appPath stringByAppendingString:@"Launcher"]; - + [[Settings sharedSettings] setLauncherPath:launcherPath]; [sharedLauncher interfaceFinishedDownloading]; } -(void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error { - NSLog(@"completed; error: %@", error); if (error) { + NSLog(@"DownloadInterface: did complete with error -> error: %@", error); [[Launcher sharedLauncher] displayErrorPage]; } } diff --git a/launchers/darwin/src/ImageView.h b/launchers/darwin/src/ImageView.h new file mode 100644 index 0000000000..2def447099 --- /dev/null +++ b/launchers/darwin/src/ImageView.h @@ -0,0 +1,6 @@ +#import + +@interface ImageView : NSImageView +{ +} +@end diff --git a/launchers/darwin/src/ImageView.m b/launchers/darwin/src/ImageView.m new file mode 100644 index 0000000000..f8b0a4b928 --- /dev/null +++ b/launchers/darwin/src/ImageView.m @@ -0,0 +1,11 @@ +#import "ImageView.h" + +@implementation ImageView + +- (BOOL) mouseDownCanMoveWindow +{ + return TRUE; +} + + +@end diff --git a/launchers/darwin/src/LatestBuildRequest.m b/launchers/darwin/src/LatestBuildRequest.m index 0c136dce3c..767c67eea1 100644 --- a/launchers/darwin/src/LatestBuildRequest.m +++ b/launchers/darwin/src/LatestBuildRequest.m @@ -28,12 +28,12 @@ [request setURL:[NSURL URLWithString:@"https://thunder.highfidelity.com/builds/api/tags/latest?format=json"]]; [request setHTTPMethod:@"GET"]; [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; - + // We're using an ephermeral session here to ensure the tags api response is never cached. NSURLSession * session = [NSURLSession sessionWithConfiguration:NSURLSessionConfiguration.ephemeralSessionConfiguration]; NSURLSessionDataTask* dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { - - + + NSLog(@"Latest Build Request error: %@", error); NSLog(@"Latest Build Request Data: %@", data); NSHTTPURLResponse *ne = (NSHTTPURLResponse *)response; @@ -46,25 +46,25 @@ NSLog(@"Latest Build Request -> json string: %@", jsonString); NSError *jsonError = nil; id json = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&jsonError]; - + if (jsonError) { NSLog(@"Latest Build request: Failed to convert Json to data"); } - + NSFileManager* fileManager = [NSFileManager defaultManager]; NSArray *values = [json valueForKey:@"results"]; NSDictionary *value = [values objectAtIndex:0]; - - + + NSString* buildNumber = [value valueForKey:@"latest_version"]; NSDictionary* installers = [value objectForKey:@"installers"]; NSDictionary* macInstallerObject = [installers objectForKey:@"mac"]; NSString* macInstallerUrl = [macInstallerObject valueForKey:@"zip_url"]; - + 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); @@ -72,66 +72,13 @@ NSLog(@"Latest Build Request -> mac url: %@", macInstallerUrl); BOOL latestVersionAvailable = (currentVersion != buildNumber.integerValue); [[Settings sharedSettings] buildVersion:buildNumber.integerValue]; - + BOOL shouldDownloadInterface = (latestVersionAvailable || !appDirectoryExist); NSLog(@"Latest Build Request -> SHOULD DOWNLOAD: %@", shouldDownloadInterface ? @"TRUE" : @"FALSE"); [sharedLauncher shouldDownloadLatestBuild:shouldDownloadInterface :macInstallerUrl]; }); }]; - + [dataTask resume]; - - //NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; - - /*if(theConnection) { - self.webData = [NSMutableData data]; - NSLog(@"connection initiated"); - }*/ } - -- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { - [self.webData appendData:data]; -} - -- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { - NSHTTPURLResponse *ne = (NSHTTPURLResponse *)response; - if([ne statusCode] == 200) { - NSLog(@"connection state is 200 - all okay"); - } else { - NSLog(@"connection state is NOT 200"); - [[Launcher sharedLauncher] displayErrorPage]; - } -} - --(void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { - NSLog(@"Conn Err: %@", [error localizedDescription]); - [[Launcher sharedLauncher] displayErrorPage]; -} - -- (void)connectionDidFinishLoading:(NSURLConnection *)connection { - Launcher* sharedLauncher = [Launcher sharedLauncher]; - self.jsonString = [[NSString alloc] initWithBytes: [self.webData mutableBytes] length:[self.webData length] encoding:NSUTF8StringEncoding]; - NSData *data = [self.jsonString dataUsingEncoding:NSUTF8StringEncoding]; - id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; - - NSFileManager* fileManager = [NSFileManager defaultManager]; - NSArray *values = [json valueForKey:@"results"]; - NSDictionary *value = [values objectAtIndex:0]; - - - NSString* buildNumber = [value valueForKey:@"latest_version"]; - NSDictionary* installers = [value objectForKey:@"installers"]; - NSDictionary* macInstallerObject = [installers objectForKey:@"mac"]; - NSString* macInstallerUrl = [macInstallerObject valueForKey:@"zip_url"]; - - NSString* interfaceAppPath = [[sharedLauncher getAppPath] stringByAppendingString:@"interface.app"]; - BOOL appDirectoryExist = [fileManager fileExistsAtPath:interfaceAppPath]; - - BOOL latestVersionAvailable = ([self getCurrentVersion] != buildNumber.integerValue); - [[Settings sharedSettings] buildVersion:buildNumber.integerValue]; - - BOOL shouldDownloadInterface = (latestVersionAvailable || !appDirectoryExist); - [sharedLauncher shouldDownloadLatestBuild:shouldDownloadInterface :macInstallerUrl]; -} - @end diff --git a/launchers/darwin/src/Launcher.h b/launchers/darwin/src/Launcher.h index 69484a378d..9eb1cbf3b5 100644 --- a/launchers/darwin/src/Launcher.h +++ b/launchers/darwin/src/Launcher.h @@ -66,7 +66,7 @@ typedef enum LoginErrorTypes - (void) interfaceFinishedDownloading; - (NSString*) getDownloadPathForContentAndScripts; - (void) launchInterface; -- (void) extractZipFileAtDestination:(NSString*) destination :(NSString*) file; +- (BOOL) extractZipFileAtDestination:(NSString*) destination :(NSString*) file; - (BOOL) isWaitingForInterfaceToTerminate; - (void) setDownloadFilename:(NSString*) aFilename; - (void) setDownloadContextFilename:(NSString*) aFilename; diff --git a/launchers/darwin/src/Launcher.m b/launchers/darwin/src/Launcher.m index d60c4080a2..209060d90d 100644 --- a/launchers/darwin/src/Launcher.m +++ b/launchers/darwin/src/Launcher.m @@ -51,11 +51,11 @@ static BOOL const DELETE_ZIP_FILES = TRUE; selector:@selector(didTerminateApp:) name:NSWorkspaceDidTerminateApplicationNotification object:nil]; - + SplashScreen* splashScreen = [[SplashScreen alloc] initWithNibName:@"SplashScreen" bundle:nil]; [self.window setContentViewController: splashScreen]; [self closeInterfaceIfRunning]; - + if (!self.waitingForInterfaceToTerminate) { [self checkLoginStatus]; } @@ -65,12 +65,12 @@ static BOOL const DELETE_ZIP_FILES = TRUE; { 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]; } - + return filePath; } @@ -79,19 +79,26 @@ static BOOL const DELETE_ZIP_FILES = TRUE; return [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/Contents/MacOS/"]; } -- (void) extractZipFileAtDestination:(NSString *)destination :(NSString*)file +- (BOOL) extractZipFileAtDestination:(NSString *)destination :(NSString*)file { NSTask* task = [[NSTask alloc] init]; task.launchPath = @"/usr/bin/unzip"; task.arguments = @[@"-o", @"-d", destination, file]; - + [task launch]; [task waitUntilExit]; - + if (DELETE_ZIP_FILES) { NSFileManager* fileManager = [NSFileManager defaultManager]; [fileManager removeItemAtPath:file error:NULL]; } + + if ([task terminationStatus] != 0) { + NSLog(@"Extracting file failed -> termination status: %d", [task terminationStatus]); + return FALSE; + } + + return TRUE; } - (void) displayErrorPage @@ -175,7 +182,7 @@ static BOOL const DELETE_ZIP_FILES = TRUE; self.domainURL = aDomainURL; self.domainContentUrl = aDomainContentUrl; self.domainScriptsUrl = aDomainScriptsUrl; - + [[Settings sharedSettings] setDomainUrl:aDomainURL]; } @@ -326,14 +333,14 @@ static BOOL const DELETE_ZIP_FILES = TRUE; - (void) launchInterface { NSString* launcherPath = [[self getLauncherPath] stringByAppendingString:@"HQ Launcher"]; - + [[Settings sharedSettings] setLauncherPath:launcherPath]; [[Settings sharedSettings] save]; NSWorkspace *workspace = [NSWorkspace sharedWorkspace]; NSURL *url = [NSURL fileURLWithPath:[workspace fullPathForApplication:[[self getAppPath] stringByAppendingString:@"interface.app/Contents/MacOS/interface"]]]; NSError *error = nil; - + NSString* contentPath = [[self getDownloadPathForContentAndScripts] stringByAppendingString:@"content"]; NSString* displayName = [ self displayName]; NSString* scriptsPath = [[self getAppPath] stringByAppendingString:@"interface.app/Contents/Resources/scripts/simplifiedUI/"]; @@ -361,7 +368,7 @@ static BOOL const DELETE_ZIP_FILES = TRUE; @"--no-launcher", nil]; } [workspace launchApplicationAtURL:url options:NSWorkspaceLaunchNewInstance configuration:[NSDictionary dictionaryWithObject:arguments forKey:NSWorkspaceLaunchConfigurationArguments] error:&error]; - + [NSApp terminate:self]; } diff --git a/launchers/darwin/src/OrganizationRequest.h b/launchers/darwin/src/OrganizationRequest.h index 2f7d2570d6..e10719c332 100644 --- a/launchers/darwin/src/OrganizationRequest.h +++ b/launchers/darwin/src/OrganizationRequest.h @@ -1,6 +1,6 @@ #import -@interface OrganizationRequest : NSObject { +@interface OrganizationRequest : NSObject { } @property (nonatomic, retain) NSMutableData* webData; diff --git a/launchers/darwin/src/OrganizationRequest.m b/launchers/darwin/src/OrganizationRequest.m index abc104785a..1aaed2ce51 100644 --- a/launchers/darwin/src/OrganizationRequest.m +++ b/launchers/darwin/src/OrganizationRequest.m @@ -6,6 +6,11 @@ static NSString* const organizationURL = @"https://orgs.highfidelity.com/organizations/"; +@interface OrganizationRequest () +@property (nonatomic, assign) NSMutableData* receivedData; +@property (nonatomic, assign) NSInteger statusCode; +@end + @implementation OrganizationRequest - (void) confirmOrganization:(NSString*)aOrganization :(NSString*)aUsername { @@ -23,70 +28,72 @@ static NSString* const organizationURL = @"https://orgs.highfidelity.com/organiz } NSString* jsonFile = [hash stringByAppendingString:@".json"]; - NSError *error; - NSData *data = [NSData dataWithContentsOfURL: [NSURL URLWithString:[organizationURL stringByAppendingString:jsonFile]]]; - - Launcher* sharedLauncher = [Launcher sharedLauncher]; - if (data) { - NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]; - [sharedLauncher setDomainURLInfo:[json valueForKey:@"domain"] :[json valueForKey:@"content_set_url"] :[json valueForKey:@"scripts_url"]]; - [sharedLauncher setLoginErrorState: NONE]; - return [sharedLauncher organizationRequestFinished:TRUE]; - } - [sharedLauncher setLoginErrorState: ORGANIZATION]; - return [sharedLauncher organizationRequestFinished:FALSE]; - /*NSLog(@"URL: %@", [organizationURL stringByAppendingString:jsonFile]); + NSMutableURLRequest *request = [NSMutableURLRequest new]; - [request setURL:[NSURL URLWithString: [organizationURL stringByAppendingString:@"High%20Fidelity"]]]; + [request setURL:[NSURL URLWithString:[organizationURL stringByAppendingString:jsonFile]]]; [request setHTTPMethod:@"GET"]; - [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; + [request setValue:@"" forHTTPHeaderField:@"Content-Type"]; - NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; - - if(theConnection) { - self.webData = [NSMutableData data]; - NSLog(@"connection initiated"); - }*/ + NSURLSession * session = [NSURLSession sessionWithConfiguration:NSURLSessionConfiguration.ephemeralSessionConfiguration delegate: self delegateQueue: [NSOperationQueue mainQueue]]; + NSURLSessionDataTask* dataTask = [session dataTaskWithRequest:request]; + [dataTask resume]; } -- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { - [self.webData appendData:data]; -} -- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { +- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSURLResponse *)response + completionHandler:(void (^)(NSURLSessionResponseDisposition disposition))completionHandler { + self.receivedData = nil; + self.receivedData = [[NSMutableData alloc] init]; + [self.receivedData setLength:0]; NSHTTPURLResponse *ne = (NSHTTPURLResponse *)response; - if([ne statusCode] == 200) { - NSLog(@"connection state is 200 - all okay"); + self.statusCode = [ne statusCode]; + NSLog(@"Organization Response status code: %ld", self.statusCode); + completionHandler(NSURLSessionResponseAllow); +} + + +-(void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask + didReceiveData:(NSData *)data { + + [self.receivedData appendData:data]; + NSLog(@"Organization: did recieve data"); +} + +- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error { + Launcher* sharedLauncher = [Launcher sharedLauncher]; + if (error) { + NSLog(@"Organization: Request completed with an error -> error: %@", error); + [sharedLauncher displayErrorPage]; } else { - NSLog(@"connection state is NOT 200"); + if (self.statusCode == 200) { + NSError *jsonError = nil; + NSDictionary *json = [NSJSONSerialization JSONObjectWithData:self.receivedData options:kNilOptions error:&jsonError]; + if (jsonError) { + NSLog(@"Failed to parse Organzation json -> error: %@", jsonError); + [sharedLauncher displayErrorPage]; + return; + } + NSString* domainURL = [json valueForKey:@"domain"]; + NSString* contentSetURL = [json valueForKey:@"content_set_url"]; + + if (domainURL != nil && contentSetURL != nil) { + NSLog(@"Organization: getting org file successful"); + [sharedLauncher setDomainURLInfo:[json valueForKey:@"domain"] :[json valueForKey:@"content_set_url"] :nil]; + [sharedLauncher setLoginErrorState: NONE]; + [sharedLauncher organizationRequestFinished:TRUE]; + } else { + NSLog(@"Organization: Either domainURL: %@ or contentSetURL: %@ json entries are invalid", domainURL, contentSetURL); + [sharedLauncher displayErrorPage]; + } + } else if (self.statusCode == 403 || self.statusCode == 404) { + NSLog(@"Organization: failed to get org file"); + [sharedLauncher setLoginErrorState: ORGANIZATION]; + [sharedLauncher organizationRequestFinished:FALSE]; + } else { + NSLog(@ "Organization: Response error -> statusCode: %ld", self.statusCode); + [sharedLauncher displayErrorPage]; + } } } --(void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { - NSLog(@"Conn Err: %@", [error localizedDescription]); -} - -- (void)connectionDidFinishLoading:(NSURLConnection *)connection { - /*NSString* jsonString = [[NSString alloc] initWithBytes: [self.webData mutableBytes] length:[self.webData length] encoding:NSUTF8StringEncoding]; - NSData *data = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; - id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];*/ - - /*Launcher* sharedLauncher = [Launcher sharedLauncher]; - if (json[@"error"] != nil) { - NSLog(@"Login in failed"); - NSString* accessToken = [json objectForKey:@"access_token"]; - NSLog(@"access token %@", accessToken); - [sharedLauncher credentialsAccepted:FALSE]; - } else { - NSLog(@"Login successful"); - NSString* accessToken = [json objectForKey:@"access_token"]; - NSLog(@"access token %@", accessToken); - NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - [defaults setValue:accessToken forKey:@"access_token"]; - [defaults synchronize]; - [sharedLauncher credentialsAccepted:TRUE]; - }*/ - //NSLog(@"OUTPUT:: %@", self.jsonString); -} - @end diff --git a/launchers/darwin/src/Window.h b/launchers/darwin/src/Window.h index 05e1a7e09e..ace35baab6 100644 --- a/launchers/darwin/src/Window.h +++ b/launchers/darwin/src/Window.h @@ -1,6 +1,6 @@ #import @interface Window : NSWindow { - + } @end diff --git a/launchers/darwin/src/Window.m b/launchers/darwin/src/Window.m index fc54e095e7..a17b2533fd 100644 --- a/launchers/darwin/src/Window.m +++ b/launchers/darwin/src/Window.m @@ -4,4 +4,10 @@ -(BOOL)canBecomeKeyWindow { return YES; } + +-(BOOL)isMovableByWindowBackground +{ + return TRUE; +} + @end