From 2d666b4d84b61128e95f09506a340201f7829fa4 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 20 Feb 2021 00:38:12 -0800 Subject: [PATCH 1/5] Add updater:userDidSkipThisVersion: delegate method --- Sparkle/SPUUIBasedUpdateDriver.m | 11 ++++++++++- Sparkle/SPUUpdaterDelegate.h | 8 ++++++++ Sparkle/SUUpdater.m | 7 +++++++ Sparkle/SUUpdaterDelegate.h | 8 ++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Sparkle/SPUUIBasedUpdateDriver.m b/Sparkle/SPUUIBasedUpdateDriver.m index ceb41864..c165c740 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -107,6 +107,8 @@ - (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate { + id updaterDelegate = self.updaterDelegate; + if (updateItem.isInformationOnlyUpdate) { assert(!self.resumingDownloadedUpdate); assert(!self.resumingInstallingUpdate); @@ -134,6 +136,10 @@ case SPUSkipThisVersionChoice: [self.coreDriver clearDownloadedUpdate]; [self.host setObject:[updateItem versionString] forUserDefaultsKey:SUSkippedVersionKey]; + + if ([self.updaterDelegate respondsToSelector:@selector(updater:userDidSkipThisVersion:)]) { + [self.updaterDelegate updater:self.updater userDidSkipThisVersion:updateItem]; + } // Fall through case SPUInstallLaterChoice: [self.delegate uiDriverIsRequestingAbortUpdateWithError:nil]; @@ -151,6 +157,10 @@ break; case SPUSkipThisVersionChoice: [self.host setObject:[updateItem versionString] forUserDefaultsKey:SUSkippedVersionKey]; + + if ([self.updaterDelegate respondsToSelector:@selector(updater:userDidSkipThisVersion:)]) { + [self.updaterDelegate updater:self.updater userDidSkipThisVersion:updateItem]; + } // Fall through case SPUInstallLaterChoice: [self.delegate uiDriverIsRequestingAbortUpdateWithError:nil]; @@ -171,7 +181,6 @@ [self.delegate uiDriverDidShowUpdate]; } - id updaterDelegate = self.updaterDelegate; if (updateItem.releaseNotesURL != nil && (![updaterDelegate respondsToSelector:@selector(updaterShouldDownloadReleaseNotes:)] || [updaterDelegate updaterShouldDownloadReleaseNotes:self.updater])) { NSURLRequest *request = [NSURLRequest requestWithURL:updateItem.releaseNotesURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30]; diff --git a/Sparkle/SPUUpdaterDelegate.h b/Sparkle/SPUUpdaterDelegate.h index a336047f..7dff6691 100644 --- a/Sparkle/SPUUpdaterDelegate.h +++ b/Sparkle/SPUUpdaterDelegate.h @@ -188,6 +188,14 @@ typedef NS_ENUM(NSInteger, SPUUpdateCheck) */ - (void)updaterDidNotFindUpdate:(SPUUpdater *)updater; +/*! + Called when an update is skipped by the user. + + \param updater The updater instance. + \param item The appcast item corresponding to the update that the user skipped. + */ +- (void)updater:(SPUUpdater *)updater userDidSkipThisVersion:(SUAppcastItem *)item; + /*! Returns whether the release notes (if available) should be downloaded after an update is found and shown. diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index f767c00d..8cde41f8 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -326,6 +326,13 @@ static NSMutableDictionary *sharedUpdaters = nil; } } +- (void)updater:(SPUUpdater *)__unused updater userDidSkipThisVersion:(nonnull SUAppcastItem *)item +{ + if ([self.delegate respondsToSelector:@selector(updater:userDidSkipThisVersion:)]) { + [self.delegate updater:self userDidSkipThisVersion:item]; + } +} + - (void)updater:(SPUUpdater *)__unused updater willDownloadUpdate:(SUAppcastItem *)item withRequest:(NSMutableURLRequest *)request { if ([self.delegate respondsToSelector:@selector(updater:willDownloadUpdate:withRequest:)]) { diff --git a/Sparkle/SUUpdaterDelegate.h b/Sparkle/SUUpdaterDelegate.h index 87e5d1c6..3ac41414 100644 --- a/Sparkle/SUUpdaterDelegate.h +++ b/Sparkle/SUUpdaterDelegate.h @@ -160,6 +160,14 @@ __deprecated_msg("See SPUUpdaterDelegate instead") */ - (void)updater:(SUUpdater *)updater willInstallUpdate:(SUAppcastItem *)item; +/*! + Called when an update is skipped by the user. + + \param updater The updater instance. + \param item The appcast item corresponding to the update that the user skipped. + */ +- (void)updater:(SUUpdater *)updater userDidSkipThisVersion:(SUAppcastItem *)item; + /*! Returns whether the relaunch should be delayed in order to perform other tasks. From 3c0962b13742464d9c6446be7ad845a42358fde5 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 20 Feb 2021 19:05:24 -0800 Subject: [PATCH 2/5] Add delegate methods for downloading/extracting updates --- Sparkle/SPUCoreBasedUpdateDriver.m | 12 ++++++++++++ Sparkle/SPUUpdaterDelegate.h | 24 ++++++++++++++++++++++++ Sparkle/SUUpdater.m | 23 ++++++++++++++++++++++- Sparkle/SUUpdaterDelegate.h | 24 ++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 1 deletion(-) diff --git a/Sparkle/SPUCoreBasedUpdateDriver.m b/Sparkle/SPUCoreBasedUpdateDriver.m index 8dbfb9a0..40eadf4c 100644 --- a/Sparkle/SPUCoreBasedUpdateDriver.m +++ b/Sparkle/SPUCoreBasedUpdateDriver.m @@ -211,6 +211,10 @@ [SUPhasedUpdateGroupInfo setNewUpdateGroupIdentifierForHost:self.host]; } + if ([self.updaterDelegate respondsToSelector:@selector(updater:didDownloadUpdate:)]) { + [self.updaterDelegate updater:self.updater didDownloadUpdate:self.updateItem]; + } + self.resumableUpdate = downloadedUpdate; [self extractUpdate:downloadedUpdate]; } @@ -233,6 +237,10 @@ - (void)extractUpdate:(SPUDownloadedUpdate *)downloadedUpdate { + if ([self.updaterDelegate respondsToSelector:@selector(updater:willExtractUpdate:)]) { + [self.updaterDelegate updater:self.updater willExtractUpdate:self.updateItem]; + } + // Now we have to extract the downloaded archive. if ([self.delegate respondsToSelector:@selector(coreDriverDidStartExtractingUpdate)]) { [self.delegate coreDriverDidStartExtractingUpdate]; @@ -245,6 +253,10 @@ // If the installer started properly, we can't use the downloaded update archive anymore // Especially if the installer fails later and we try resuming the update with a missing archive file [self clearDownloadedUpdate]; + + if ([self.updaterDelegate respondsToSelector:@selector(updater:didExtractUpdate:)]) { + [self.updaterDelegate updater:self.updater didExtractUpdate:self.updateItem]; + } } }]; } diff --git a/Sparkle/SPUUpdaterDelegate.h b/Sparkle/SPUUpdaterDelegate.h index 7dff6691..76792e50 100644 --- a/Sparkle/SPUUpdaterDelegate.h +++ b/Sparkle/SPUUpdaterDelegate.h @@ -216,6 +216,14 @@ typedef NS_ENUM(NSInteger, SPUUpdateCheck) */ - (void)updater:(SPUUpdater *)updater willDownloadUpdate:(SUAppcastItem *)item withRequest:(NSMutableURLRequest *)request; +/*! + Called immediately after succesfull download of the specified update. + + \param updater The SUUpdater instance. + \param item The appcast item corresponding to the update that has been downloaded. + */ +- (void)updater:(SPUUpdater *)updater didDownloadUpdate:(SUAppcastItem *)item; + /*! Called after the specified update failed to download. @@ -232,6 +240,22 @@ typedef NS_ENUM(NSInteger, SPUUpdateCheck) */ - (void)userDidCancelDownload:(SPUUpdater *)updater; +/*! + Called immediately before extracting the specified downloaded update. + + \param updater The SUUpdater instance. + \param item The appcast item corresponding to the update that is proposed to be extracted. + */ +- (void)updater:(SPUUpdater *)updater willExtractUpdate:(SUAppcastItem *)item; + +/*! + Called immediately after extracting the specified downloaded update. + + \param updater The SUUpdater instance. + \param item The appcast item corresponding to the update that has been extracted. + */ +- (void)updater:(SPUUpdater *)updater didExtractUpdate:(SUAppcastItem *)item; + /*! Called immediately before installing the specified update. diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 8cde41f8..71ace7ef 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -337,7 +337,14 @@ static NSMutableDictionary *sharedUpdaters = nil; { if ([self.delegate respondsToSelector:@selector(updater:willDownloadUpdate:withRequest:)]) { [self.delegate updater:self willDownloadUpdate:item withRequest:request]; - } + } +} + +- (void)updater:(SPUUpdater *)__unused updater didDownloadUpdate:(SUAppcastItem *)item +{ + if ([self.delegate respondsToSelector:@selector(updater:didDownloadUpdate:)]) { + [self.delegate updater:self didDownloadUpdate:item]; + } } - (void)updater:(SPUUpdater *)__unused updater failedToDownloadUpdate:(SUAppcastItem *)item error:(NSError *)error @@ -354,6 +361,20 @@ static NSMutableDictionary *sharedUpdaters = nil; } } +- (void)updater:(SPUUpdater *)updater willExtractUpdate:(SUAppcastItem *)item +{ + if ([self.delegate respondsToSelector:@selector(updater:willExtractUpdate:)]) { + [self.delegate updater:self willExtractUpdate:item]; + } +} + +- (void)updater:(SPUUpdater *)updater didExtractUpdate:(SUAppcastItem *)item +{ + if ([self.delegate respondsToSelector:@selector(updater:didExtractUpdate:)]) { + [self.delegate updater:self didExtractUpdate:item]; + } +} + - (void)updater:(SPUUpdater *)__unused updater willInstallUpdate:(SUAppcastItem *)item { if ([self.delegate respondsToSelector:@selector(updater:willInstallUpdate:)]) { diff --git a/Sparkle/SUUpdaterDelegate.h b/Sparkle/SUUpdaterDelegate.h index 3ac41414..718efb4a 100644 --- a/Sparkle/SUUpdaterDelegate.h +++ b/Sparkle/SUUpdaterDelegate.h @@ -136,6 +136,14 @@ __deprecated_msg("See SPUUpdaterDelegate instead") */ - (void)updater:(SUUpdater *)updater willDownloadUpdate:(SUAppcastItem *)item withRequest:(NSMutableURLRequest *)request; +/*! + Called immediately after succesfull download of the specified update. + + \param updater The SUUpdater instance. + \param item The appcast item corresponding to the update that has been downloaded. + */ +- (void)updater:(SUUpdater *)updater didDownloadUpdate:(SUAppcastItem *)item; + /*! Called after the specified update failed to download. @@ -152,6 +160,22 @@ __deprecated_msg("See SPUUpdaterDelegate instead") */ - (void)userDidCancelDownload:(SUUpdater *)updater; +/*! + Called immediately before extracting the specified downloaded update. + + \param updater The SUUpdater instance. + \param item The appcast item corresponding to the update that is proposed to be extracted. + */ +- (void)updater:(SUUpdater *)updater willExtractUpdate:(SUAppcastItem *)item; + +/*! + Called immediately after extracting the specified downloaded update. + + \param updater The SUUpdater instance. + \param item The appcast item corresponding to the update that has been extracted. + */ +- (void)updater:(SUUpdater *)updater didExtractUpdate:(SUAppcastItem *)item; + /*! Called immediately before installing the specified update. From 59326e80d418b9ec5f438885b60099a62c08d9da Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 20 Feb 2021 19:32:21 -0800 Subject: [PATCH 3/5] Add 1.x willInstallUpdateOnQuit:immediateInstallationBlock: stub --- Sparkle/SUUpdater.m | 8 +++++++- Sparkle/SUUpdaterDelegate.h | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 71ace7ef..97618849 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -462,7 +462,13 @@ static NSMutableDictionary *sharedUpdaters = nil; { BOOL installationHandledByDelegate = NO; - if ([self.delegate respondsToSelector:@selector(updater:willInstallUpdateOnQuit:immediateInstallationInvocation:)]) { + if ([self.delegate respondsToSelector:@selector((updater:willInstallUpdateOnQuit:immediateInstallationBlock:))]) { + [self.delegate updater:self willInstallUpdateOnQuit:item immediateInstallationBlock:immediateInstallHandler]; + + // We have to assume they will handle the installation since they implement this method + // Not ideal, but this is why this delegate callback is deprecated + installationHandledByDelegate = YES; + } else if ([self.delegate respondsToSelector:@selector(updater:willInstallUpdateOnQuit:immediateInstallationInvocation:)]) { NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[self class] instanceMethodSignatureForSelector:@selector(finishSilentInstallation)]]; // This invocation will retain self, but this instance is kept alive forever by our singleton pattern anyway diff --git a/Sparkle/SUUpdaterDelegate.h b/Sparkle/SUUpdaterDelegate.h index 718efb4a..c625e14a 100644 --- a/Sparkle/SUUpdaterDelegate.h +++ b/Sparkle/SUUpdaterDelegate.h @@ -295,6 +295,17 @@ __deprecated_msg("See SPUUpdaterDelegate instead") */ - (void)updater:(SUUpdater *)updater willInstallUpdateOnQuit:(SUAppcastItem *)item immediateInstallationInvocation:(NSInvocation *)invocation; +/*! + Called when an update is scheduled to be silently installed on quit. + This is after an update has been automatically downloaded in the background. + (i.e. SUUpdater::automaticallyDownloadsUpdates is YES) + This method acts as a more modern alternative to SUUpdaterDelegate::updater:willInstallUpdateOnQuit:immediateInstallationInvocation: using a block instead of NSInvocation, which is not available in Swift environments. + \param updater The SUUpdater instance. + \param item The appcast item corresponding to the update that is proposed to be installed. + \param installationBlock Can be used to trigger an immediate silent install and relaunch. + */ +- (void)updater:(SUUpdater *)updater willInstallUpdateOnQuit:(SUAppcastItem *)item immediateInstallationBlock:(void (^)(void))installationBlock; + /*! Calls after an update that was scheduled to be silently installed on quit has been canceled. From ea472ae3f0716b1dd38f0403e76933807f447e6c Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 20 Feb 2021 19:40:02 -0800 Subject: [PATCH 4/5] Add updater:shouldPostponeRelaunchForUpdate: 1.x stub --- Sparkle/SUUpdater.m | 3 +++ Sparkle/SUUpdaterDelegate.h | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 97618849..eedfb4d2 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -405,6 +405,9 @@ static NSMutableDictionary *sharedUpdaters = nil; self.postponedInstallHandler = installHandler; shouldPostponeRelaunch = [self.delegate updater:self shouldPostponeRelaunchForUpdate:item untilInvoking:invocation]; + } else if ([self.delegate respondsToSelector:@selector(updater:shouldPostponeRelaunchForUpdate:)]) { + // This API should really take a block, but not fixing a 1.x mishap now + shouldPostponeRelaunch = [self.delegate updater:self shouldPostponeRelaunchForUpdate:item]; } return shouldPostponeRelaunch; diff --git a/Sparkle/SUUpdaterDelegate.h b/Sparkle/SUUpdaterDelegate.h index c625e14a..e601fb2a 100644 --- a/Sparkle/SUUpdaterDelegate.h +++ b/Sparkle/SUUpdaterDelegate.h @@ -208,6 +208,21 @@ __deprecated_msg("See SPUUpdaterDelegate instead") */ - (BOOL)updater:(SUUpdater *)updater shouldPostponeRelaunchForUpdate:(SUAppcastItem *)item untilInvoking:(NSInvocation *)invocation; +/*! + Returns whether the relaunch should be delayed in order to perform other tasks. + + This is not called if the user didn't relaunch on the previous update, + in that case it will immediately restart. + + This method acts as a simpler alternative to SUUpdaterDelegate::updater:shouldPostponeRelaunchForUpdate:untilInvoking: avoiding usage of NSInvocation, which is not available in Swift environments. + + \param updater The SUUpdater instance. + \param item The appcast item corresponding to the update that is proposed to be installed. + + \return \c YES to delay the relaunch. + */ +- (BOOL)updater:(SUUpdater *)updater shouldPostponeRelaunchForUpdate:(SUAppcastItem *)item; + /*! Returns whether the application should be relaunched at all. From e148659cbbe3f062502b18d7dbd0792b352c61a7 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 20 Feb 2021 20:33:58 -0800 Subject: [PATCH 5/5] Add userDidSkipThisVersion case for informational updates --- Sparkle/SPUUIBasedUpdateDriver.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sparkle/SPUUIBasedUpdateDriver.m b/Sparkle/SPUUIBasedUpdateDriver.m index c165c740..989d3611 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -118,6 +118,10 @@ switch (choice) { case SPUSkipThisInformationalVersionChoice: [self.host setObject:[updateItem versionString] forUserDefaultsKey:SUSkippedVersionKey]; + + if ([self.updaterDelegate respondsToSelector:@selector(updater:userDidSkipThisVersion:)]) { + [self.updaterDelegate updater:self.updater userDidSkipThisVersion:updateItem]; + } // Fall through case SPUDismissInformationalNoticeChoice: [self.delegate uiDriverIsRequestingAbortUpdateWithError:nil];