diff --git a/Sparkle/SUUIBasedUpdateDriver.h b/Sparkle/SUUIBasedUpdateDriver.h index fb145072..65f37443 100644 --- a/Sparkle/SUUIBasedUpdateDriver.h +++ b/Sparkle/SUUIBasedUpdateDriver.h @@ -15,7 +15,7 @@ @class SUStatusController; -@interface SUUIBasedUpdateDriver : SUBasicUpdateDriver +@interface SUUIBasedUpdateDriver : SUBasicUpdateDriver - (void)showModalAlert:(NSAlert *)alert; - (IBAction)cancelDownload:(id)sender; diff --git a/Sparkle/SUUIBasedUpdateDriver.m b/Sparkle/SUUIBasedUpdateDriver.m index f755227f..7875dadd 100644 --- a/Sparkle/SUUIBasedUpdateDriver.m +++ b/Sparkle/SUUIBasedUpdateDriver.m @@ -28,8 +28,9 @@ - (void)didFindValidUpdate { - self.updateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:self.updateItem host:self.host]; - [self.updateAlert setDelegate:self]; + self.updateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:self.updateItem host:self.host completionBlock:^(SUUpdateAlertChoice choice) { + [self updateAlertFinishedWithChoice:choice]; + }]; id versDisp = nil; if ([[self.updater delegate] respondsToSelector:@selector(versionDisplayerForUpdater:)]) { @@ -44,8 +45,7 @@ // 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.updateAlert window] setHidesOnDeactivate:NO]; [NSApp activateIgnoringOtherApps:YES]; } @@ -78,12 +78,11 @@ [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationDidBecomeActiveNotification object:NSApp]; } -- (void)updateAlert:(SUUpdateAlert *)__unused alert finishedWithChoice:(SUUpdateAlertChoice)choice +- (void)updateAlertFinishedWithChoice:(SUUpdateAlertChoice)choice { self.updateAlert = nil; [self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; - switch (choice) - { + switch (choice) { case SUInstallUpdateChoice: self.statusController = [[SUStatusController alloc] initWithHost:self.host]; [self.statusController beginActionWithTitle:SULocalizedString(@"Downloading update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil]; diff --git a/Sparkle/SUUpdateAlert.h b/Sparkle/SUUpdateAlert.h index caf9ccba..2db57bf4 100644 --- a/Sparkle/SUUpdateAlert.h +++ b/Sparkle/SUUpdateAlert.h @@ -24,10 +24,9 @@ typedef NS_ENUM(NSInteger, SUUpdateAlertChoice) { @class WebView, SUAppcastItem, SUHost; @interface SUUpdateAlert : SUWindowController -@property (weak) id delegate; @property (weak) id versionDisplayer; -- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)host; +- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)host completionBlock:(void(^)(SUUpdateAlertChoice))c; - (IBAction)installUpdate:sender; - (IBAction)skipThisVersion:sender; @@ -35,10 +34,4 @@ typedef NS_ENUM(NSInteger, SUUpdateAlertChoice) { @end -@protocol SUUpdateAlertDelegate -- (void)updateAlert:(SUUpdateAlert *)updateAlert finishedWithChoice:(SUUpdateAlertChoice)updateChoice; -@optional -- (void)updateAlert:(SUUpdateAlert *)updateAlert shouldAllowAutoUpdate:(BOOL *)shouldAllowAutoUpdate; -@end - #endif diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index 76c69dda..0b361038 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -21,6 +21,7 @@ @property (strong) SUAppcastItem *updateItem; @property (strong) SUHost *host; +@property (strong) void(^completionBlock)(SUUpdateAlertChoice); @property (strong) NSProgressIndicator *releaseNotesSpinner; @property (assign) BOOL webViewFinishedLoading; @@ -36,7 +37,7 @@ @implementation SUUpdateAlert -@synthesize delegate; +@synthesize completionBlock; @synthesize versionDisplayer; @synthesize updateItem; @@ -52,11 +53,12 @@ @synthesize skipButton; @synthesize laterButton; -- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost +- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost completionBlock:(void (^)(SUUpdateAlertChoice))block { self = [super initWithWindowNibName:@"SUUpdateAlert"]; if (self) { + self.completionBlock = block; host = aHost; updateItem = item; [self setShouldCascadeWindows:NO]; @@ -79,8 +81,8 @@ [self.releaseNotesView setPolicyDelegate:nil]; [self.releaseNotesView removeFromSuperview]; // Otherwise it gets sent Esc presses (why?!) and gets very confused. [self close]; - if ([self.delegate respondsToSelector:@selector(updateAlert:finishedWithChoice:)]) - [self.delegate updateAlert:self finishedWithChoice:choice]; + self.completionBlock(choice); + self.completionBlock = nil; } - (IBAction)installUpdate:(id)__unused sender @@ -164,10 +166,6 @@ if ([self.host objectForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey]) allowAutoUpdates = [self.host boolForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey]; - // Give delegate a chance to modify this choice: - if (self.delegate && [self.delegate respondsToSelector:@selector(updateAlert:shouldAllowAutoUpdate:)]) - [self.delegate updateAlert:self shouldAllowAutoUpdate:&allowAutoUpdates]; - return allowAutoUpdates; }