From 15cc7a0e6cf04be29b1c3f77b3e88a739de9c7a1 Mon Sep 17 00:00:00 2001 From: dante ruiz Date: Tue, 9 Jul 2019 10:43:46 -0700 Subject: [PATCH] finished work --- launchers/darwin/src/DownloadDomainContent.m | 10 ++- launchers/darwin/src/DownloadInterface.m | 11 ++- launchers/darwin/src/Launcher.h | 11 ++- launchers/darwin/src/Launcher.m | 78 ++++++++++++-------- launchers/darwin/src/main.mm | 2 +- 5 files changed, 75 insertions(+), 37 deletions(-) diff --git a/launchers/darwin/src/DownloadDomainContent.m b/launchers/darwin/src/DownloadDomainContent.m index 42a8f5c4f0..f95ae39fc8 100644 --- a/launchers/darwin/src/DownloadDomainContent.m +++ b/launchers/darwin/src/DownloadDomainContent.m @@ -5,7 +5,7 @@ - (double) getProgressPercentage { - return (self.progressPercentage * 0.50) + (self.taskProgressPercentage * 0.50); + return (self.progressPercentage * 0.70) + (self.taskProgressPercentage * 0.30); } - (void) downloadDomainContent:(NSString *)domainContentUrl @@ -90,7 +90,13 @@ } - (void) updatePercentage:(NSTimer*) timer { - self.taskProgressPercentage += 4.0; + if (self.taskProgressPercentage < 100.0) { + self.taskProgressPercentage += 1.5; + + if (self.taskProgressPercentage > 100.0) { + self.taskProgressPercentage = 100.0; + } + } [[Launcher sharedLauncher] updateProgressIndicator]; } diff --git a/launchers/darwin/src/DownloadInterface.m b/launchers/darwin/src/DownloadInterface.m index 2e9f7dc697..200a723821 100644 --- a/launchers/darwin/src/DownloadInterface.m +++ b/launchers/darwin/src/DownloadInterface.m @@ -6,6 +6,7 @@ - (void) downloadInterface:(NSString*) downloadUrl { + NSLog(@"-----------------> %@", downloadUrl); self.progressPercentage = 0.0; self.taskProgressPercentage = 0.0; NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:downloadUrl] @@ -30,7 +31,7 @@ - (double) getProgressPercentage { - return (self.progressPercentage * 0.90) + (self.taskProgressPercentage * 0.10); + return (self.progressPercentage * 0.70) + (self.taskProgressPercentage * 0.30); } -(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didResumeAtOffset:(int64_t)fileOffset expectedTotalBytes:(int64_t)expectedTotalBytes { @@ -102,7 +103,13 @@ } - (void) updateTaskPercentage:(NSTimer*) timer { - self.taskProgressPercentage += 3.0; + if (self.taskProgressPercentage < 100.0) { + self.taskProgressPercentage += 1.5; + + if (self.taskProgressPercentage > 100.0) { + self.taskProgressPercentage = 100.0; + } + } [[Launcher sharedLauncher] updateProgressIndicator]; } diff --git a/launchers/darwin/src/Launcher.h b/launchers/darwin/src/Launcher.h index c51117be01..d82824b50e 100644 --- a/launchers/darwin/src/Launcher.h +++ b/launchers/darwin/src/Launcher.h @@ -21,6 +21,12 @@ typedef enum LoginErrorTypes CREDENTIALS } LoginError; +struct LatestBuildInfo { + NSString* downloadURL; + BOOL shouldDownload; + BOOL requestBuildFinished; +}; + @interface Launcher : NSObject { } @property (nonatomic, retain) NSString* password; @@ -52,6 +58,7 @@ typedef enum LoginErrorTypes @property (nonatomic, assign, readwrite) LoginError loginError; @property (nonatomic, assign) NSProgressIndicator* progressIndicator; @property (nonatomic) double progressTarget; +@property (nonatomic) struct LatestBuildInfo buildInfo; - (NSProgressIndicator*) getProgressView; - (void) setProgressView:(NSProgressIndicator*) aProgressIndicator; @@ -89,8 +96,8 @@ typedef enum LoginErrorTypes - (BOOL) isLoadedIn; - (NSString*) getAppPath; - (void) updateProgressIndicator; -- (void) setShouldDownloadInterface:(BOOL) shouldDownlaod; -- (BOOL) getShouldDownloadInterface; +- (void) setLatestBuildInfo:(struct LatestBuildInfo) latestBuildInfo; +- (struct LatestBuildInfo) getLatestBuildInfo; + (id) sharedLauncher; @end diff --git a/launchers/darwin/src/Launcher.m b/launchers/darwin/src/Launcher.m index 8a55b83ed1..9658d8641e 100644 --- a/launchers/darwin/src/Launcher.m +++ b/launchers/darwin/src/Launcher.m @@ -36,6 +36,11 @@ static BOOL const DELETE_ZIP_FILES = TRUE; self.latestBuildRequest = [LatestBuildRequest alloc]; self.organizationRequest = [OrganizationRequest alloc]; self.downloadScripts = [DownloadScripts alloc]; + struct LatestBuildInfo latestBuildInfo; + latestBuildInfo.downloadURL = nil; + latestBuildInfo.shouldDownload = FALSE; + latestBuildInfo.requestBuildFinished = FALSE; + self.buildInfo = latestBuildInfo; self.credentialsAccepted = TRUE; self.gotCredentialResponse = FALSE; self.waitingForCredentialReponse = FALSE; @@ -89,22 +94,21 @@ static BOOL const DELETE_ZIP_FILES = TRUE; double contentPercentage = [self.downloadDomainContent getProgressPercentage]; double interfacePercentage = [self.downloadInterface getProgressPercentage]; double currentTotalPercentage = self.progressTarget; - if (self.shouldDownloadInterface) { - currentTotalPercentage = (contentPercentage * 0.5) + (interfacePercentage * 0.5); + if (self.processState == DOWNLOADING_INTERFACE) { + if (self.shouldDownloadInterface) { + currentTotalPercentage = (contentPercentage * 0.5) + (interfacePercentage * 0.5); + } else { + currentTotalPercentage = contentPercentage; + } } else { - currentTotalPercentage = contentPercentage; + currentTotalPercentage = interfacePercentage; } self.progressTarget = currentTotalPercentage; - - //[progressIndicator incrementBy: (currentTotalPercentage - oldValue)]; - //progressIndicator.doubleValue = [self lerp:oldValue :currentTotalPercentage :0.7]; } - (double) lerp:(double) pointA :(double) pointB :(double) interp { - //NSLog(@"PointA: %f PointB: %f interp: %f", pointA, pointB, interp); double lerpValue = pointA + interp * (pointB - pointA); - //NSLog(@"----> lerp value: %f", lerpValue); return lerpValue; } @@ -150,7 +154,6 @@ static BOOL const DELETE_ZIP_FILES = TRUE; - (void) checkLoginStatus { - [self.latestBuildRequest requestLatestBuildInfo]; [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(onSplashScreenTimerFinished:) @@ -308,9 +311,12 @@ static BOOL const DELETE_ZIP_FILES = TRUE; } else { [sharedLauncher setCurrentProcessState: RUNNING_INTERFACE_AFTER_UPDATE]; } - ProcessScreen* processScreen = [[ProcessScreen alloc] initWithNibName:@"ProcessScreen" bundle:nil]; - [[[[NSApplication sharedApplication] windows] objectAtIndex:0] setContentViewController: processScreen]; - [self launchInterface]; + + [NSTimer scheduledTimerWithTimeInterval: 0.2 + target: self + selector: @selector(callLaunchInterface:) + userInfo:nil + repeats: NO]; } - (void) credentialsEntered:(NSString*)aOrginization :(NSString*)aUsername :(NSString*)aPassword @@ -337,6 +343,16 @@ static BOOL const DELETE_ZIP_FILES = TRUE; return YES; } +- (struct LatestBuildInfo) getLatestBuildInfo +{ + return self.buildInfo; +} + +- (void) setLatestBuildInfo:(struct LatestBuildInfo) latestBuildInfo +{ + self.buildInfo = latestBuildInfo; +} + -(void) showLoginScreen { LoginScreen* loginScreen = [[LoginScreen alloc] initWithNibName:@"LoginScreen" bundle:nil]; @@ -348,24 +364,14 @@ static BOOL const DELETE_ZIP_FILES = TRUE; self.shouldDownloadInterface = shouldDownload; self.interfaceDownloadUrl = downloadUrl; self.latestBuildRequestFinished = TRUE; - NSLog(@"------> FINISHED ->>>>>>>>"); - /*if (shouldDownload) { - [self.downloadInterface downloadInterface: downloadUrl]; - return; - } - [self launchInterface];*/ -} - --(void)onSplashScreenTimerFinished:(NSTimer *)timer -{ if ([self isLoadedIn]) { Launcher* sharedLauncher = [Launcher sharedLauncher]; [sharedLauncher setCurrentProcessState:CHECKING_UPDATE]; - NSLog(@"Should Downlaod: %@", self.shouldDownloadInterface ? @"True" : @"False"); - if (self.shouldDownloadInterface) { + if (shouldDownload) { ProcessScreen* processScreen = [[ProcessScreen alloc] initWithNibName:@"ProcessScreen" bundle:nil]; [[[[NSApplication sharedApplication] windows] objectAtIndex:0] setContentViewController: processScreen]; - [self.downloadInterface downloadInterface: self.interfaceDownloadUrl]; + [self startUpdateProgressIndicatorTimer]; + [self.downloadInterface downloadInterface: downloadUrl]; return; } [self interfaceFinishedDownloading]; @@ -375,6 +381,11 @@ static BOOL const DELETE_ZIP_FILES = TRUE; } } +-(void)onSplashScreenTimerFinished:(NSTimer *)timer +{ + [self.latestBuildRequest requestLatestBuildInfo]; +} + -(void)setCurrentProcessState:(ProcessState)aProcessState { self.processState = aProcessState; @@ -454,11 +465,11 @@ static BOOL const DELETE_ZIP_FILES = TRUE; } [workspace launchApplicationAtURL:url options:NSWorkspaceLaunchNewInstance configuration:[NSDictionary dictionaryWithObject:arguments forKey:NSWorkspaceLaunchConfigurationArguments] error:&error]; - NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval: 3.0 - target: self - selector: @selector(exitLauncher:) - userInfo:nil - repeats: NO]; + [NSTimer scheduledTimerWithTimeInterval: 3.0 + target: self + selector: @selector(exitLauncher:) + userInfo:nil + repeats: NO]; } - (ProcessState) currentProccessState @@ -466,6 +477,13 @@ static BOOL const DELETE_ZIP_FILES = TRUE; return self.processState; } +- (void) callLaunchInterface:(NSTimer*) timer +{ + ProcessScreen* processScreen = [[ProcessScreen alloc] initWithNibName:@"ProcessScreen" bundle:nil]; + [[[[NSApplication sharedApplication] windows] objectAtIndex:0] setContentViewController: processScreen]; + [self launchInterface]; +} + - (void) exitLauncher:(NSTimer*) timer { diff --git a/launchers/darwin/src/main.mm b/launchers/darwin/src/main.mm index 4d66d15549..b6555aad87 100644 --- a/launchers/darwin/src/main.mm +++ b/launchers/darwin/src/main.mm @@ -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");