Merge pull request #15854 from danteruiz/issues-launchers

BUGZ-692: Laucner is not movable & BUGZ-831 handle org and credentials erros.
This commit is contained in:
Dante Ruiz 2019-07-01 11:07:07 -07:00 committed by GitHub
commit ec4bd95950
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 238 additions and 237 deletions

View file

@ -27,6 +27,8 @@ set(src_files
src/LatestBuildRequest.m src/LatestBuildRequest.m
src/OrganizationRequest.m src/OrganizationRequest.m
src/OrganizationRequest.h src/OrganizationRequest.h
src/ImageView.m
src/ImageView.h
src/Interface.h src/Interface.h
src/Interface.m src/Interface.m
src/ErrorViewController.h src/ErrorViewController.h

View file

@ -16,13 +16,13 @@
<rect key="frame" x="0.0" y="0.0" width="515" height="390"/> <rect key="frame" x="0.0" y="0.0" width="515" height="390"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews> <subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="aus-lo-eVi"> <imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="aus-lo-eVi" customClass="ImageView">
<rect key="frame" x="0.0" y="0.0" width="515" height="390"/> <rect key="frame" x="0.0" y="0.0" width="515" height="390"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="MYh-TA-w2A"/> <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="MYh-TA-w2A"/>
</imageView> </imageView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="iAf-Ee-jJL"> <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="iAf-Ee-jJL">
<rect key="frame" x="95" y="344" width="325" height="33"/> <rect key="frame" x="95" y="336" width="325" height="41"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<textFieldCell key="cell" lineBreakMode="clipping" alignment="center" title="Choose a display name" id="GzZ-0d-2JH"> <textFieldCell key="cell" lineBreakMode="clipping" alignment="center" title="Choose a display name" id="GzZ-0d-2JH">
<font key="font" metaFont="systemBold" size="28"/> <font key="font" metaFont="systemBold" size="28"/>
@ -70,12 +70,12 @@
</connections> </connections>
</textField> </textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="0CN-kS-xZ5"> <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="0CN-kS-xZ5">
<rect key="frame" x="66" y="68" width="266" height="17"/> <rect key="frame" x="66" y="68" width="271" height="17"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<textFieldCell key="cell" lineBreakMode="clipping" alignment="center" title="By signing in, you agree to the High Fidelity" id="zSf-YA-osu"> <textFieldCell key="cell" lineBreakMode="clipping" alignment="center" title="By signing in, you agree to the High Fidelity" id="zSf-YA-osu">
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="alternateSelectedControlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/> <color key="backgroundColor" name="alternateSelectedControlTextColor" catalog="System" colorSpace="catalog"/>
</textFieldCell> </textFieldCell>
</textField> </textField>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="xeX-qc-ccB" customClass="HFButton"> <button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="xeX-qc-ccB" customClass="HFButton">

View file

@ -16,7 +16,7 @@
<rect key="frame" x="0.0" y="0.0" width="515" height="390"/> <rect key="frame" x="0.0" y="0.0" width="515" height="390"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews> <subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="eih-a8-Pqa"> <imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="eih-a8-Pqa" customClass="ImageView">
<rect key="frame" x="0.0" y="0.0" width="515" height="390"/> <rect key="frame" x="0.0" y="0.0" width="515" height="390"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="SuI-2T-YhQ"/> <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="SuI-2T-YhQ"/>
@ -36,21 +36,21 @@
</textFieldCell> </textFieldCell>
</textField> </textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="FkC-xi-3UI"> <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="FkC-xi-3UI">
<rect key="frame" x="156" y="105" width="192" height="17"/> <rect key="frame" x="156" y="103" width="202" height="19"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<textFieldCell key="cell" lineBreakMode="clipping" alignment="center" title="We seem to have a problem." id="bX3-v1-LLM"> <textFieldCell key="cell" lineBreakMode="clipping" alignment="center" title="We seem to have a problem." id="bX3-v1-LLM">
<font key="font" metaFont="system" size="15"/> <font key="font" metaFont="system" size="15"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="alternateSelectedControlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/> <color key="backgroundColor" name="alternateSelectedControlTextColor" catalog="System" colorSpace="catalog"/>
</textFieldCell> </textFieldCell>
</textField> </textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="tV0-Su-eLX"> <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="tV0-Su-eLX">
<rect key="frame" x="156" y="80" width="192" height="17"/> <rect key="frame" x="156" y="78" width="192" height="19"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<textFieldCell key="cell" lineBreakMode="clipping" alignment="center" title="Please restart Launcher" id="aBw-o2-xZE"> <textFieldCell key="cell" lineBreakMode="clipping" alignment="center" title="Please restart Launcher" id="aBw-o2-xZE">
<font key="font" metaFont="system" size="15"/> <font key="font" metaFont="system" size="15"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="alternateSelectedControlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/> <color key="backgroundColor" name="alternateSelectedControlTextColor" catalog="System" colorSpace="catalog"/>
</textFieldCell> </textFieldCell>
</textField> </textField>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Sds-MZ-qhT" customClass="HFButton"> <button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Sds-MZ-qhT" customClass="HFButton">

View file

@ -16,7 +16,7 @@
<rect key="frame" x="0.0" y="0.0" width="515" height="390"/> <rect key="frame" x="0.0" y="0.0" width="515" height="390"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews> <subviews>
<imageView focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="L56-Jv-0N8"> <imageView focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="L56-Jv-0N8" customClass="ImageView" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="515" height="390"/> <rect key="frame" x="0.0" y="0.0" width="515" height="390"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<imageCell key="cell" refusesFirstResponder="YES" focusRingType="none" alignment="left" imageScaling="proportionallyDown" id="ONf-d4-EDr"/> <imageCell key="cell" refusesFirstResponder="YES" focusRingType="none" alignment="left" imageScaling="proportionallyDown" id="ONf-d4-EDr"/>
@ -94,7 +94,7 @@
</connections> </connections>
</button> </button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="hIC-qf-Abj"> <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="hIC-qf-Abj">
<rect key="frame" x="63" y="337" width="384" height="33"/> <rect key="frame" x="63" y="330" width="384" height="40"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<textFieldCell key="cell" lineBreakMode="clipping" alignment="center" title="Please log in" id="YuE-2K-HLT"> <textFieldCell key="cell" lineBreakMode="clipping" alignment="center" title="Please log in" id="YuE-2K-HLT">
<font key="font" metaFont="systemBold" size="28"/> <font key="font" metaFont="systemBold" size="28"/>

View file

@ -16,7 +16,7 @@
<rect key="frame" x="0.0" y="0.0" width="515" height="390"/> <rect key="frame" x="0.0" y="0.0" width="515" height="390"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews> <subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="kuY-e2-Hqb"> <imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="kuY-e2-Hqb" customClass="ImageView">
<rect key="frame" x="0.0" y="0.0" width="515" height="390"/> <rect key="frame" x="0.0" y="0.0" width="515" height="390"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="Abr-HV-cKq"/> <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="Abr-HV-cKq"/>

View file

@ -16,7 +16,7 @@
<rect key="frame" x="0.0" y="0.0" width="515" height="390"/> <rect key="frame" x="0.0" y="0.0" width="515" height="390"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews> <subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="qtD-mb-qqq"> <imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="qtD-mb-qqq" customClass="ImageView">
<rect key="frame" x="0.0" y="0.0" width="515" height="390"/> <rect key="frame" x="0.0" y="0.0" width="515" height="390"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="ixM-5m-vi6"/> <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="ixM-5m-vi6"/>

View file

@ -1,10 +1,7 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
@interface CredentialsRequest : NSObject <NSURLConnectionDelegate> { @interface CredentialsRequest : NSObject <NSURLSessionDelegate, NSURLSessionTaskDelegate> {
} }
@property (nonatomic, retain) NSMutableData* webData;
@property (nonatomic, retain) NSString* jsonString;
- (void) confirmCredentials:(NSString*)username :(NSString*)password; - (void) confirmCredentials:(NSString*)username :(NSString*)password;
@end @end

View file

@ -2,6 +2,11 @@
#import "Launcher.h" #import "Launcher.h"
#import "Settings.h" #import "Settings.h"
@interface CredentialsRequest ()
@property (nonatomic, assign) NSMutableData* receivedData;
@property (nonatomic, assign) NSInteger statusCode;
@end
@implementation CredentialsRequest @implementation CredentialsRequest
- (void) confirmCredentials:(NSString*)username :(NSString*)password { - (void) confirmCredentials:(NSString*)username :(NSString*)password {
@ -21,77 +26,70 @@
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData]; [request setHTTPBody:postData];
NSURLSession* session = [NSURLSession sharedSession]; NSURLSession* session = [NSURLSession sessionWithConfiguration:NSURLSessionConfiguration.ephemeralSessionConfiguration delegate: self delegateQueue: [NSOperationQueue mainQueue]];
NSURLSessionDataTask* dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { NSURLSessionDataTask* dataTask = [session dataTaskWithRequest:request];
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");
}];
[dataTask resume]; [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 { - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSURLResponse *)response
NSLog(@"credentials connection received response"); completionHandler:(void (^)(NSURLSessionResponseDisposition disposition))completionHandler {
self.receivedData = nil;
self.receivedData = [[NSMutableData alloc] init];
[self.receivedData setLength:0];
NSHTTPURLResponse *ne = (NSHTTPURLResponse *)response; NSHTTPURLResponse *ne = (NSHTTPURLResponse *)response;
if([ne statusCode] == 200) { self.statusCode = [ne statusCode];
NSLog(@"connection state is 200 - all okay"); NSLog(@"Credentials Response status code: %ld", self.statusCode);
} else { completionHandler(NSURLSessionResponseAllow);
NSLog(@"connection state is NOT 200");
[[Launcher sharedLauncher] displayErrorPage];
}
} }
-(void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"Conn Err: %@", [error localizedDescription]); -(void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask
[[Launcher sharedLauncher] displayErrorPage]; didReceiveData:(NSData *)data {
[self.receivedData appendData:data];
NSLog(@"Credentials: did recieve data");
} }
- (void)connectionDidFinishLoading:(NSURLConnection *)connection { - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
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];
Launcher* sharedLauncher = [Launcher sharedLauncher]; Launcher* sharedLauncher = [Launcher sharedLauncher];
if (json[@"error"] != nil) { if (error) {
[[Settings sharedSettings] login:FALSE]; NSLog(@"Credentials: Request completed with an error -> error: %@", error);
[sharedLauncher setLoginErrorState: CREDENTIALS]; [sharedLauncher displayErrorPage];
[sharedLauncher credentialsAccepted:FALSE];
} else { } else {
[[Settings sharedSettings] login:TRUE]; if (self.statusCode == 200) {
[sharedLauncher setTokenString:jsonString]; NSString* jsonString = [[NSString alloc] initWithBytes: [self.receivedData mutableBytes] length:[self.receivedData length] encoding:NSUTF8StringEncoding];
[sharedLauncher credentialsAccepted:TRUE]; NSData* jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
} NSError* jsonError = nil;
id json = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&jsonError];
NSLog(@"credentials: connectionDidFinished completed");
}
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 @end

View file

@ -8,7 +8,7 @@
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:domainContentUrl] NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:domainContentUrl]
cachePolicy:NSURLRequestUseProtocolCachePolicy cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0]; timeoutInterval:60.0];
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: self delegateQueue: [NSOperationQueue mainQueue]]; NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: self delegateQueue: [NSOperationQueue mainQueue]];
NSURLSessionDownloadTask *downloadTask = [defaultSession downloadTaskWithRequest:request]; 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 { -(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite {
CGFloat prog = (float)totalBytesWritten/totalBytesExpectedToWrite; CGFloat prog = (float)totalBytesWritten/totalBytesExpectedToWrite;
NSLog(@"domain content downloaded %d%%", (int)(100.0*prog)); NSLog(@"domain content downloaded %d%%", (int)(100.0*prog));
} }
-(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didResumeAtOffset:(int64_t)fileOffset expectedTotalBytes:(int64_t)expectedTotalBytes { -(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 { -(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location {
NSLog(@"Did finish downloading to url"); NSLog(@"Did finish downloading to url");
NSError *error; NSError *error = nil;
NSFileManager *fileManager = [NSFileManager defaultManager]; NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *destinationFileName = downloadTask.originalRequest.URL.lastPathComponent; NSString *destinationFileName = downloadTask.originalRequest.URL.lastPathComponent;
NSString* finalFilePath = [[[Launcher sharedLauncher] getDownloadPathForContentAndScripts] stringByAppendingPathComponent:destinationFileName]; NSString* finalFilePath = [[[Launcher sharedLauncher] getDownloadPathForContentAndScripts] stringByAppendingPathComponent:destinationFileName];
@ -36,18 +36,28 @@
{ {
[fileManager removeItemAtURL:destinationURL error:nil]; [fileManager removeItemAtURL:destinationURL error:nil];
} }
NSLog(@"%@", location.path); NSLog(@"location: %@", location.path);
NSLog(@"%@", destinationURL); NSLog(@"destination: %@", destinationURL);
BOOL success = [fileManager moveItemAtURL:location toURL:destinationURL error:&error]; BOOL success = [fileManager moveItemAtURL:location toURL:destinationURL error:&error];
NSLog(success ? @"TRUE" : @"FALSE"); NSLog(success ? @"TRUE" : @"FALSE");
Launcher* sharedLauncher = [Launcher sharedLauncher]; Launcher* sharedLauncher = [Launcher sharedLauncher];
if (error) {
NSLog(@"DownlodDomainContent: failed to move file to destintation -> error: %@", error);
[sharedLauncher displayErrorPage];
return;
}
[sharedLauncher setDownloadContextFilename:destinationFileName]; [sharedLauncher setDownloadContextFilename:destinationFileName];
NSLog(@"extracting domain content file"); 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"); NSLog(@"finished extracting content file");
[sharedLauncher domainContentDownloadFinished]; [sharedLauncher domainContentDownloadFinished];
} }

View file

@ -9,18 +9,18 @@
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:downloadUrl] NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:downloadUrl]
cachePolicy:NSURLRequestUseProtocolCachePolicy cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0]; timeoutInterval:60.0];
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: self delegateQueue: [NSOperationQueue mainQueue]]; NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: self delegateQueue: [NSOperationQueue mainQueue]];
NSURLSessionDownloadTask *downloadTask = [defaultSession downloadTaskWithRequest:request]; NSURLSessionDownloadTask *downloadTask = [defaultSession downloadTaskWithRequest:request];
[downloadTask resume]; [downloadTask resume];
} }
-(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite { -(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite {
CGFloat prog = (float)totalBytesWritten/totalBytesExpectedToWrite; CGFloat prog = (float)totalBytesWritten/totalBytesExpectedToWrite;
NSLog(@"interface downloaded %d%%", (int)(100.0*prog)); NSLog(@"interface downloaded %d%%", (int)(100.0*prog));
} }
-(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didResumeAtOffset:(int64_t)fileOffset expectedTotalBytes:(int64_t)expectedTotalBytes { -(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 { -(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location {
NSLog(@"Did finish downloading to url"); NSLog(@"Did finish downloading to url");
NSError *error; NSError *error = nil;
NSFileManager *fileManager = [NSFileManager defaultManager]; NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *destinationFileName = downloadTask.originalRequest.URL.lastPathComponent; NSString *destinationFileName = downloadTask.originalRequest.URL.lastPathComponent;
NSString* finalFilePath = [[[Launcher sharedLauncher] getAppPath] stringByAppendingPathComponent:destinationFileName]; NSString* finalFilePath = [[[Launcher sharedLauncher] getAppPath] stringByAppendingPathComponent:destinationFileName];
@ -39,34 +39,44 @@
[fileManager removeItemAtURL:destinationURL error:nil]; [fileManager removeItemAtURL:destinationURL error:nil];
} }
[fileManager moveItemAtURL:location toURL:destinationURL error:&error]; [fileManager moveItemAtURL:location toURL:destinationURL error:&error];
Launcher* sharedLauncher = [Launcher sharedLauncher]; Launcher* sharedLauncher = [Launcher sharedLauncher];
if (error) {
NSLog(@"Download Interface: failed to move file to destination -> error: %@", error);
[sharedLauncher displayErrorPage];
return;
}
[sharedLauncher setDownloadFilename:destinationFileName]; [sharedLauncher setDownloadFilename:destinationFileName];
NSString* appPath = [sharedLauncher getAppPath]; NSString* appPath = [sharedLauncher getAppPath];
NSString* downloadFileName = [sharedLauncher getDownloadFilename]; NSString* downloadFileName = [sharedLauncher getDownloadFilename];
NSLog(@"extract interface zip"); 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(@"finished extracting interface zip");
NSLog(@"starting xattr"); NSLog(@"starting xattr");
NSTask* quaratineTask = [[NSTask alloc] init]; NSTask* quaratineTask = [[NSTask alloc] init];
quaratineTask.launchPath = @"/usr/bin/xattr"; quaratineTask.launchPath = @"/usr/bin/xattr";
quaratineTask.arguments = @[@"-d", @"com.apple.quarantine", [appPath stringByAppendingString:@"interface.app"]]; quaratineTask.arguments = @[@"-d", @"com.apple.quarantine", [appPath stringByAppendingString:@"interface.app"]];
[quaratineTask launch]; [quaratineTask launch];
[quaratineTask waitUntilExit]; [quaratineTask waitUntilExit];
NSLog(@"finished xattr"); NSLog(@"finished xattr");
NSString* launcherPath = [appPath stringByAppendingString:@"Launcher"]; NSString* launcherPath = [appPath stringByAppendingString:@"Launcher"];
[[Settings sharedSettings] setLauncherPath:launcherPath]; [[Settings sharedSettings] setLauncherPath:launcherPath];
[sharedLauncher interfaceFinishedDownloading]; [sharedLauncher interfaceFinishedDownloading];
} }
-(void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error { -(void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
NSLog(@"completed; error: %@", error);
if (error) { if (error) {
NSLog(@"DownloadInterface: did complete with error -> error: %@", error);
[[Launcher sharedLauncher] displayErrorPage]; [[Launcher sharedLauncher] displayErrorPage];
} }
} }

View file

@ -0,0 +1,6 @@
#import <Cocoa/Cocoa.h>
@interface ImageView : NSImageView
{
}
@end

View file

@ -0,0 +1,11 @@
#import "ImageView.h"
@implementation ImageView
- (BOOL) mouseDownCanMoveWindow
{
return TRUE;
}
@end

View file

@ -28,12 +28,12 @@
[request setURL:[NSURL URLWithString:@"https://thunder.highfidelity.com/builds/api/tags/latest?format=json"]]; [request setURL:[NSURL URLWithString:@"https://thunder.highfidelity.com/builds/api/tags/latest?format=json"]];
[request setHTTPMethod:@"GET"]; [request setHTTPMethod:@"GET"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
// We're using an ephermeral session here to ensure the tags api response is never cached. // We're using an ephermeral session here to ensure the tags api response is never cached.
NSURLSession * session = [NSURLSession sessionWithConfiguration:NSURLSessionConfiguration.ephemeralSessionConfiguration]; NSURLSession * session = [NSURLSession sessionWithConfiguration:NSURLSessionConfiguration.ephemeralSessionConfiguration];
NSURLSessionDataTask* dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { NSURLSessionDataTask* dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSLog(@"Latest Build Request error: %@", error); NSLog(@"Latest Build Request error: %@", error);
NSLog(@"Latest Build Request Data: %@", data); NSLog(@"Latest Build Request Data: %@", data);
NSHTTPURLResponse *ne = (NSHTTPURLResponse *)response; NSHTTPURLResponse *ne = (NSHTTPURLResponse *)response;
@ -46,25 +46,25 @@
NSLog(@"Latest Build Request -> json string: %@", jsonString); NSLog(@"Latest Build Request -> json string: %@", jsonString);
NSError *jsonError = nil; NSError *jsonError = nil;
id json = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&jsonError]; id json = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&jsonError];
if (jsonError) { if (jsonError) {
NSLog(@"Latest Build request: Failed to convert Json to data"); NSLog(@"Latest Build request: Failed to convert Json to data");
} }
NSFileManager* fileManager = [NSFileManager defaultManager]; NSFileManager* fileManager = [NSFileManager defaultManager];
NSArray *values = [json valueForKey:@"results"]; NSArray *values = [json valueForKey:@"results"];
NSDictionary *value = [values objectAtIndex:0]; NSDictionary *value = [values objectAtIndex:0];
NSString* buildNumber = [value valueForKey:@"latest_version"]; NSString* buildNumber = [value valueForKey:@"latest_version"];
NSDictionary* installers = [value objectForKey:@"installers"]; NSDictionary* installers = [value objectForKey:@"installers"];
NSDictionary* macInstallerObject = [installers objectForKey:@"mac"]; NSDictionary* macInstallerObject = [installers objectForKey:@"mac"];
NSString* macInstallerUrl = [macInstallerObject valueForKey:@"zip_url"]; NSString* macInstallerUrl = [macInstallerObject valueForKey:@"zip_url"];
BOOL appDirectoryExist = [fileManager fileExistsAtPath:[[sharedLauncher getAppPath] stringByAppendingString:@"interface.app"]]; BOOL appDirectoryExist = [fileManager fileExistsAtPath:[[sharedLauncher getAppPath] stringByAppendingString:@"interface.app"]];
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
NSInteger currentVersion = [self getCurrentVersion]; NSInteger currentVersion = [self getCurrentVersion];
NSLog(@"Latest Build Request -> does build directory exist: %@", appDirectoryExist ? @"TRUE" : @"FALSE"); NSLog(@"Latest Build Request -> does build directory exist: %@", appDirectoryExist ? @"TRUE" : @"FALSE");
NSLog(@"Latest Build Request -> current version: %ld", currentVersion); NSLog(@"Latest Build Request -> current version: %ld", currentVersion);
@ -72,66 +72,13 @@
NSLog(@"Latest Build Request -> mac url: %@", macInstallerUrl); NSLog(@"Latest Build Request -> mac url: %@", macInstallerUrl);
BOOL latestVersionAvailable = (currentVersion != buildNumber.integerValue); BOOL latestVersionAvailable = (currentVersion != buildNumber.integerValue);
[[Settings sharedSettings] buildVersion:buildNumber.integerValue]; [[Settings sharedSettings] buildVersion:buildNumber.integerValue];
BOOL shouldDownloadInterface = (latestVersionAvailable || !appDirectoryExist); BOOL shouldDownloadInterface = (latestVersionAvailable || !appDirectoryExist);
NSLog(@"Latest Build Request -> SHOULD DOWNLOAD: %@", shouldDownloadInterface ? @"TRUE" : @"FALSE"); NSLog(@"Latest Build Request -> SHOULD DOWNLOAD: %@", shouldDownloadInterface ? @"TRUE" : @"FALSE");
[sharedLauncher shouldDownloadLatestBuild:shouldDownloadInterface :macInstallerUrl]; [sharedLauncher shouldDownloadLatestBuild:shouldDownloadInterface :macInstallerUrl];
}); });
}]; }];
[dataTask resume]; [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 @end

View file

@ -66,7 +66,7 @@ typedef enum LoginErrorTypes
- (void) interfaceFinishedDownloading; - (void) interfaceFinishedDownloading;
- (NSString*) getDownloadPathForContentAndScripts; - (NSString*) getDownloadPathForContentAndScripts;
- (void) launchInterface; - (void) launchInterface;
- (void) extractZipFileAtDestination:(NSString*) destination :(NSString*) file; - (BOOL) extractZipFileAtDestination:(NSString*) destination :(NSString*) file;
- (BOOL) isWaitingForInterfaceToTerminate; - (BOOL) isWaitingForInterfaceToTerminate;
- (void) setDownloadFilename:(NSString*) aFilename; - (void) setDownloadFilename:(NSString*) aFilename;
- (void) setDownloadContextFilename:(NSString*) aFilename; - (void) setDownloadContextFilename:(NSString*) aFilename;

View file

@ -51,11 +51,11 @@ static BOOL const DELETE_ZIP_FILES = TRUE;
selector:@selector(didTerminateApp:) selector:@selector(didTerminateApp:)
name:NSWorkspaceDidTerminateApplicationNotification name:NSWorkspaceDidTerminateApplicationNotification
object:nil]; object:nil];
SplashScreen* splashScreen = [[SplashScreen alloc] initWithNibName:@"SplashScreen" bundle:nil]; SplashScreen* splashScreen = [[SplashScreen alloc] initWithNibName:@"SplashScreen" bundle:nil];
[self.window setContentViewController: splashScreen]; [self.window setContentViewController: splashScreen];
[self closeInterfaceIfRunning]; [self closeInterfaceIfRunning];
if (!self.waitingForInterfaceToTerminate) { if (!self.waitingForInterfaceToTerminate) {
[self checkLoginStatus]; [self checkLoginStatus];
} }
@ -65,12 +65,12 @@ static BOOL const DELETE_ZIP_FILES = TRUE;
{ {
NSString* filePath = [[NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) objectAtIndex:0] NSString* filePath = [[NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) objectAtIndex:0]
stringByAppendingString:@"/Launcher/"]; stringByAppendingString:@"/Launcher/"];
if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) { if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
NSError * error = nil; NSError * error = nil;
[[NSFileManager defaultManager] createDirectoryAtPath:filePath withIntermediateDirectories:TRUE attributes:nil error:&error]; [[NSFileManager defaultManager] createDirectoryAtPath:filePath withIntermediateDirectories:TRUE attributes:nil error:&error];
} }
return filePath; return filePath;
} }
@ -79,19 +79,26 @@ static BOOL const DELETE_ZIP_FILES = TRUE;
return [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/Contents/MacOS/"]; return [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/Contents/MacOS/"];
} }
- (void) extractZipFileAtDestination:(NSString *)destination :(NSString*)file - (BOOL) extractZipFileAtDestination:(NSString *)destination :(NSString*)file
{ {
NSTask* task = [[NSTask alloc] init]; NSTask* task = [[NSTask alloc] init];
task.launchPath = @"/usr/bin/unzip"; task.launchPath = @"/usr/bin/unzip";
task.arguments = @[@"-o", @"-d", destination, file]; task.arguments = @[@"-o", @"-d", destination, file];
[task launch]; [task launch];
[task waitUntilExit]; [task waitUntilExit];
if (DELETE_ZIP_FILES) { if (DELETE_ZIP_FILES) {
NSFileManager* fileManager = [NSFileManager defaultManager]; NSFileManager* fileManager = [NSFileManager defaultManager];
[fileManager removeItemAtPath:file error:NULL]; [fileManager removeItemAtPath:file error:NULL];
} }
if ([task terminationStatus] != 0) {
NSLog(@"Extracting file failed -> termination status: %d", [task terminationStatus]);
return FALSE;
}
return TRUE;
} }
- (void) displayErrorPage - (void) displayErrorPage
@ -175,7 +182,7 @@ static BOOL const DELETE_ZIP_FILES = TRUE;
self.domainURL = aDomainURL; self.domainURL = aDomainURL;
self.domainContentUrl = aDomainContentUrl; self.domainContentUrl = aDomainContentUrl;
self.domainScriptsUrl = aDomainScriptsUrl; self.domainScriptsUrl = aDomainScriptsUrl;
[[Settings sharedSettings] setDomainUrl:aDomainURL]; [[Settings sharedSettings] setDomainUrl:aDomainURL];
} }
@ -326,14 +333,14 @@ static BOOL const DELETE_ZIP_FILES = TRUE;
- (void) launchInterface - (void) launchInterface
{ {
NSString* launcherPath = [[self getLauncherPath] stringByAppendingString:@"HQ Launcher"]; NSString* launcherPath = [[self getLauncherPath] stringByAppendingString:@"HQ Launcher"];
[[Settings sharedSettings] setLauncherPath:launcherPath]; [[Settings sharedSettings] setLauncherPath:launcherPath];
[[Settings sharedSettings] save]; [[Settings sharedSettings] save];
NSWorkspace *workspace = [NSWorkspace sharedWorkspace]; NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
NSURL *url = [NSURL fileURLWithPath:[workspace fullPathForApplication:[[self getAppPath] stringByAppendingString:@"interface.app/Contents/MacOS/interface"]]]; NSURL *url = [NSURL fileURLWithPath:[workspace fullPathForApplication:[[self getAppPath] stringByAppendingString:@"interface.app/Contents/MacOS/interface"]]];
NSError *error = nil; NSError *error = nil;
NSString* contentPath = [[self getDownloadPathForContentAndScripts] stringByAppendingString:@"content"]; NSString* contentPath = [[self getDownloadPathForContentAndScripts] stringByAppendingString:@"content"];
NSString* displayName = [ self displayName]; NSString* displayName = [ self displayName];
NSString* scriptsPath = [[self getAppPath] stringByAppendingString:@"interface.app/Contents/Resources/scripts/simplifiedUI/"]; 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]; @"--no-launcher", nil];
} }
[workspace launchApplicationAtURL:url options:NSWorkspaceLaunchNewInstance configuration:[NSDictionary dictionaryWithObject:arguments forKey:NSWorkspaceLaunchConfigurationArguments] error:&error]; [workspace launchApplicationAtURL:url options:NSWorkspaceLaunchNewInstance configuration:[NSDictionary dictionaryWithObject:arguments forKey:NSWorkspaceLaunchConfigurationArguments] error:&error];
[NSApp terminate:self]; [NSApp terminate:self];
} }

View file

@ -1,6 +1,6 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
@interface OrganizationRequest : NSObject <NSURLConnectionDelegate> { @interface OrganizationRequest : NSObject <NSURLSessionDelegate, NSURLSessionTaskDelegate> {
} }
@property (nonatomic, retain) NSMutableData* webData; @property (nonatomic, retain) NSMutableData* webData;

View file

@ -6,6 +6,11 @@
static NSString* const organizationURL = @"https://orgs.highfidelity.com/organizations/"; static NSString* const organizationURL = @"https://orgs.highfidelity.com/organizations/";
@interface OrganizationRequest ()
@property (nonatomic, assign) NSMutableData* receivedData;
@property (nonatomic, assign) NSInteger statusCode;
@end
@implementation OrganizationRequest @implementation OrganizationRequest
- (void) confirmOrganization:(NSString*)aOrganization :(NSString*)aUsername { - (void) confirmOrganization:(NSString*)aOrganization :(NSString*)aUsername {
@ -23,70 +28,72 @@ static NSString* const organizationURL = @"https://orgs.highfidelity.com/organiz
} }
NSString* jsonFile = [hash stringByAppendingString:@".json"]; 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]; NSMutableURLRequest *request = [NSMutableURLRequest new];
[request setURL:[NSURL URLWithString: [organizationURL stringByAppendingString:@"High%20Fidelity"]]]; [request setURL:[NSURL URLWithString:[organizationURL stringByAppendingString:jsonFile]]];
[request setHTTPMethod:@"GET"]; [request setHTTPMethod:@"GET"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [request setValue:@"" forHTTPHeaderField:@"Content-Type"];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; NSURLSession * session = [NSURLSession sessionWithConfiguration:NSURLSessionConfiguration.ephemeralSessionConfiguration delegate: self delegateQueue: [NSOperationQueue mainQueue]];
NSURLSessionDataTask* dataTask = [session dataTaskWithRequest:request];
if(theConnection) { [dataTask resume];
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 { - (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; NSHTTPURLResponse *ne = (NSHTTPURLResponse *)response;
if([ne statusCode] == 200) { self.statusCode = [ne statusCode];
NSLog(@"connection state is 200 - all okay"); 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 { } 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 @end

View file

@ -1,6 +1,6 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
@interface Window : NSWindow { @interface Window : NSWindow {
} }
@end @end

View file

@ -4,4 +4,10 @@
-(BOOL)canBecomeKeyWindow { -(BOOL)canBecomeKeyWindow {
return YES; return YES;
} }
-(BOOL)isMovableByWindowBackground
{
return TRUE;
}
@end @end