| 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..e98c21c036872905ec832de760c83691fec782fe 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,8 +17,11 @@
|
| (void (^__nullable)(NSModalResponse returnCode))handler;
|
| @end
|
|
|
| -@interface AppDelegate ()<OmahaCommunicationDelegate, DownloaderDelegate> {
|
| +@interface AppDelegate ()<OmahaCommunicationDelegate,
|
| + DownloaderDelegate,
|
| + UnpackDelegate> {
|
| InstallerWindowController* installerWindowController_;
|
| + Unpacker* unpacker_;
|
| }
|
| @property(strong) NSWindow* window;
|
| @end
|
| @@ -27,6 +33,13 @@
|
| - (void)applicationDidFinishLaunching:(NSNotification*)aNotification {
|
| installerWindowController_ =
|
| [[InstallerWindowController alloc] initWithWindow:window_];
|
| + unpacker_ = [[Unpacker alloc]
|
| + // NOTE: purposefully misspelled Chrome in order to avoid overwriting the
|
| + // current machine's Google Chrome installation.
|
| + // TODO: this app name can be a command-line flag
|
| + initWithFinalAppPath:@"/Applications/Google Chromo.app"];
|
| + unpacker_.delegate = self;
|
| +
|
| [self startDownload];
|
| }
|
|
|
| @@ -45,14 +58,16 @@
|
| [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 +77,16 @@
|
|
|
| // 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 {
|
| +- (void)downloader:(Downloader*)download onSuccess:(NSURL*)diskImageURL {
|
| [installerWindowController_ updateStatusDescription:@"Done."];
|
| - // TODO: replace the line of code below with real code someday
|
| + [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,6 +94,43 @@
|
| [self displayError:downloadError];
|
| }
|
|
|
| +- (void)unpacker:(Unpacker*)unpacker onSuccess:(NSString*)appPath {
|
| + NSError* error = nil;
|
| + [[NSWorkspace sharedWorkspace]
|
| + launchApplicationAtURL:[NSURL fileURLWithPath:appPath isDirectory:NO]
|
| + options:NSWorkspaceLaunchDefault
|
| + configuration:@{}
|
| + error:&error];
|
| + if (error) {
|
| + NSLog(@"Chromo failed to launch: %@", error);
|
| + }
|
| + // TODO: make it seem like the installer has finished its work, and begin
|
| + // tear-down work
|
| + [unpacker unmountDMG];
|
| +}
|
| +
|
| +- (void)unpacker:(Unpacker*)unpacker onFailure:(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 {
|
| + // TODO: add temporary folder deleting
|
| + NSLog(@"we're done here!");
|
| +}
|
| +
|
| +- (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 teminate:nil];
|
| +}
|
| +
|
| // Displays an alert on the main window using the contents of the passed in
|
| // error.
|
| - (void)displayError:(NSError*)error {
|
| @@ -90,7 +139,7 @@
|
| dispatch_sync(dispatch_get_main_queue(), ^{
|
| [alertForUser beginSheetModalForWindow:window_
|
| completionHandler:^(NSModalResponse returnCode) {
|
| - if (returnCode != [alertForUser quitButton]) {
|
| + if (returnCode != [alertForUser quitResponse]) {
|
| [self startDownload];
|
| } else {
|
| [NSApp terminate:nil];
|
|
|