From f210be32dc73ad12d032af52019bbd476631f733 Mon Sep 17 00:00:00 2001 From: dante ruiz Date: Tue, 2 Jul 2019 20:56:49 -0700 Subject: [PATCH] updating progress indicator work --- launchers/darwin/src/DownloadDomainContent.h | 1 + launchers/darwin/src/DownloadDomainContent.m | 20 ++++++++++++++++++-- launchers/darwin/src/DownloadInterface.h | 3 ++- launchers/darwin/src/DownloadInterface.m | 18 +++++++++++++++++- launchers/darwin/src/Launcher.m | 13 ++++++++++--- 5 files changed, 48 insertions(+), 7 deletions(-) diff --git a/launchers/darwin/src/DownloadDomainContent.h b/launchers/darwin/src/DownloadDomainContent.h index 64671373e2..80d03fd1c8 100644 --- a/launchers/darwin/src/DownloadDomainContent.h +++ b/launchers/darwin/src/DownloadDomainContent.h @@ -3,6 +3,7 @@ @interface DownloadDomainContent : NSObject { } @property (nonatomic, assign) double progressPercentage; +@property (nonatomic, assign) double taskProgressPercentage; - (void) downloadDomainContent:(NSString*) domainContentUrl; - (double) getProgressPercentage; diff --git a/launchers/darwin/src/DownloadDomainContent.m b/launchers/darwin/src/DownloadDomainContent.m index 31582b4d4c..6f66d6af20 100644 --- a/launchers/darwin/src/DownloadDomainContent.m +++ b/launchers/darwin/src/DownloadDomainContent.m @@ -5,12 +5,13 @@ - (double) getProgressPercentage { - return self.progressPercentage; + return (self.progressPercentage * .90) + (self.taskProgressPercentage * .10); } - (void) downloadDomainContent:(NSString *)domainContentUrl { self.progressPercentage = 0.0; + self.taskProgressPercentage = 0.0; NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:domainContentUrl] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; @@ -36,6 +37,11 @@ -(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location { NSLog(@"Did finish downloading to url"); + NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval: 0.1 + target: self + selector: @selector(updatePercentage:) + userInfo:nil + repeats: YES]; NSError *error = nil; NSFileManager *fileManager = [NSFileManager defaultManager]; NSString *destinationFileName = downloadTask.originalRequest.URL.lastPathComponent; @@ -56,6 +62,7 @@ if (error) { NSLog(@"DownlodDomainContent: failed to move file to destintation -> error: %@", error); + [timer invalidate]; [sharedLauncher displayErrorPage]; return; } @@ -64,18 +71,27 @@ BOOL extractionSuccessful = [sharedLauncher extractZipFileAtDestination:[[sharedLauncher getDownloadPathForContentAndScripts] stringByAppendingString:@"content"] :[[sharedLauncher getDownloadPathForContentAndScripts] stringByAppendingString:[sharedLauncher getDownloadContentFilename]]]; if (!extractionSuccessful) { + [timer invalidate]; [sharedLauncher displayErrorPage]; return; } NSLog(@"finished extracting content file"); + [timer invalidate]; + self.taskProgressPercentage = 100.0; + [sharedLauncher updateProgressIndicator]; [sharedLauncher domainContentDownloadFinished]; } --(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) { [[Launcher sharedLauncher] displayErrorPage]; } } +- (void) updatePercentage:(NSTimer*) timer { + self.taskProgressPercentage += 3.0; + [[Launcher sharedLauncher] updateProgressIndicator]; +} + @end diff --git a/launchers/darwin/src/DownloadInterface.h b/launchers/darwin/src/DownloadInterface.h index 3eec43159b..9d90688654 100644 --- a/launchers/darwin/src/DownloadInterface.h +++ b/launchers/darwin/src/DownloadInterface.h @@ -4,8 +4,9 @@ } @property (nonatomic, assign) NSString* finalFilePath; @property (nonatomic, assign) double progressPercentage; +@property (nonatomic, assign) double taskProgressPercentage; - (void) downloadInterface:(NSString*) downloadUrl; -- (double) getProgressPercentage; +- (double) getProgressPercentage; @end diff --git a/launchers/darwin/src/DownloadInterface.m b/launchers/darwin/src/DownloadInterface.m index f80c2ac3d9..2e9f7dc697 100644 --- a/launchers/darwin/src/DownloadInterface.m +++ b/launchers/darwin/src/DownloadInterface.m @@ -7,6 +7,7 @@ - (void) downloadInterface:(NSString*) downloadUrl { self.progressPercentage = 0.0; + self.taskProgressPercentage = 0.0; NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:downloadUrl] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; @@ -29,7 +30,7 @@ - (double) getProgressPercentage { - return self.progressPercentage; + return (self.progressPercentage * 0.90) + (self.taskProgressPercentage * 0.10); } -(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didResumeAtOffset:(int64_t)fileOffset expectedTotalBytes:(int64_t)expectedTotalBytes { @@ -38,6 +39,11 @@ -(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location { NSLog(@"Did finish downloading to url"); + NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval: 0.1 + target: self + selector: @selector(updateTaskPercentage:) + userInfo:nil + repeats: YES]; NSError *error = nil; NSFileManager *fileManager = [NSFileManager defaultManager]; NSString *destinationFileName = downloadTask.originalRequest.URL.lastPathComponent; @@ -53,6 +59,7 @@ if (error) { NSLog(@"Download Interface: failed to move file to destination -> error: %@", error); + [timer invalidate]; [sharedLauncher displayErrorPage]; return; } @@ -63,6 +70,7 @@ NSLog(@"extract interface zip"); BOOL success = [sharedLauncher extractZipFileAtDestination:appPath :[appPath stringByAppendingString:downloadFileName]]; if (!success) { + [timer invalidate]; [sharedLauncher displayErrorPage]; return; } @@ -80,6 +88,9 @@ NSString* launcherPath = [appPath stringByAppendingString:@"Launcher"]; [[Settings sharedSettings] setLauncherPath:launcherPath]; + [timer invalidate]; + self.taskProgressPercentage = 100.0; + [sharedLauncher updateProgressIndicator]; [sharedLauncher interfaceFinishedDownloading]; } @@ -90,5 +101,10 @@ } } +- (void) updateTaskPercentage:(NSTimer*) timer { + self.taskProgressPercentage += 3.0; + [[Launcher sharedLauncher] updateProgressIndicator]; +} + @end diff --git a/launchers/darwin/src/Launcher.m b/launchers/darwin/src/Launcher.m index bf78384e1f..6ce7c1477a 100644 --- a/launchers/darwin/src/Launcher.m +++ b/launchers/darwin/src/Launcher.m @@ -84,13 +84,20 @@ static BOOL const DELETE_ZIP_FILES = TRUE; - (void) updateProgressIndicator { NSProgressIndicator* progressIndicator = [self getProgressView]; - //double oldValue = progressIndicator.doubleValue; + double oldValue = progressIndicator.doubleValue; double contentPercentage = [self.downloadDomainContent getProgressPercentage]; double interfacePercentage = [self.downloadInterface getProgressPercentage]; - //double currentTotalPercentage = (contentPercentage * 0.5) + (interfacePercentage * 0.5); + double currentTotalPercentage = (contentPercentage * 0.5) + (interfacePercentage * 0.5); //[progressIndicator incrementBy: (currentTotalPercentage - oldValue)]; - progressIndicator.doubleValue = (contentPercentage * 0.4) + (interfacePercentage * 0.4); + progressIndicator.doubleValue = [self lerp:oldValue :currentTotalPercentage :0.7]; +} + +- (double) lerp:(double) pointA :(double) pointB :(double) interp +{ + double lerpValue = pointA + interp * (pointB - pointA); + NSLog(@"----> lerp value: %f", lerpValue); + return lerpValue; } - (BOOL) extractZipFileAtDestination:(NSString *)destination :(NSString*)file