Merge showUpdateFount: methods into single one

Handling the different variations with different completion blocks is a pain when ultimately clients want to display a mostly unified user interface.
This commit is contained in:
Zorg committed 2021-04-16 16:34:01 -07:00
1 parent 2d0b9ae356
commit e64253be0b
13 files changed
+285 -340

No files matched your search

@@ -11,7 +11,7 @@
@interface SUInstallUpdateViewController : NSViewController
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem skippable:(BOOL)skippable reply:(void (^)(SPUUpdateAlertChoice))reply;
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem skippable:(BOOL)skippable reply:(void (^)(SPUUserUpdateChoice))reply;
- (void)showReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData;
@@ -14,7 +14,7 @@
@property (nonatomic) IBOutlet NSTextView *textView;
@property (nonatomic, readonly) SUAppcastItem *appcastItem;
@property (nonatomic, nullable) NSAttributedString *preloadedReleaseNotes;
@property (nonatomic, copy) void (^reply)(SPUUpdateAlertChoice);
@property (nonatomic, copy) void (^reply)(SPUUserUpdateChoice);
@property (nonatomic, readonly) BOOL skippable;
@end
@@ -28,7 +28,7 @@
@synthesize reply = _reply;
@synthesize skippable = _skippable;
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem skippable:(BOOL)skippable reply:(void (^)(SPUUpdateAlertChoice))reply
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem skippable:(BOOL)skippable reply:(void (^)(SPUUserUpdateChoice))reply
{
self = [super initWithNibName:@"SUInstallUpdateViewController" bundle:nil];
if (self != nil) {
@@ -109,7 +109,7 @@
- (IBAction)installUpdate:(id)__unused sender
{
if (self.reply != nil) {
self.reply(SPUInstallUpdateChoice);
self.reply(SPUUserUpdateChoiceInstall);
self.reply = nil;
}
}
@@ -117,7 +117,7 @@
- (IBAction)installUpdateLater:(id)__unused sender
{
if (self.reply != nil) {
self.reply(SPUInstallLaterChoice);
self.reply(SPUUserUpdateChoiceDismiss);
self.reply = nil;
}
}
@@ -125,7 +125,7 @@
- (IBAction)skipUpdate:(id)__unused sender
{
if (self.reply != nil) {
self.reply(SPUSkipThisVersionChoice);
self.reply(SPUUserUpdateChoiceSkip);
self.reply = nil;
}
}
+21 -35
View File
@@ -113,7 +113,7 @@
#pragma mark Update Found
- (void)showUpdateWithAppcastItem:(SUAppcastItem *)appcastItem skippable:(BOOL)skippable reply:(void (^)(SPUUpdateAlertChoice))reply
- (void)showUpdateWithAppcastItem:(SUAppcastItem *)appcastItem skippable:(BOOL)skippable reply:(void (^)(SPUUserUpdateChoice))reply
{
NSPopover *popover = [[NSPopover alloc] init];
popover.behavior = NSPopoverBehaviorTransient;
@@ -121,7 +121,7 @@
__weak SUPopUpTitlebarUserDriver *weakSelf = self;
__block NSButton *actionButton = nil;
SUInstallUpdateViewController *viewController = [[SUInstallUpdateViewController alloc] initWithAppcastItem:appcastItem skippable:skippable reply:^(SPUUpdateAlertChoice choice) {
SUInstallUpdateViewController *viewController = [[SUInstallUpdateViewController alloc] initWithAppcastItem:appcastItem skippable:skippable reply:^(SPUUserUpdateChoice choice) {
reply(choice);
[popover close];
@@ -139,38 +139,24 @@
}];
}
- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)__unused userInitiated reply:(void (^)(SPUUpdateAlertChoice))reply
- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated state:(SPUUserUpdateState)state reply:(void (^)(SPUUserUpdateChoice))reply
{
[self showUpdateWithAppcastItem:appcastItem skippable:YES reply:reply];
}
- (void)showDownloadedUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)__unused userInitiated reply:(void (^)(SPUUpdateAlertChoice))reply
{
[self showUpdateWithAppcastItem:appcastItem skippable:YES reply:reply];
}
- (void)showResumableUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)__unused userInitiated reply:(void (^)(SPUInstallUpdateStatus))reply
{
[self showUpdateWithAppcastItem:appcastItem skippable:NO reply:^(SPUUpdateAlertChoice choice) {
switch (choice) {
case SPUInstallUpdateChoice:
reply(SPUInstallAndRelaunchUpdateNow);
break;
case SPUInstallLaterChoice:
reply(SPUDismissUpdateInstallation);
break;
case SPUSkipThisVersionChoice:
abort();
}
}];
}
- (void)showInformationalUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)__unused userInitiated reply:(void (^)(SPUInformationalUpdateAlertChoice))reply
{
// Todo: show user interface for this
NSLog(@"Found info URL: %@", appcastItem.infoURL);
reply(SPUDismissInformationalNoticeChoice);
switch (state) {
case SPUUserUpdateStateInformational:
// Todo: show user interface for this
NSLog(@"Found info URL: %@", appcastItem.infoURL);
reply(SPUUserUpdateChoiceDismiss);
break;
case SPUUserUpdateStateNotDownloaded:
case SPUUserUpdateStateDownloaded:
[self showUpdateWithAppcastItem:appcastItem skippable:YES reply:reply];
break;
case SPUUserUpdateStateInstalling:
[self showUpdateWithAppcastItem:appcastItem skippable:YES reply:reply];
break;
}
}
- (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData
@@ -184,10 +170,10 @@
#pragma mark Install & Relaunch Update
- (void)showReadyToInstallAndRelaunch:(void (^)(SPUInstallUpdateStatus))installUpdateHandler
- (void)showReadyToInstallAndRelaunch:(void (^)(SPUUserUpdateChoice))installUpdateHandler
{
[self addUpdateButtonWithTitle:@"Install & Relaunch" action:^(NSButton *__unused button) {
installUpdateHandler(SPUInstallAndRelaunchUpdateNow);
installUpdateHandler(SPUUserUpdateChoiceInstall);
}];
}