diff --git a/launchers/darwin/src/DownloadDomainContent.m b/launchers/darwin/src/DownloadDomainContent.m index 6f66d6af20..42a8f5c4f0 100644 --- a/launchers/darwin/src/DownloadDomainContent.m +++ b/launchers/darwin/src/DownloadDomainContent.m @@ -5,7 +5,7 @@ - (double) getProgressPercentage { - return (self.progressPercentage * .90) + (self.taskProgressPercentage * .10); + return (self.progressPercentage * 0.50) + (self.taskProgressPercentage * 0.50); } - (void) downloadDomainContent:(NSString *)domainContentUrl @@ -24,9 +24,9 @@ -(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)); + NSLog(@"domain content downloaded %f", (100.0*prog)); - self.progressPercentage = (100.0 * prog); + self.progressPercentage = (int)(100.0 * prog); [[Launcher sharedLauncher] updateProgressIndicator]; } @@ -90,7 +90,7 @@ } - (void) updatePercentage:(NSTimer*) timer { - self.taskProgressPercentage += 3.0; + self.taskProgressPercentage += 4.0; [[Launcher sharedLauncher] updateProgressIndicator]; } diff --git a/launchers/darwin/src/LatestBuildRequest.m b/launchers/darwin/src/LatestBuildRequest.m index 767c67eea1..6ae8bfeba5 100644 --- a/launchers/darwin/src/LatestBuildRequest.m +++ b/launchers/darwin/src/LatestBuildRequest.m @@ -6,7 +6,7 @@ @implementation LatestBuildRequest - (NSInteger) getCurrentVersion { - NSInteger currentVersion; + /*NSInteger currentVersion; @try { NSString* interfaceAppPath = [[Launcher.sharedLauncher getAppPath] stringByAppendingString:@"interface.app"]; NSError * error = nil; @@ -19,8 +19,8 @@ } @catch (NSException *exception) { NSLog(@"an exception was thrown: %@", exception); currentVersion = [Settings.sharedSettings latestBuildVersion]; - } - return currentVersion; + }*/ + return [Settings.sharedSettings latestBuildVersion];//currentVersion; } - (void) requestLatestBuildInfo { diff --git a/launchers/darwin/src/Launcher.h b/launchers/darwin/src/Launcher.h index 129542676c..c51117be01 100644 --- a/launchers/darwin/src/Launcher.h +++ b/launchers/darwin/src/Launcher.h @@ -34,6 +34,7 @@ typedef enum LoginErrorTypes @property (nonatomic, retain) NSString* domainURL; @property (nonatomic, retain) NSString* domainContentUrl; @property (nonatomic, retain) NSString* domainScriptsUrl; +@property (nonatomic, retain) NSString* interfaceDownloadUrl; @property (nonatomic, retain) DownloadInterface* downloadInterface; @property (nonatomic, retain) CredentialsRequest* credentialsRequest; @property (nonatomic, retain) DownloadDomainContent* downloadDomainContent; @@ -44,9 +45,13 @@ typedef enum LoginErrorTypes @property (nonatomic) BOOL waitingForCredentialReponse; @property (nonatomic) BOOL gotCredentialResponse; @property (nonatomic) BOOL waitingForInterfaceToTerminate; +@property (nonatomic) BOOL shouldDownloadInterface; +@property (nonatomic) BOOL latestBuildRequestFinished; +@property (nonatomic, assign) NSTimer* updateProgressIndicatorTimer; @property (nonatomic, assign, readwrite) ProcessState processState; @property (nonatomic, assign, readwrite) LoginError loginError; @property (nonatomic, assign) NSProgressIndicator* progressIndicator; +@property (nonatomic) double progressTarget; - (NSProgressIndicator*) getProgressView; - (void) setProgressView:(NSProgressIndicator*) aProgressIndicator; @@ -79,9 +84,13 @@ typedef enum LoginErrorTypes - (NSString*) getDownloadContentFilename; - (NSString*) getDownloadScriptsFilename; - (NSString*) getDownloadFilename; +- (void) startUpdateProgressIndicatorTimer; +- (void) endUpdateProgressIndicatorTimer; - (BOOL) isLoadedIn; - (NSString*) getAppPath; - (void) updateProgressIndicator; +- (void) setShouldDownloadInterface:(BOOL) shouldDownlaod; +- (BOOL) getShouldDownloadInterface; + (id) sharedLauncher; @end diff --git a/launchers/darwin/src/Launcher.m b/launchers/darwin/src/Launcher.m index 6ce7c1477a..8a55b83ed1 100644 --- a/launchers/darwin/src/Launcher.m +++ b/launchers/darwin/src/Launcher.m @@ -40,6 +40,7 @@ static BOOL const DELETE_ZIP_FILES = TRUE; self.gotCredentialResponse = FALSE; self.waitingForCredentialReponse = FALSE; self.waitingForInterfaceToTerminate = FALSE; + self.latestBuildRequestFinished = FALSE; self.userToken = nil; self.progressIndicator = nil; self.processState = DOWNLOADING_INTERFACE; @@ -87,16 +88,23 @@ static BOOL const DELETE_ZIP_FILES = TRUE; double oldValue = progressIndicator.doubleValue; double contentPercentage = [self.downloadDomainContent getProgressPercentage]; double interfacePercentage = [self.downloadInterface getProgressPercentage]; - double currentTotalPercentage = (contentPercentage * 0.5) + (interfacePercentage * 0.5); + double currentTotalPercentage = self.progressTarget; + if (self.shouldDownloadInterface) { + currentTotalPercentage = (contentPercentage * 0.5) + (interfacePercentage * 0.5); + } else { + currentTotalPercentage = contentPercentage; + } + self.progressTarget = currentTotalPercentage; //[progressIndicator incrementBy: (currentTotalPercentage - oldValue)]; - progressIndicator.doubleValue = [self lerp:oldValue :currentTotalPercentage :0.7]; + //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); + //NSLog(@"----> lerp value: %f", lerpValue); return lerpValue; } @@ -130,7 +138,7 @@ static BOOL const DELETE_ZIP_FILES = TRUE; -(NSProgressIndicator*) getProgressView { - NSLog(@"Getting progressIndicator %@", self.progressIndicator); + //NSLog(@"Getting progressIndicator %@", self.progressIndicator); return self.progressIndicator; } @@ -142,19 +150,12 @@ static BOOL const DELETE_ZIP_FILES = TRUE; - (void) checkLoginStatus { - if ([self isLoadedIn]) { - Launcher* sharedLauncher = [Launcher sharedLauncher]; - [sharedLauncher setCurrentProcessState:CHECKING_UPDATE]; - ProcessScreen* processScreen = [[ProcessScreen alloc] initWithNibName:@"ProcessScreen" bundle:nil]; - [[[[NSApplication sharedApplication] windows] objectAtIndex:0] setContentViewController: processScreen]; - [self.latestBuildRequest requestLatestBuildInfo]; - } else { - [NSTimer scheduledTimerWithTimeInterval:2.0 - target:self - selector:@selector(onSplashScreenTimerFinished:) - userInfo:nil - repeats:NO]; - } + [self.latestBuildRequest requestLatestBuildInfo]; + [NSTimer scheduledTimerWithTimeInterval:2.0 + target:self + selector:@selector(onSplashScreenTimerFinished:) + userInfo:nil + repeats:NO]; [[NSApplication sharedApplication] activateIgnoringOtherApps:TRUE]; } @@ -178,6 +179,31 @@ static BOOL const DELETE_ZIP_FILES = TRUE; return self.scriptsFilename; } +- (void) startUpdateProgressIndicatorTimer +{ + self.progressTarget = 0.0; + self.updateProgressIndicatorTimer = [NSTimer scheduledTimerWithTimeInterval: 0.0016 + target: self + selector: @selector(updateIndicator:) + userInfo:nil + repeats: YES]; + + [[NSRunLoop mainRunLoop] addTimer:self.updateProgressIndicatorTimer forMode:NSRunLoopCommonModes]; +} + +- (void) endUpdateProgressIndicatorTimer +{ + [self.updateProgressIndicatorTimer invalidate]; + self.updateProgressIndicatorTimer = nil; +} + +- (void) updateIndicator:(NSTimer*) timer +{ + NSProgressIndicator* progressIndicator = [self getProgressView]; + double oldValue = progressIndicator.doubleValue; + progressIndicator.doubleValue = [self lerp:oldValue :self.progressTarget :0.3]; +} + - (void)didTerminateApp:(NSNotification *)notification { if (self.waitingForInterfaceToTerminate) { NSString* appName = [notification.userInfo valueForKey:@"NSApplicationName"]; @@ -232,6 +258,7 @@ static BOOL const DELETE_ZIP_FILES = TRUE; - (void) displayNameEntered:(NSString*)aDiplayName { self.processState = DOWNLOADING_INTERFACE; + [self startUpdateProgressIndicatorTimer]; ProcessScreen* processScreen = [[ProcessScreen alloc] initWithNibName:@"ProcessScreen" bundle:nil]; [[[[NSApplication sharedApplication] windows] objectAtIndex:0] setContentViewController: processScreen]; [self.downloadDomainContent downloadDomainContent:self.domainContentUrl]; @@ -240,8 +267,12 @@ static BOOL const DELETE_ZIP_FILES = TRUE; - (void) domainContentDownloadFinished { - //.[self.downloadScripts downloadScripts:self.domainScriptsUrl]; - [self.latestBuildRequest requestLatestBuildInfo]; + if (self.shouldDownloadInterface) { + [self.downloadInterface downloadInterface: self.interfaceDownloadUrl]; + return; + } + [self interfaceFinishedDownloading]; + //[self.latestBuildRequest requestLatestBuildInfo]; } - (void) domainScriptsDownloadFinished @@ -268,10 +299,14 @@ static BOOL const DELETE_ZIP_FILES = TRUE; - (void) interfaceFinishedDownloading { - if (self.processState == DOWNLOADING_INTERFACE) { - self.processState = RUNNING_INTERFACE_AFTER_DOWNLOAD; + [self endUpdateProgressIndicatorTimer]; + NSProgressIndicator* progressIndicator = [self getProgressView]; + progressIndicator.doubleValue = self.progressTarget; + Launcher* sharedLauncher = [Launcher sharedLauncher]; + if ([sharedLauncher currentProccessState] == DOWNLOADING_INTERFACE) { + [sharedLauncher setCurrentProcessState: RUNNING_INTERFACE_AFTER_DOWNLOAD]; } else { - self.processState = RUNNING_INTERFACE_AFTER_UPDATE; + [sharedLauncher setCurrentProcessState: RUNNING_INTERFACE_AFTER_UPDATE]; } ProcessScreen* processScreen = [[ProcessScreen alloc] initWithNibName:@"ProcessScreen" bundle:nil]; [[[[NSApplication sharedApplication] windows] objectAtIndex:0] setContentViewController: processScreen]; @@ -310,17 +345,34 @@ static BOOL const DELETE_ZIP_FILES = TRUE; - (void) shouldDownloadLatestBuild:(BOOL) shouldDownload :(NSString*) downloadUrl { - if (shouldDownload) { + self.shouldDownloadInterface = shouldDownload; + self.interfaceDownloadUrl = downloadUrl; + self.latestBuildRequestFinished = TRUE; + NSLog(@"------> FINISHED ->>>>>>>>"); + /*if (shouldDownload) { [self.downloadInterface downloadInterface: downloadUrl]; return; } - [self launchInterface]; + [self launchInterface];*/ } -(void)onSplashScreenTimerFinished:(NSTimer *)timer { - [[NSApplication sharedApplication] activateIgnoringOtherApps:TRUE]; - [self showLoginScreen]; + if ([self isLoadedIn]) { + Launcher* sharedLauncher = [Launcher sharedLauncher]; + [sharedLauncher setCurrentProcessState:CHECKING_UPDATE]; + NSLog(@"Should Downlaod: %@", self.shouldDownloadInterface ? @"True" : @"False"); + if (self.shouldDownloadInterface) { + ProcessScreen* processScreen = [[ProcessScreen alloc] initWithNibName:@"ProcessScreen" bundle:nil]; + [[[[NSApplication sharedApplication] windows] objectAtIndex:0] setContentViewController: processScreen]; + [self.downloadInterface downloadInterface: self.interfaceDownloadUrl]; + return; + } + [self interfaceFinishedDownloading]; + } else { + [[NSApplication sharedApplication] activateIgnoringOtherApps:TRUE]; + [self showLoginScreen]; + } } -(void)setCurrentProcessState:(ProcessState)aProcessState @@ -402,7 +454,11 @@ static BOOL const DELETE_ZIP_FILES = TRUE; } [workspace launchApplicationAtURL:url options:NSWorkspaceLaunchNewInstance configuration:[NSDictionary dictionaryWithObject:arguments forKey:NSWorkspaceLaunchConfigurationArguments] error:&error]; - [NSApp terminate:self]; + NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval: 3.0 + target: self + selector: @selector(exitLauncher:) + userInfo:nil + repeats: NO]; } - (ProcessState) currentProccessState @@ -410,4 +466,10 @@ static BOOL const DELETE_ZIP_FILES = TRUE; return self.processState; } + +- (void) exitLauncher:(NSTimer*) timer +{ + [NSApp terminate:self]; +} + @end