From 1da4ee961c832b6ba8d1b1aef86151ee6be268b6 Mon Sep 17 00:00:00 2001 From: Zorg Date: Tue, 1 Mar 2016 22:22:05 -0500 Subject: [PATCH] Add delegate as parameter to SUUpdater's initializer --- Sparkle/SUUpdater.h | 4 ++-- Sparkle/SUUpdater.m | 4 +++- Sparkle/SUUpdaterController.m | 13 +++++++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Sparkle/SUUpdater.h b/Sparkle/SUUpdater.h index 77305d9b..39f5ce01 100644 --- a/Sparkle/SUUpdater.h +++ b/Sparkle/SUUpdater.h @@ -26,11 +26,11 @@ */ SU_EXPORT @interface SUUpdater : NSObject +- (instancetype)initWithHostBundle:(NSBundle *)bundle userDriver:(id )userDriver delegate:(id )delegate; + @property (weak) id delegate; @property (nonatomic, readonly) id userDriver; -- (instancetype)initWithHostBundle:(NSBundle *)bundle userDriver:(id )userDriver; - @property (readonly, strong) NSBundle *hostBundle; @property (strong, readonly) NSBundle *sparkleBundle; diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index e390febf..3d37fc5c 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -53,7 +53,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification @synthesize sparkleBundle; @synthesize decryptionPassword; -- (instancetype)initWithHostBundle:(NSBundle *)bundle userDriver:(id )userDriver +- (instancetype)initWithHostBundle:(NSBundle *)bundle userDriver:(id )userDriver delegate:(id )theDelegate { self = [super init]; @@ -68,6 +68,8 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification _userDriver = userDriver; + delegate = theDelegate; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateDriverDidFinish:) name:SUUpdateDriverFinishedNotification object:nil]; [self startUpdateCycle]; diff --git a/Sparkle/SUUpdaterController.m b/Sparkle/SUUpdaterController.m index 05c69b5e..7cbbc282 100644 --- a/Sparkle/SUUpdaterController.m +++ b/Sparkle/SUUpdaterController.m @@ -33,21 +33,22 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults // We don't want the updater to start its updating cycle before the app has finished launching // If this is instantiated in a nib, the runloop may not be ready + // Furthermore, this delay allows setting the updater and user driver delegates before the updater initializes [self performSelector:@selector(instantiateUpdater) withObject:nil afterDelay:0]; } return self; } +- (void)dealloc +{ + [self unregisterAsObserver]; +} + - (void)instantiateUpdater { NSBundle *hostBundle = [NSBundle mainBundle]; id driver = [[SUSparkleUserDriver alloc] initWithHostBundle:hostBundle delegate:nil]; - self.updater = [[SUUpdater alloc] initWithHostBundle:hostBundle userDriver:driver]; -} - -- (void)dealloc -{ - [self unregisterAsObserver]; + self.updater = [[SUUpdater alloc] initWithHostBundle:hostBundle userDriver:driver delegate:nil]; } - (IBAction)checkForUpdates:(id)__unused sender