diff --git a/Sparkle/SUAutomaticUpdateAlert.h b/Sparkle/SUAutomaticUpdateAlert.h index 0a2c8610..be0f7f6d 100644 --- a/Sparkle/SUAutomaticUpdateAlert.h +++ b/Sparkle/SUAutomaticUpdateAlert.h @@ -22,15 +22,11 @@ typedef NS_ENUM(NSInteger, SUAutomaticInstallationChoice) { @class SUAppcastItem, SUHost; @interface SUAutomaticUpdateAlert : SUWindowController -- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)hostBundle delegate:(id)delegate; +- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)hostBundle completionBlock:(void (^)(SUAutomaticInstallationChoice))c; - (IBAction)installNow:sender; - (IBAction)installLater:sender; - (IBAction)doNotInstall:sender; @end -@protocol SUAutomaticUpdateAlertDelegate -- (void)automaticUpdateAlert:(SUAutomaticUpdateAlert *)aua finishedWithChoice:(SUAutomaticInstallationChoice)choice; -@end - #endif diff --git a/Sparkle/SUAutomaticUpdateAlert.m b/Sparkle/SUAutomaticUpdateAlert.m index 1119b27b..4271e608 100644 --- a/Sparkle/SUAutomaticUpdateAlert.m +++ b/Sparkle/SUAutomaticUpdateAlert.m @@ -11,23 +11,22 @@ #import "SUHost.h" @interface SUAutomaticUpdateAlert () +@property (strong) void(^completionBlock)(SUAutomaticInstallationChoice); @property (strong) SUAppcastItem *updateItem; -@property (weak) id delegate; @property (strong) SUHost *host; @end @implementation SUAutomaticUpdateAlert -@synthesize delegate; @synthesize host; @synthesize updateItem; +@synthesize completionBlock; -- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost delegate:(id)del +- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost completionBlock:(void (^)(SUAutomaticInstallationChoice))block { self = [super initWithWindowNibName:@"SUAutomaticUpdateAlert"]; - if (self) - { + if (self) { self.updateItem = item; - self.delegate = del; + self.completionBlock = block; self.host = aHost; [self setShouldCascadeWindows:NO]; [[self window] center]; @@ -40,19 +39,22 @@ - (IBAction)installNow:(id)__unused sender { [self close]; - [self.delegate automaticUpdateAlert:self finishedWithChoice:SUInstallNowChoice]; + self.completionBlock(SUInstallNowChoice); + self.completionBlock = nil; } - (IBAction)installLater:(id)__unused sender { [self close]; - [self.delegate automaticUpdateAlert:self finishedWithChoice:SUInstallLaterChoice]; + self.completionBlock(SUInstallLaterChoice); + self.completionBlock = nil; } - (IBAction)doNotInstall:(id)__unused sender { [self close]; - [self.delegate automaticUpdateAlert:self finishedWithChoice:SUDoNotInstallChoice]; + self.completionBlock(SUDoNotInstallChoice); + self.completionBlock = nil; } - (NSImage *)applicationIcon diff --git a/Sparkle/SUAutomaticUpdateDriver.h b/Sparkle/SUAutomaticUpdateDriver.h index 9935936e..4dd90e8f 100644 --- a/Sparkle/SUAutomaticUpdateDriver.h +++ b/Sparkle/SUAutomaticUpdateDriver.h @@ -13,7 +13,7 @@ #import "SUBasicUpdateDriver.h" #import "SUAutomaticUpdateAlert.h" -@interface SUAutomaticUpdateDriver : SUBasicUpdateDriver +@interface SUAutomaticUpdateDriver : SUBasicUpdateDriver @end diff --git a/Sparkle/SUAutomaticUpdateDriver.m b/Sparkle/SUAutomaticUpdateDriver.m index 51c445c0..45b3d546 100644 --- a/Sparkle/SUAutomaticUpdateDriver.m +++ b/Sparkle/SUAutomaticUpdateDriver.m @@ -42,13 +42,14 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 - (void)showUpdateAlert { self.interruptible = NO; - self.alert = [[SUAutomaticUpdateAlert alloc] initWithAppcastItem:self.updateItem host:self.host delegate:self]; + self.alert = [[SUAutomaticUpdateAlert alloc] initWithAppcastItem:self.updateItem host:self.host completionBlock:^(SUAutomaticInstallationChoice choice) { + [self automaticUpdateAlertFinishedWithChoice:choice]; + }]; // If the app is a menubar app or the like, we need to focus it first and alter the // update prompt to behave like a normal window. Otherwise if the window were hidden // there may be no way for the application to be activated to make it visible again. - if ([self.host isBackgroundApplication]) - { + if ([self.host isBackgroundApplication]) { [[self.alert window] setHidesOnDeactivate:NO]; [NSApp activateIgnoringOtherApps:YES]; } @@ -138,7 +139,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationDidBecomeActiveNotification object:NSApp]; } -- (void)automaticUpdateAlert:(SUAutomaticUpdateAlert *)__unused aua finishedWithChoice:(SUAutomaticInstallationChoice)choice +- (void)automaticUpdateAlertFinishedWithChoice:(SUAutomaticInstallationChoice)choice { switch (choice) {