OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "AppDelegate.h" | 5 #import "AppDelegate.h" |
6 | 6 |
7 #import "InstallerWindowController.h" | 7 #import "InstallerWindowController.h" |
8 #import "NSError+ChromeInstallerAdditions.h" | 8 #import "NSError+ChromeInstallerAdditions.h" |
9 #import "NSAlert+ChromeInstallerAdditions.h" | 9 #import "NSAlert+ChromeInstallerAdditions.h" |
| 10 #import "AuthorizedInstall.h" |
10 | 11 |
11 @interface NSAlert () | 12 @interface NSAlert () |
12 - (void)beginSheetModalForWindow:(NSWindow*)sheetWindow | 13 - (void)beginSheetModalForWindow:(NSWindow*)sheetWindow |
13 completionHandler: | 14 completionHandler: |
14 (void (^__nullable)(NSModalResponse returnCode))handler; | 15 (void (^__nullable)(NSModalResponse returnCode))handler; |
15 @end | 16 @end |
16 | 17 |
17 @interface AppDelegate ()<OmahaCommunicationDelegate, DownloaderDelegate> { | 18 @interface AppDelegate ()<OmahaCommunicationDelegate, DownloaderDelegate> { |
18 InstallerWindowController* installerWindowController_; | 19 InstallerWindowController* installerWindowController_; |
| 20 AuthorizedInstall* authorizedInstall_; |
19 } | 21 } |
20 @property(strong) NSWindow* window; | 22 @property(strong) NSWindow* window; |
21 @end | 23 @end |
22 | 24 |
23 @implementation AppDelegate | 25 @implementation AppDelegate |
24 @synthesize window = window_; | 26 @synthesize window = window_; |
25 | 27 |
26 // Sets up the main window and begins the downloading process. | 28 // Sets up the main window and begins the downloading process. |
27 - (void)applicationDidFinishLaunching:(NSNotification*)aNotification { | 29 - (void)applicationDidFinishLaunching:(NSNotification*)aNotification { |
| 30 // TODO: fix UI not loading until after asking for authorization. |
28 installerWindowController_ = | 31 installerWindowController_ = |
29 [[InstallerWindowController alloc] initWithWindow:window_]; | 32 [[InstallerWindowController alloc] initWithWindow:window_]; |
30 [self startDownload]; | 33 authorizedInstall_ = [[AuthorizedInstall alloc] init]; |
| 34 if ([authorizedInstall_ loadInstallationTool]) { |
| 35 [self startDownload]; |
| 36 } else { |
| 37 [self onLoadInstallationToolFailure]; |
| 38 } |
31 } | 39 } |
32 | 40 |
33 - (void)applicationWillTerminate:(NSNotification*)aNotification { | 41 - (void)applicationWillTerminate:(NSNotification*)aNotification { |
34 } | 42 } |
35 | 43 |
36 - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)sender { | 44 - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)sender { |
37 return YES; | 45 return YES; |
38 } | 46 } |
39 | 47 |
40 - (void)startDownload { | 48 - (void)startDownload { |
(...skipping 23 matching lines...) Expand all Loading... |
64 // to update the progressbar without having direct access to any UI obejcts. | 72 // to update the progressbar without having direct access to any UI obejcts. |
65 - (void)didDownloadData:(double)downloadProgressPercentage { | 73 - (void)didDownloadData:(double)downloadProgressPercentage { |
66 [installerWindowController_ | 74 [installerWindowController_ |
67 updateDownloadProgress:(double)downloadProgressPercentage]; | 75 updateDownloadProgress:(double)downloadProgressPercentage]; |
68 } | 76 } |
69 | 77 |
70 - (void)downloader:(Downloader*)download | 78 - (void)downloader:(Downloader*)download |
71 onDownloadSuccess:(NSURL*)diskImagePath { | 79 onDownloadSuccess:(NSURL*)diskImagePath { |
72 [installerWindowController_ updateStatusDescription:@"Done."]; | 80 [installerWindowController_ updateStatusDescription:@"Done."]; |
73 [installerWindowController_ enableLaunchButton]; | 81 [installerWindowController_ enableLaunchButton]; |
74 // TODO: replace the line of code below with real code someday | 82 // TODO: Add unpacking step here and pass the path to the app bundle inside |
| 83 // the mounted disk image path to startInstall. Currently passing hardcoded |
| 84 // path to preunpacked app bundle. |
| 85 //[authorizedInstall_ |
| 86 // startInstall:@"$HOME/Downloads/Google Chrome.app"]; |
75 } | 87 } |
76 | 88 |
77 - (void)downloader:(Downloader*)download | 89 - (void)downloader:(Downloader*)download |
78 onDownloadFailureWithError:(NSError*)error { | 90 onDownloadFailureWithError:(NSError*)error { |
79 NSError* downloadError = | 91 NSError* downloadError = |
80 [NSError errorForAlerts:@"Download Failure" | 92 [NSError errorForAlerts:@"Download Failure" |
81 withDescription:@"Unable to download Google Chrome." | 93 withDescription:@"Unable to download Google Chrome." |
82 isRecoverable:NO]; | 94 isRecoverable:NO]; |
83 [self displayError:downloadError]; | 95 [self displayError:downloadError]; |
84 } | 96 } |
85 | 97 |
| 98 - (void)onLoadInstallationToolFailure { |
| 99 NSError* loadToolError = [NSError |
| 100 errorForAlerts:@"Could not load installion tool" |
| 101 withDescription: |
| 102 @"Your Chrome Installer may be corrupted. Download and try again." |
| 103 isRecoverable:NO]; |
| 104 [self displayError:loadToolError]; |
| 105 } |
| 106 |
86 // Displays an alert on the main window using the contents of the passed in | 107 // Displays an alert on the main window using the contents of the passed in |
87 // error. | 108 // error. |
88 - (void)displayError:(NSError*)error { | 109 - (void)displayError:(NSError*)error { |
89 NSAlert* alertForUser = [NSAlert alertWithError:error]; | 110 NSAlert* alertForUser = [NSAlert alertWithError:error]; |
90 | 111 |
91 dispatch_sync(dispatch_get_main_queue(), ^{ | 112 dispatch_async(dispatch_get_main_queue(), ^{ |
92 [alertForUser beginSheetModalForWindow:window_ | 113 [alertForUser beginSheetModalForWindow:window_ |
93 completionHandler:^(NSModalResponse returnCode) { | 114 completionHandler:^(NSModalResponse returnCode) { |
94 if (returnCode != [alertForUser quitButton]) { | 115 if (returnCode != [alertForUser quitButton]) { |
95 [self startDownload]; | 116 [self startDownload]; |
96 } else { | 117 } else { |
97 [NSApp terminate:nil]; | 118 [NSApp terminate:nil]; |
98 } | 119 } |
99 }]; | 120 }]; |
100 }); | 121 }); |
101 } | 122 } |
102 | 123 |
103 @end | 124 @end |
OLD | NEW |