Index: chrome/installer/mac/app/AppDelegate.m |
diff --git a/chrome/installer/mac/app/AppDelegate.m b/chrome/installer/mac/app/AppDelegate.m |
index f60f0db6e36ed8641e1c40dca619541c7b868187..736cd4c06dd000154f395a0ed6dc9e5ef0308738 100644 |
--- a/chrome/installer/mac/app/AppDelegate.m |
+++ b/chrome/installer/mac/app/AppDelegate.m |
@@ -4,9 +4,12 @@ |
#import "AppDelegate.h" |
+#import "Downloader.h" |
#import "InstallerWindowController.h" |
#import "NSError+ChromeInstallerAdditions.h" |
#import "NSAlert+ChromeInstallerAdditions.h" |
+#import "OmahaCommunication.h" |
+#import "Unpacker.h" |
@interface NSAlert () |
- (void)beginSheetModalForWindow:(NSWindow*)sheetWindow |
@@ -14,7 +17,10 @@ |
(void (^__nullable)(NSModalResponse returnCode))handler; |
@end |
-@interface AppDelegate ()<OmahaCommunicationDelegate, DownloaderDelegate> { |
+@interface AppDelegate ()<NSWindowDelegate, |
+ OmahaCommunicationDelegate, |
+ DownloaderDelegate, |
+ UnpackDelegate> { |
InstallerWindowController* installerWindowController_; |
} |
@property(strong) NSWindow* window; |
@@ -25,34 +31,45 @@ |
// Sets up the main window and begins the downloading process. |
- (void)applicationDidFinishLaunching:(NSNotification*)aNotification { |
+ window_.delegate = self; |
installerWindowController_ = |
[[InstallerWindowController alloc] initWithWindow:window_]; |
+ |
[self startDownload]; |
} |
- (void)applicationWillTerminate:(NSNotification*)aNotification { |
} |
-- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)sender { |
+// This function effectively takes the place of |
+// applicationShouldTerminateAfterLastWindowClosed: to make sure that the |
+// application does correctly terminate after closing the installer, but does |
+// not terminate when we call windowOut: to hide the installer during its |
Sidney San Martín
2016/08/19 22:06:04
orderOut:
Anna Zeng
2016/08/23 03:13:43
Done.
|
+// tear-down steps. |
+- (BOOL)windowShouldClose:(id)sender { |
+ [NSApp terminate:nil]; |
return YES; |
} |
- (void)startDownload { |
[installerWindowController_ updateStatusDescription:@"Initializing..."]; |
+ |
OmahaCommunication* omahaMessenger = [[OmahaCommunication alloc] init]; |
omahaMessenger.delegate = self; |
- |
[omahaMessenger fetchDownloadURLs]; |
} |
-- (void)onOmahaSuccessWithURLs:(NSArray*)URLs { |
+- (void)omahaCommunication:(OmahaCommunication*)messenger |
+ onSuccess:(NSArray*)URLs { |
[installerWindowController_ updateStatusDescription:@"Downloading..."]; |
+ |
Downloader* download = [[Downloader alloc] init]; |
download.delegate = self; |
- [download downloadChromeImageToDownloadsDirectory:[URLs firstObject]]; |
+ [download downloadChromeImageFrom:[URLs firstObject]]; |
} |
-- (void)onOmahaFailureWithError:(NSError*)error { |
+- (void)omahaCommunication:(OmahaCommunication*)messenger |
+ onFailure:(NSError*)error { |
NSError* networkError = |
[NSError errorForAlerts:@"Network Error" |
withDescription:@"Could not connect to Chrome server." |
@@ -62,19 +79,19 @@ |
// Bridge method from Downloader to InstallerWindowController. Allows Downloader |
// to update the progressbar without having direct access to any UI obejcts. |
-- (void)didDownloadData:(double)downloadProgressPercentage { |
- [installerWindowController_ |
- updateDownloadProgress:(double)downloadProgressPercentage]; |
+- (void)downloader:(Downloader*)download percentProgress:(double)percentage { |
+ [installerWindowController_ updateDownloadProgress:(double)percentage]; |
} |
-- (void)downloader:(Downloader*)download |
- onDownloadSuccess:(NSURL*)diskImagePath { |
- [installerWindowController_ updateStatusDescription:@"Done."]; |
- // TODO: replace the line of code below with real code someday |
+- (void)downloader:(Downloader*)download onSuccess:(NSURL*)diskImageURL { |
+ [installerWindowController_ updateStatusDescription:@"Installing..."]; |
+ |
+ Unpacker* unpacker = [[Unpacker alloc] init]; |
+ unpacker.delegate = self; |
+ [unpacker mountDMGFromURL:diskImageURL]; |
} |
-- (void)downloader:(Downloader*)download |
- onDownloadFailureWithError:(NSError*)error { |
+- (void)downloader:(Downloader*)download onFailure:(NSError*)error { |
NSError* downloadError = |
[NSError errorForAlerts:@"Download Failure" |
withDescription:@"Unable to download Google Chrome." |
@@ -82,15 +99,85 @@ |
[self displayError:downloadError]; |
} |
+- (void)unpacker:(Unpacker*)unpacker onMountSuccess:(NSString*)mountPath { |
+ // TODO: move the below code into AuthorizedInstall |
+ NSString* diskAppPath = |
+ [NSString pathWithComponents:@[ mountPath, @"Google Chrome.app" ]]; |
+ if (![[NSFileManager defaultManager] fileExistsAtPath:diskAppPath]) { |
+ NSLog(@"File in DMG doesn't exist"); |
+ } |
+ |
+ // By disabling closing the window, we can guarantee that the user will not |
Sidney San Martín
2016/08/19 22:06:04
I don't think guarantee is the right word :). They
Anna Zeng
2016/08/23 03:13:43
Done.
|
+ // have a partially-copied Google Chrome application. |
+ // TODO: should we keep this? |
+ window_.styleMask &= ~NSClosableWindowMask; |
Sidney San Martín
2016/08/19 22:06:04
You also need to disable quit. Implementing applic
Anna Zeng
2016/08/23 03:13:43
Done.
|
+ |
+ // Calling this function will change the progress bar into an indeterminate |
+ // one. We won't need to update the progress bar any more after this point |
+ [installerWindowController_ updateDownloadProgress:-1.0]; |
+ |
+ NSError* error = nil; |
+ if ([[NSFileManager defaultManager] |
+ fileExistsAtPath:@"/Applications/Google Chromo.app"]) { |
+ [[NSFileManager defaultManager] |
+ removeItemAtPath:@"/Applications/Google Chromo.app" |
+ error:nil]; |
+ } |
+ if (![[NSFileManager defaultManager] |
+ copyItemAtPath:diskAppPath |
+ toPath:@"/Applications/Google Chromo.app" |
+ error:&error]) { |
+ NSLog(@"%@", error); |
+ } |
+ |
+ [[NSWorkspace sharedWorkspace] |
+ launchApplicationAtURL: |
+ [NSURL fileURLWithPath:@"/Applications/Google Chromo.app" |
Sidney San Martín
2016/08/19 22:06:04
All of these `@"/Applications/Google Chromo.app"`s
Anna Zeng
2016/08/23 03:13:43
This portion of the code will be taken care of by
|
+ isDirectory:NO] |
+ options:NSWorkspaceLaunchDefault |
+ configuration:@{} |
+ error:&error]; |
+ if (error) { |
+ NSLog(@"Chromo failed to launch: %@", error); |
+ } |
+ |
+ dispatch_async(dispatch_get_main_queue(), ^{ |
+ [window_ orderOut:nil]; |
+ }); |
+ |
+ [unpacker unmountDMG]; |
+} |
+ |
+- (void)unpacker:(Unpacker*)unpacker onMountFailure:(NSError*)error { |
+ NSError* extractError = |
+ [NSError errorForAlerts:@"Install Failure" |
+ withDescription:@"Unable to add Google Chrome to Applications." |
+ isRecoverable:NO]; |
+ [self displayError:extractError]; |
+} |
+ |
+- (void)unpacker:(Unpacker*)unpacker onUnmountSuccess:(NSString*)mountpath { |
+ NSLog(@"we're done here!"); |
+ [NSApp terminate:nil]; |
+} |
+ |
+- (void)unpacker:(Unpacker*)unpacker onUnmountFailure:(NSError*)error { |
+ NSLog(@"error unmounting"); |
+ // NOTE: since we are not deleting the temporary folder if the unmount fails, |
+ // we'll just leave it up to the computer to delete the temporary folder on |
+ // its own time, and to unmount the disk during a restart at some point. There |
+ // is no other work to be done in the mean time. |
+ [NSApp terminate:nil]; |
+} |
+ |
// Displays an alert on the main window using the contents of the passed in |
// error. |
- (void)displayError:(NSError*)error { |
NSAlert* alertForUser = [NSAlert alertWithError:error]; |
- |
- dispatch_sync(dispatch_get_main_queue(), ^{ |
+ dispatch_async(dispatch_get_main_queue(), ^{ |
[alertForUser beginSheetModalForWindow:window_ |
completionHandler:^(NSModalResponse returnCode) { |
- if (returnCode != [alertForUser quitButton]) { |
+ if (returnCode != [alertForUser quitResponse]) { |
[self startDownload]; |
} else { |
[NSApp terminate:nil]; |