diff --git a/Sparkle/SUSparkleUserDriver.h b/Sparkle/SUSparkleUserDriver.h index b2ec0853..ee8687a3 100644 --- a/Sparkle/SUSparkleUserDriver.h +++ b/Sparkle/SUSparkleUserDriver.h @@ -28,7 +28,7 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithHostBundle:(NSBundle *)hostBundle delegate:(_Nullable id )delegate; -@property (nonatomic, readonly, weak, nullable) id delegate; +@property (nonatomic, weak, nullable) id delegate; @property (nonatomic, readonly, getter=isUpdateInProgress) BOOL updateInProgress; diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 3d37fc5c..e4ab5330 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -72,7 +72,9 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateDriverDidFinish:) name:SUUpdateDriverFinishedNotification object:nil]; - [self startUpdateCycle]; + // This runs the permission prompt if needed, but never before the app has finished launching because the runloop may not have ran before that + // We will also take precaussions if a developer instantiates an updater themselves where the application may not be completely finished launching yet + [self performSelector:@selector(startUpdateCycle) withObject:nil afterDelay:1]; return self; } diff --git a/Sparkle/SUUpdaterController.h b/Sparkle/SUUpdaterController.h index 85b94e45..9ef6071a 100644 --- a/Sparkle/SUUpdaterController.h +++ b/Sparkle/SUUpdaterController.h @@ -31,18 +31,13 @@ NS_ASSUME_NONNULL_BEGIN /*! Initializes a new updater controller instance. Typically this class is instantiated in a nib, thus this method is not usually called directly by the developer. - - Note that this defers instantiation of its SUUpdater to the next cycle in Cocoa's runloop. - This is to prevent starting the updater cycle when the application may not be ready yet. */ - (instancetype)init; /*! Accessible property for the updater. Some properties on the updater can be binded via KVO - - The updater may be nil, which means its instantiation is deferred to the next runloop cycle. */ -@property (nonatomic, readonly, nullable) SUUpdater *updater; +@property (nonatomic, readonly) SUUpdater *updater; /*! Explicitly checks for updates and displays a progress dialog while doing so. diff --git a/Sparkle/SUUpdaterController.m b/Sparkle/SUUpdaterController.m index 7cbbc282..e4a8fa95 100644 --- a/Sparkle/SUUpdaterController.m +++ b/Sparkle/SUUpdaterController.m @@ -31,10 +31,9 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults if (self != nil) { [self registerAsObserver]; - // 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]; + NSBundle *hostBundle = [NSBundle mainBundle]; + id driver = [[SUSparkleUserDriver alloc] initWithHostBundle:hostBundle delegate:nil]; + self.updater = [[SUUpdater alloc] initWithHostBundle:hostBundle userDriver:driver delegate:nil]; } return self; } @@ -44,13 +43,6 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults [self unregisterAsObserver]; } -- (void)instantiateUpdater -{ - NSBundle *hostBundle = [NSBundle mainBundle]; - id driver = [[SUSparkleUserDriver alloc] initWithHostBundle:hostBundle delegate:nil]; - self.updater = [[SUUpdater alloc] initWithHostBundle:hostBundle userDriver:driver delegate:nil]; -} - - (IBAction)checkForUpdates:(id)__unused sender { [self.updater checkForUpdates]; @@ -59,7 +51,7 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults - (BOOL)validateMenuItem:(NSMenuItem *)item { if ([item action] == @selector(checkForUpdates:)) { - return (self.updater != nil && !self.updater.updateInProgress); + return !self.updater.updateInProgress; } return YES; }