From 0bb3ab51b31e4297e857ae2932b5f8f3bd4099ee Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 1 Jan 2017 21:22:02 -0500 Subject: [PATCH] Handle informational only updates from the automatic update driver The automatic update driver defers the informational only update & aborts, allowing a scheduled UI driver to resume it. The automatic update driver aborts before the point an update would normally be downloaded. --- Sparkle/SPUAutomaticUpdateDriver.m | 9 +++++++-- Sparkle/SPUCoreBasedUpdateDriver.h | 2 ++ Sparkle/SPUCoreBasedUpdateDriver.m | 6 ++++++ Sparkle/SPUDownloadedUpdate.h | 9 +++++++-- Sparkle/SPUDownloadedUpdate.m | 9 +++++++++ Sparkle/SPUUpdater.m | 2 +- 6 files changed, 32 insertions(+), 5 deletions(-) diff --git a/Sparkle/SPUAutomaticUpdateDriver.m b/Sparkle/SPUAutomaticUpdateDriver.m index a0c04ab4..dfc7d90f 100644 --- a/Sparkle/SPUAutomaticUpdateDriver.m +++ b/Sparkle/SPUAutomaticUpdateDriver.m @@ -84,7 +84,12 @@ { self.updateItem = updateItem; - [self.coreDriver downloadUpdateFromAppcastItem:updateItem]; + if (updateItem.isInformationOnlyUpdate) { + [self.coreDriver deferInformationalUpdate:updateItem]; + [self abortUpdate]; + } else { + [self.coreDriver downloadUpdateFromAppcastItem:updateItem]; + } } - (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately silently:(BOOL)willInstallSilently @@ -126,7 +131,7 @@ - (void)abortUpdateWithError:(NSError *)error { - BOOL showNextUpdateImmediately = (error == nil || error.code == SUInstallationAuthorizeLaterError) && (!self.willInstallSilently || self.updateItem.isCriticalUpdate); + BOOL showNextUpdateImmediately = (error == nil || error.code == SUInstallationAuthorizeLaterError) && (!self.willInstallSilently || self.updateItem.isCriticalUpdate || self.updateItem.isInformationOnlyUpdate); [self.coreDriver abortUpdateAndShowNextUpdateImmediately:showNextUpdateImmediately error:error]; } diff --git a/Sparkle/SPUCoreBasedUpdateDriver.h b/Sparkle/SPUCoreBasedUpdateDriver.h index cdf49b6e..94872f95 100644 --- a/Sparkle/SPUCoreBasedUpdateDriver.h +++ b/Sparkle/SPUCoreBasedUpdateDriver.h @@ -63,6 +63,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)downloadUpdateFromAppcastItem:(SUAppcastItem *)updateItem; +- (void)deferInformationalUpdate:(SUAppcastItem *)updateItem; + - (void)extractDownloadedUpdate; - (void)clearDownloadedUpdate; diff --git a/Sparkle/SPUCoreBasedUpdateDriver.m b/Sparkle/SPUCoreBasedUpdateDriver.m index e46e2fee..3f897c4f 100644 --- a/Sparkle/SPUCoreBasedUpdateDriver.m +++ b/Sparkle/SPUCoreBasedUpdateDriver.m @@ -203,6 +203,11 @@ [self extractUpdate:downloadedUpdate]; } +- (void)deferInformationalUpdate:(SUAppcastItem *)updateItem +{ + self.downloadedUpdate = [[SPUDownloadedUpdate alloc] initWithAppcastItem:updateItem]; +} + - (void)extractDownloadedUpdate { assert(self.downloadedUpdate != nil); @@ -342,6 +347,7 @@ [self.downloadDriver cleanup]; SPUDownloadedUpdate *downloadedUpdate = (error == nil || error.code == SUInstallationAuthorizeLaterError) ? self.downloadedUpdate : nil; + [self.basicDriver abortUpdateAndShowNextUpdateImmediately:shouldShowUpdateImmediately downloadedUpdate:downloadedUpdate error:error]; } diff --git a/Sparkle/SPUDownloadedUpdate.h b/Sparkle/SPUDownloadedUpdate.h index aa8db1ec..7c542aa8 100644 --- a/Sparkle/SPUDownloadedUpdate.h +++ b/Sparkle/SPUDownloadedUpdate.h @@ -16,9 +16,14 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithAppcastItem:(SUAppcastItem *)updateItem downloadName:(NSString *)downloadName temporaryDirectory:(NSString *)temporaryDirectory; +// For information only updates +- (instancetype)initWithAppcastItem:(SUAppcastItem *)updateItem; + @property (nonatomic, readonly) SUAppcastItem *updateItem; -@property (nonatomic, copy, readonly) NSString *downloadName; -@property (nonatomic, copy, readonly) NSString *temporaryDirectory; + +// These are nil when the update item is just informational and no download is linked +@property (nonatomic, copy, nullable, readonly) NSString *downloadName; +@property (nonatomic, copy, nullable, readonly) NSString *temporaryDirectory; @end diff --git a/Sparkle/SPUDownloadedUpdate.m b/Sparkle/SPUDownloadedUpdate.m index bd670566..709cb17c 100644 --- a/Sparkle/SPUDownloadedUpdate.m +++ b/Sparkle/SPUDownloadedUpdate.m @@ -29,4 +29,13 @@ return self; } +- (instancetype)initWithAppcastItem:(SUAppcastItem *)updateItem +{ + self = [super init]; + if (self != nil) { + _updateItem = updateItem; + } + return self; +} + @end diff --git a/Sparkle/SPUUpdater.m b/Sparkle/SPUUpdater.m index 600e46d8..ef1bff55 100644 --- a/Sparkle/SPUUpdater.m +++ b/Sparkle/SPUUpdater.m @@ -797,7 +797,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification // Proceed as normal if there's no resumable updates completionHandler(regularCheckInterval); } else { - if (!installationInfo.canSilentlyInstall || [installationInfo.appcastItem isCriticalUpdate]) { + if (!installationInfo.canSilentlyInstall || [installationInfo.appcastItem isCriticalUpdate] || [installationInfo.appcastItem isInformationOnlyUpdate]) { completionHandler(MIN(regularCheckInterval, SUImpatientUpdateCheckInterval)); } else { completionHandler(MAX(regularCheckInterval, SUImpatientUpdateCheckInterval));