diff --git a/Sparkle/SPUUpdater.m b/Sparkle/SPUUpdater.m index 04583aef..2b59ac0c 100644 --- a/Sparkle/SPUUpdater.m +++ b/Sparkle/SPUUpdater.m @@ -353,6 +353,9 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification [self.userDriver showCanCheckForUpdates:!automaticallyCheckForUpdates]; if (!automaticallyCheckForUpdates) { + if ([self.delegate respondsToSelector:@selector(updaterWillIdleSchedulingUpdates:)]) { + [self.delegate updaterWillIdleSchedulingUpdates:self]; + } return; } @@ -372,6 +375,9 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification updateCheckInterval = SUMinimumUpdateCheckInterval; if (intervalSinceCheck < updateCheckInterval) { NSTimeInterval delayUntilCheck = (updateCheckInterval - intervalSinceCheck); // It hasn't been long enough. + if ([self.delegate respondsToSelector:@selector(updater:willScheduleUpdateCheckAfterDelay:)]) { + [self.delegate updater:self willScheduleUpdateCheckAfterDelay:delayUntilCheck]; + } [self.updaterTimer startAndFireAfterDelay:delayUntilCheck]; } else { // We're overdue! Run one now. diff --git a/Sparkle/SPUUpdaterDelegate.h b/Sparkle/SPUUpdaterDelegate.h index b62202ec..18c6d35f 100644 --- a/Sparkle/SPUUpdaterDelegate.h +++ b/Sparkle/SPUUpdaterDelegate.h @@ -40,6 +40,26 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey; @protocol SPUUpdaterDelegate @optional +/*! + Called when a background update will be scheduled after a delay. + + Automatic update checks need to be enabled for this to trigger. + + \param delay The delay until the next scheduled update will occur. + + \param updater The updater instance. + */ +- (void)updater:(SPUUpdater *)updater willScheduleUpdateCheckAfterDelay:(NSTimeInterval)delay; + +/*! + Called when no updates will be scheduled in the future. + + This may later change if automatic update checks become enabled. + + \param updater The updater instance. + */ +- (void)updaterWillIdleSchedulingUpdates:(SPUUpdater *)updater; + /*! Returns whether to allow Sparkle to pop up. diff --git a/sparkle-cli/SPUCommandLineDriver.m b/sparkle-cli/SPUCommandLineDriver.m index cb4a3f22..638a8e87 100644 --- a/sparkle-cli/SPUCommandLineDriver.m +++ b/sparkle-cli/SPUCommandLineDriver.m @@ -60,6 +60,22 @@ void _SULogDisableStandardErrorStream(void); return self; } +- (void)updater:(SPUUpdater *)__unused updater willScheduleUpdateCheckAfterDelay:(NSTimeInterval)delay __attribute__((noreturn)) +{ + if (self.verbose) { + fprintf(stderr, "Last update check occurred too soon. Try again after %0.0f second(s).", delay); + } + exit(EXIT_SUCCESS); +} + +- (void)updaterWillIdleSchedulingUpdates:(SPUUpdater *)__unused updater __attribute__((noreturn)) +{ + if (self.verbose) { + fprintf(stderr, "Automatic update checks are disabled. Exiting.\n"); + } + exit(EXIT_SUCCESS); +} + - (BOOL)updaterShouldAllowInstallerInteraction:(SPUUpdater *)__unused updater { // If the installation is interactive, we can show an authorization prompt for requesting additional privileges, @@ -79,25 +95,21 @@ void _SULogDisableStandardErrorStream(void); } // In case we fail during probing, otherwise we leave error handling to the user driver -- (void)updaterDidNotFindUpdate:(SPUUpdater *)__unused updater +- (void)updaterDidNotFindUpdate:(SPUUpdater *)__unused updater __attribute__((noreturn)) { - if (self.probingForUpdates) { - if (self.verbose) { - fprintf(stderr, "No update available!\n"); - } - exit(EXIT_FAILURE); + if (self.verbose) { + fprintf(stderr, "No update available!\n"); } + exit(EXIT_FAILURE); } // In case we fail during probing, otherwise we leave error handling to the user driver -- (void)updater:(SPUUpdater *)__unused updater didAbortWithError:(NSError *)error +- (void)updater:(SPUUpdater *)__unused updater didAbortWithError:(NSError *)error __attribute__((noreturn)) { - if (self.probingForUpdates) { - if (self.verbose) { - fprintf(stderr, "Aborted update with error (%ld): %s\n", (long)error.code, error.localizedDescription.UTF8String); - } - exit(EXIT_FAILURE); + if (self.verbose) { + fprintf(stderr, "Aborted update with error (%ld): %s\n", (long)error.code, error.localizedDescription.UTF8String); } + exit(EXIT_FAILURE); } - (BOOL)updaterShouldDownloadReleaseNotes:(SPUUpdater *)__unused updater