|
18 | 18 | @class ALTDeviceManager; |
19 | 19 | @protocol Installation; |
20 | 20 |
|
21 | | -@interface ALTMainViewController () <ALTAddAppleIDDelegate, ALTDragDropViewDelegate> |
22 | | - |
23 | | -@property (weak) IBOutlet NSTextField *descriptionLabel; |
24 | | -@property (weak) IBOutlet NSProgressIndicator *progressIndicator; |
25 | | -@property (weak) IBOutlet NSView *progressContainerView; |
26 | | -@property (weak) IBOutlet NSPopUpButton *accountButton; |
27 | | -@property (weak) IBOutlet NSPopUpButton *deviceButton; |
28 | | -@property (weak) IBOutlet NSPopUpButton *actionButton; |
29 | | -@property (weak) IBOutlet NSButton *startButton; |
30 | | - |
31 | | -@end |
32 | | - |
33 | 21 | @implementation ALTMainViewController { |
34 | 22 | NSArray <NSDictionary *> *accounts; |
35 | 23 | NSArray <NSString *> *devices; |
@@ -68,24 +56,25 @@ - (void)viewDidLoad { |
68 | 56 | @"RegisterDeviceAutomatically": @(YES) |
69 | 57 | }]; |
70 | 58 |
|
71 | | - NSMenuItem *item0 = NSApp.mainMenu.itemArray[0].submenu.itemArray[2]; |
72 | | - item0.action = @selector(didClickAddAppleID:); |
73 | | - item0.target = self; |
| 59 | + NSMenuItem *item = NSApp.mainMenu.itemArray[0].submenu.itemArray[3]; |
| 60 | + item.action = @selector(didClickAddAppleID:); |
| 61 | + item.target = self; |
74 | 62 |
|
75 | | - NSMenuItem *item1 = NSApp.mainMenu.itemArray[0].submenu.itemArray[3]; |
76 | | - item1.action = @selector(didClickKeychainAccess:); |
77 | | - item1.target = self; |
| 63 | + item = NSApp.mainMenu.itemArray[0].submenu.itemArray[4]; |
| 64 | + item.action = @selector(didClickKeychainAccess:); |
| 65 | + item.target = self; |
78 | 66 |
|
79 | | - registerDeviceMenuItem = NSApp.mainMenu.itemArray[0].submenu.itemArray[4]; |
| 67 | + registerDeviceMenuItem = NSApp.mainMenu.itemArray[0].submenu.itemArray[5]; |
80 | 68 | registerDeviceMenuItem.action = @selector(didClickRegisterDeviceAutomatically:); |
81 | 69 | registerDeviceMenuItem.target = self; |
82 | 70 | registerDeviceMenuItem.state = [[NSUserDefaults standardUserDefaults] boolForKey:@"RegisterDeviceAutomatically"] ? NSControlStateValueOn : NSControlStateValueOff; |
83 | 71 |
|
84 | | - NSMenuItem *itemHelp = NSApp.mainMenu.itemArray[4].submenu.itemArray[0]; |
85 | | - itemHelp.action = @selector(showHelp:); |
86 | | - itemHelp.target = self; |
| 72 | + item = NSApp.mainMenu.itemArray[4].submenu.itemArray[0]; |
| 73 | + item.action = @selector(showHelp:); |
| 74 | + item.target = self; |
| 75 | + NSApp.helpMenu = [NSMenu new]; |
87 | 76 |
|
88 | | - mailPluginMenuItem = NSApp.mainMenu.itemArray[0].submenu.itemArray[6]; |
| 77 | + mailPluginMenuItem = NSApp.mainMenu.itemArray[0].submenu.itemArray[7]; |
89 | 78 | mailPluginMenuItem.action = @selector(didClickInstallPlugin:); |
90 | 79 | mailPluginMenuItem.target = self; |
91 | 80 |
|
@@ -123,8 +112,8 @@ - (void)setRepresentedObject:(id)representedObject { |
123 | 112 |
|
124 | 113 | - (void)dragDropView:(ALTDragDropView *)view droppedWithFilenames:(NSArray <NSString *> *)filenames { |
125 | 114 | if (filenames.count == 1) { |
126 | | - self.actionButton.enabled = YES; |
127 | 115 | self->selectedFileURL = [NSURL fileURLWithPath:filenames.firstObject]; |
| 116 | + [_actionButton.menu performActionForItemAtIndex:0]; |
128 | 117 | [self didChooseAction:self.actionButton]; |
129 | 118 | } |
130 | 119 | } |
@@ -179,7 +168,6 @@ - (void)beginMailPluginInstallation { |
179 | 168 | @"do shell script \"/bin/bash -c \\\"\\\\\\\"\\\\$(base64 -D <<< \\\\\\\"%@\\\\\\\")\\\\\\\" -i\\\"\" with administrator privileges", |
180 | 169 | [[NSBundle.mainBundle.executablePath dataUsingEncoding:NSUTF8StringEncoding] base64EncodedStringWithOptions:0] |
181 | 170 | ]; |
182 | | - NSLog(@"%@", script); |
183 | 171 | NSAppleScript *appleScript = [[NSAppleScript alloc] initWithSource:script]; |
184 | 172 | NSAlert *alert = [NSAlert new]; |
185 | 173 | [alert addButtonWithTitle:@"OK"]; |
@@ -460,25 +448,26 @@ - (void)didClickStart:(id)sender { |
460 | 448 | ALTDevice *device = [[ALTDevice alloc] initWithName:@"targetDevice" identifier:devices[_deviceButton.indexOfSelectedItem]]; |
461 | 449 | NSProgress *progress = nil; |
462 | 450 | progress = [ALTDeviceManager.sharedManager installApplicationTo:device |
463 | | - appleID:username |
464 | | - password:password |
465 | | - applicationURL:fileURL |
466 | | - completion:^(NSError * _Nullable error) { |
467 | | - [progress removeObserver:self forKeyPath:@"localizedDescription"]; |
468 | | - if (error) { |
469 | | - dispatch_async(dispatch_get_main_queue(), ^{ |
470 | | - NSAlert *alert = [NSAlert alertWithError:error]; |
471 | | - [alert addButtonWithTitle:@"Dismiss"]; |
472 | | - [alert runModal]; |
473 | | - [self setProgressVisible:NO]; |
474 | | - }); |
475 | | - } |
476 | | - else { |
477 | | - dispatch_async(dispatch_get_main_queue(), ^{ |
478 | | - [self setProgressVisible:NO]; |
479 | | - }); |
480 | | - } |
481 | | - }]; |
| 451 | + appleID:username |
| 452 | + password:password |
| 453 | + applicationURL:fileURL |
| 454 | + completion:^(NSError * _Nullable error) { |
| 455 | + [progress removeObserver:self forKeyPath:@"localizedDescription"]; |
| 456 | + if (error) { |
| 457 | + dispatch_async(dispatch_get_main_queue(), ^{ |
| 458 | + NSAlert *alert = [NSAlert alertWithError:error]; |
| 459 | + [alert addButtonWithTitle:@"Dismiss"]; |
| 460 | + [alert runModal]; |
| 461 | + [self setProgressVisible:NO]; |
| 462 | + }); |
| 463 | + } |
| 464 | + else { |
| 465 | + dispatch_async(dispatch_get_main_queue(), ^{ |
| 466 | + [self setProgressVisible:NO]; |
| 467 | + }); |
| 468 | + } |
| 469 | + } |
| 470 | + ]; |
482 | 471 | // FIXME: Race condition |
483 | 472 | // If the completionHandler is called before the addObserver call, |
484 | 473 | // the app will crash. |
|
0 commit comments