Add callbacks for scheduled updates occurring after a delay and being idled

I think I used to have this when the remote XPC callbacks were in the user driver and I removed them at some point.
These callbacks are now part of the SPUUpdaterDelegate and the logic is simpler now than before.
The command line utility makes use of these callbacks.
This commit is contained in:
Zorg committed 2016-08-13 20:35:14 -04:00
1 parent eb319ee1b7
commit 4ec5652a0d
3 files changed
+50 -12

No files matched your search

+6
View File
@@ -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.
+20
View File
@@ -40,6 +40,26 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey;
@protocol SPUUpdaterDelegate <NSObject>
@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.
+24 -12
View File
@@ -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