mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
redoing some work
This commit is contained in:
parent
06bb09ff58
commit
d20f50fa3c
17 changed files with 217 additions and 202 deletions
|
@ -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
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
<rect key="frame" x="0.0" y="0.0" width="515" height="390"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<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"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="MYh-TA-w2A"/>
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
<rect key="frame" x="0.0" y="0.0" width="515" height="390"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<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"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="SuI-2T-YhQ"/>
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
<rect key="frame" x="0.0" y="0.0" width="515" height="390"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<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"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<imageCell key="cell" refusesFirstResponder="YES" focusRingType="none" alignment="left" imageScaling="proportionallyDown" id="ONf-d4-EDr"/>
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
<rect key="frame" x="0.0" y="0.0" width="515" height="390"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<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"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="Abr-HV-cKq"/>
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
<rect key="frame" x="0.0" y="0.0" width="515" height="390"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<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"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="ixM-5m-vi6"/>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface CredentialsRequest : NSObject <NSURLConnectionDelegate> {
|
||||
@interface CredentialsRequest : NSObject {
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) NSMutableData* webData;
|
||||
|
|
|
@ -23,75 +23,72 @@
|
|||
|
||||
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];
|
||||
});
|
||||
NSLog(@"Credentials: request finished");
|
||||
NSHTTPURLResponse *ne = (NSHTTPURLResponse *)response;
|
||||
NSInteger statusCode = [ne statusCode];
|
||||
NSLog(@"Credentials: Response status code: %ld", statusCode);
|
||||
NSLog(@"dante");
|
||||
if (!error) {
|
||||
if (statusCode == 200) {
|
||||
NSLog(@"--->");
|
||||
NSMutableData* webData = [NSMutableData data];
|
||||
[webData appendData:data];
|
||||
NSLog(@"---kdjf");
|
||||
NSString* jsonString = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[data length] encoding:NSUTF8StringEncoding];
|
||||
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSError* jsonError;
|
||||
NSLog(@"fiest");
|
||||
id json = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&jsonError];
|
||||
NSLog(@"last");
|
||||
|
||||
if (jsonError) {
|
||||
NSLog(@"Credentials: Failed to parse json -> error: %@", jsonError);
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
Launcher* sharedLauncher = [Launcher sharedLauncher];
|
||||
[sharedLauncher displayErrorPage];
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (json[@"error"] != nil) {
|
||||
NSLog(@"Credentials: Login failed -> error: %@", json[@"error"]);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
Launcher* sharedLauncher = [Launcher sharedLauncher];
|
||||
[[Settings sharedSettings] login:FALSE];
|
||||
[sharedLauncher setLoginErrorState: CREDENTIALS];
|
||||
[sharedLauncher credentialsAccepted:FALSE];
|
||||
});
|
||||
} else {
|
||||
NSLog(@"Credentials: Login Successful");
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
Launcher* sharedLauncher = [Launcher sharedLauncher];
|
||||
[[Settings sharedSettings] login:TRUE];
|
||||
[sharedLauncher setTokenString:jsonString];
|
||||
[sharedLauncher credentialsAccepted:TRUE];
|
||||
});
|
||||
}
|
||||
} else if (statusCode == 403 || statusCode == 404 || statusCode == 401) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
Launcher* sharedLauncher = [Launcher sharedLauncher];
|
||||
[[Settings sharedSettings] login:FALSE];
|
||||
[sharedLauncher setLoginErrorState: CREDENTIALS];
|
||||
[sharedLauncher credentialsAccepted:FALSE];
|
||||
});
|
||||
} else {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
Launcher* sharedLauncher = [Launcher sharedLauncher];
|
||||
[sharedLauncher displayErrorPage];
|
||||
});
|
||||
}
|
||||
} else {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[Settings sharedSettings] login:TRUE];
|
||||
[sharedLauncher setTokenString:jsonString];
|
||||
[sharedLauncher credentialsAccepted:TRUE];
|
||||
Launcher* sharedLauncher = [Launcher sharedLauncher];
|
||||
[sharedLauncher displayErrorPage];
|
||||
});
|
||||
}
|
||||
|
||||
NSLog(@"credentials: connectionDidFinished completed");
|
||||
|
||||
}];
|
||||
|
||||
|
||||
[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");
|
||||
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 {
|
||||
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];
|
||||
if (json[@"error"] != nil) {
|
||||
[[Settings sharedSettings] login:FALSE];
|
||||
[sharedLauncher setLoginErrorState: CREDENTIALS];
|
||||
[sharedLauncher credentialsAccepted:FALSE];
|
||||
} else {
|
||||
[[Settings sharedSettings] login:TRUE];
|
||||
[sharedLauncher setTokenString:jsonString];
|
||||
[sharedLauncher credentialsAccepted:TRUE];
|
||||
}
|
||||
|
||||
NSLog(@"credentials: connectionDidFinished completed");
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -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 {
|
||||
|
@ -39,27 +39,27 @@
|
|||
[fileManager removeItemAtURL:destinationURL error:nil];
|
||||
}
|
||||
[fileManager moveItemAtURL:location toURL:destinationURL error:&error];
|
||||
|
||||
|
||||
Launcher* sharedLauncher = [Launcher sharedLauncher];
|
||||
[sharedLauncher setDownloadFilename:destinationFileName];
|
||||
NSString* appPath = [sharedLauncher getAppPath];
|
||||
NSString* downloadFileName = [sharedLauncher getDownloadFilename];
|
||||
|
||||
|
||||
NSLog(@"extract interface zip");
|
||||
[sharedLauncher extractZipFileAtDestination:appPath :[appPath stringByAppendingString:downloadFileName]];
|
||||
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];
|
||||
}
|
||||
|
|
6
launchers/darwin/src/ImageView.h
Normal file
6
launchers/darwin/src/ImageView.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface ImageView : NSImageView
|
||||
{
|
||||
}
|
||||
@end
|
11
launchers/darwin/src/ImageView.m
Normal file
11
launchers/darwin/src/ImageView.m
Normal file
|
@ -0,0 +1,11 @@
|
|||
#import "ImageView.h"
|
||||
|
||||
@implementation ImageView
|
||||
|
||||
- (BOOL) mouseDownCanMoveWindow
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
@end
|
|
@ -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
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface OrganizationRequest : NSObject <NSURLConnectionDelegate> {
|
||||
@interface OrganizationRequest : NSObject <NSURLSessionDelegate, NSURLSessionTaskDelegate> {
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) NSMutableData* webData;
|
||||
|
|
|
@ -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,111 @@ 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];
|
||||
NSURLSession * session = [NSURLSession sessionWithConfiguration:NSURLSessionConfiguration.ephemeralSessionConfiguration delegate: self delegateQueue: [NSOperationQueue mainQueue]];
|
||||
NSURLSessionDataTask* dataTask = [session dataTaskWithRequest:request];
|
||||
/* NSURLSessionDataTask* dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
|
||||
NSHTTPURLResponse *ne = (NSHTTPURLResponse *)response;
|
||||
NSInteger statusCode = [ne statusCode];
|
||||
NSLog(@"Organization Response status code: %ld", [ne statusCode]);
|
||||
|
||||
if(theConnection) {
|
||||
self.webData = [NSMutableData data];
|
||||
NSLog(@"connection initiated");
|
||||
}*/
|
||||
if (!error) {
|
||||
if (statusCode == 200) {
|
||||
NSError *jsonError;
|
||||
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&jsonError];
|
||||
if (jsonError) {
|
||||
NSLog(@"Failed to parse Organzation json -> error: %@", jsonError);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
Launcher* sharedLauncher = [Launcher sharedLauncher];
|
||||
[sharedLauncher displayErrorPage];
|
||||
});
|
||||
return;
|
||||
}
|
||||
NSLog(@"getting org done");
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
Launcher* sharedLauncher = [Launcher sharedLauncher];
|
||||
[sharedLauncher setDomainURLInfo:[json valueForKey:@"domain"] :[json valueForKey:@"content_set_url"] :[json valueForKey:@"scripts_url"]];
|
||||
[sharedLauncher setLoginErrorState: NONE];
|
||||
[sharedLauncher organizationRequestFinished:TRUE];
|
||||
});
|
||||
} else if (statusCode == 403 || statusCode == 404) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
Launcher* sharedLauncher = [Launcher sharedLauncher];
|
||||
[sharedLauncher setLoginErrorState: ORGANIZATION];
|
||||
[sharedLauncher organizationRequestFinished:FALSE];
|
||||
});
|
||||
} else {
|
||||
NSLog(@ "Organization Response error: -> %@", error);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
Launcher* sharedLauncher = [Launcher sharedLauncher];
|
||||
[sharedLauncher displayErrorPage];
|
||||
});
|
||||
}
|
||||
} else {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
Launcher* sharedLauncher = [Launcher sharedLauncher];
|
||||
[sharedLauncher displayErrorPage];
|
||||
});
|
||||
}
|
||||
}];*/
|
||||
|
||||
[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 {
|
||||
NSLog(@"----------------> ");
|
||||
|
||||
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");
|
||||
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(@"did recieve data");
|
||||
}
|
||||
|
||||
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
|
||||
NSLog(@"did complete with error");
|
||||
if (error) {
|
||||
// Handle error
|
||||
}
|
||||
else {
|
||||
Launcher* sharedLauncher = [Launcher sharedLauncher];
|
||||
if (self.statusCode == 200) {
|
||||
NSError *jsonError;
|
||||
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:self.receivedData options:kNilOptions error:&jsonError];
|
||||
if (jsonError) {
|
||||
NSLog(@"Failed to parse Organzation json -> error: %@", jsonError);
|
||||
[sharedLauncher displayErrorPage];
|
||||
return;
|
||||
}
|
||||
NSLog(@"getting org done");
|
||||
[sharedLauncher setDomainURLInfo:[json valueForKey:@"domain"] :[json valueForKey:@"content_set_url"] :[json valueForKey:@"scripts_url"]];
|
||||
[sharedLauncher setLoginErrorState: NONE];
|
||||
[sharedLauncher organizationRequestFinished:TRUE];
|
||||
} else if (self.statusCode == 403 || self.statusCode == 404) {
|
||||
[sharedLauncher setLoginErrorState: ORGANIZATION];
|
||||
[sharedLauncher organizationRequestFinished:FALSE];
|
||||
} else {
|
||||
NSLog(@ "Organization Response error: -> %@", error);
|
||||
[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
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface Window : NSWindow {
|
||||
|
||||
|
||||
}
|
||||
@end
|
||||
|
|
|
@ -4,4 +4,10 @@
|
|||
-(BOOL)canBecomeKeyWindow {
|
||||
return YES;
|
||||
}
|
||||
|
||||
-(BOOL)isMovableByWindowBackground
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -17,7 +17,7 @@ void redirectLogToDocuments()
|
|||
|
||||
int main(int argc, const char* argv[]) {
|
||||
//NSApp.appearance = [NSAppearance appearanceNamed: NSAppearanceNameAqua];
|
||||
redirectLogToDocuments();
|
||||
//redirectLogToDocuments();
|
||||
NSArray* apps = [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.highfidelity.launcher"];
|
||||
if ([apps count] > 1) {
|
||||
NSLog(@"launcher is already running");
|
||||
|
|
Loading…
Reference in a new issue