From d9cce796cb8525f26a36388daf9616bbe79322b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Jan=20K=C3=B6hler?= Date: Thu, 31 Oct 2019 01:30:00 +0100 Subject: [PATCH] Let SPUUpdaterDelegate handle errors currently suppressed (#1494) * Let SPUUpdaterDelegate handle errors which are suppressed when calling the user driver --- Sparkle/SPUScheduledUpdateDriver.m | 22 ++++++++++++++++++++-- Sparkle/SPUUpdaterDelegate.h | 8 ++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Sparkle/SPUScheduledUpdateDriver.m b/Sparkle/SPUScheduledUpdateDriver.m index 9e7bd922..ba44f776 100644 --- a/Sparkle/SPUScheduledUpdateDriver.m +++ b/Sparkle/SPUScheduledUpdateDriver.m @@ -18,18 +18,24 @@ @interface SPUScheduledUpdateDriver() @property (nonatomic, readonly) SPUUIBasedUpdateDriver *uiDriver; +@property (nonatomic, readonly) id updater; +@property (nonatomic, readonly) id updaterDelegate; @end @implementation SPUScheduledUpdateDriver @synthesize uiDriver = _uiDriver; +@synthesize updater = _updater; +@synthesize updaterDelegate = _updaterDelegate; - (instancetype)initWithHost:(SUHost *)host applicationBundle:(NSBundle *)applicationBundle sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id )userDriver updaterDelegate:(nullable id )updaterDelegate { self = [super init]; if (self != nil) { _uiDriver = [[SPUUIBasedUpdateDriver alloc] initWithHost:host applicationBundle:applicationBundle sparkleBundle:sparkleBundle updater:updater userDriver:userDriver userInitiated:NO updaterDelegate:updaterDelegate delegate:self]; + _updater = updater; + _updaterDelegate = updaterDelegate; } return self; } @@ -58,18 +64,30 @@ [self.uiDriver resumeUpdate:resumableUpdate completion:completionBlock]; } -- (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *)__unused error +- (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *) error { // Don't tell the user that no update was found or some appcast fetch error occurred for scheduled update checks [self abortUpdateWithError:nil]; + + [self notifyDelegateAboutError:error]; } -- (void)coreDriverIsRequestingAbortUpdateWithError:(nullable NSError *)__unused error +- (void)coreDriverIsRequestingAbortUpdateWithError:(nullable NSError *) error { // Don't tell the user that a non-UI update error occurred for scheduled update checks [self abortUpdateWithError:nil]; + + [self notifyDelegateAboutError:error]; } +- (void)notifyDelegateAboutError:(nullable NSError *)error +{ + if (error == nil) { return; } + if ([self.updaterDelegate respondsToSelector:@selector(updater:scheduledUpdateCheckDidAbortWithError:)]) { + [self.updaterDelegate updater:self.updater scheduledUpdateCheckDidAbortWithError:(NSError * _Nonnull)error]; + } +} + - (void)uiDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error { [self abortUpdateWithError:error]; diff --git a/Sparkle/SPUUpdaterDelegate.h b/Sparkle/SPUUpdaterDelegate.h index 09132e74..51341f8e 100644 --- a/Sparkle/SPUUpdaterDelegate.h +++ b/Sparkle/SPUUpdaterDelegate.h @@ -300,6 +300,14 @@ typedef NS_ENUM(NSInteger, SPUUpdateCheck) */ - (void)updater:(SPUUpdater *)updater didAbortWithError:(NSError *)error; +/*! + Called after an update is aborted due to an error during an scheduled update check. + + \param updater The updater instance. + \param error The error that caused the abort + */ +- (void)updater:(SPUUpdater *)updater scheduledUpdateCheckDidAbortWithError:(NSError *)error; + @end NS_ASSUME_NONNULL_END