From a2764158d62dc93dbb3cc1968ea19c67aeda1026 Mon Sep 17 00:00:00 2001 From: Kornel Date: Wed, 3 May 2017 12:34:28 +0100 Subject: [PATCH] Unify handling of aborted updates --- Sparkle/SUAutomaticUpdateDriver.m | 20 -------------------- Sparkle/SUScheduledUpdateDriver.m | 29 ++++++++--------------------- Sparkle/SUUIBasedUpdateDriver.h | 1 + Sparkle/SUUIBasedUpdateDriver.m | 14 +++++++++----- 4 files changed, 18 insertions(+), 46 deletions(-) diff --git a/Sparkle/SUAutomaticUpdateDriver.m b/Sparkle/SUAutomaticUpdateDriver.m index 44fb18fd..c88aaeaf 100644 --- a/Sparkle/SUAutomaticUpdateDriver.m +++ b/Sparkle/SUAutomaticUpdateDriver.m @@ -29,7 +29,6 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 @interface SUAutomaticUpdateDriver () @property (assign) BOOL postponingInstallation; -@property (assign) BOOL showErrors; @property (assign) BOOL willUpdateOnTermination; @property (assign) BOOL isTerminating; @property (strong) SUAutomaticUpdateAlert *alert; @@ -40,7 +39,6 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 @implementation SUAutomaticUpdateDriver @synthesize postponingInstallation; -@synthesize showErrors; @synthesize willUpdateOnTermination; @synthesize isTerminating; @synthesize alert; @@ -202,7 +200,6 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 [self stopUpdatingOnTermination]; } - self.showErrors = YES; [super installWithToolAndRelaunch:relaunch displayingUserInterface:showUI]; } @@ -231,21 +228,4 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 } } -- (void)abortUpdateWithError:(NSError *)error -{ - if (self.showErrors) { - [super abortUpdateWithError:error]; - } else { - // Call delegate separately here because otherwise it won't know we stopped. - // Normally this gets called by the superclass - id updater = self.updater; - id updaterDelegate = [updater delegate]; - if ([updaterDelegate respondsToSelector:@selector(updater:didAbortWithError:)]) { - [updaterDelegate updater:self.updater didAbortWithError:error]; - } - - [self abortUpdate]; - } -} - @end diff --git a/Sparkle/SUScheduledUpdateDriver.m b/Sparkle/SUScheduledUpdateDriver.m index 18f4826c..a7a840db 100644 --- a/Sparkle/SUScheduledUpdateDriver.m +++ b/Sparkle/SUScheduledUpdateDriver.m @@ -12,13 +12,17 @@ @interface SUScheduledUpdateDriver () -@property (assign) BOOL showErrors; - @end @implementation SUScheduledUpdateDriver -@synthesize showErrors; +- (instancetype)initWithUpdater:(id)anUpdater +{ + if ((self = [super initWithUpdater:anUpdater])) { + self.showErrors = NO; + } + return self; +} - (void)didFindValidUpdate { @@ -39,25 +43,8 @@ [self abortUpdate]; // Don't tell the user that no update was found; this was a scheduled update. } -- (void)abortUpdateWithError:(NSError *)error -{ - if (self.showErrors) { - [super abortUpdateWithError:error]; - } else { - // Call delegate separately here because otherwise it won't know we stopped. - // Normally this gets called by the superclass - id updater = self.updater; - id updaterDelegate = [updater delegate]; - if ([updaterDelegate respondsToSelector:@selector(updater:didAbortWithError:)]) { - [updaterDelegate updater:self.updater didAbortWithError:error]; - } - - [self abortUpdate]; - } -} - - (BOOL)shouldDisableKeyboardShortcutForInstallButton { return YES; } - + @end diff --git a/Sparkle/SUUIBasedUpdateDriver.h b/Sparkle/SUUIBasedUpdateDriver.h index 69f34459..0c9f3914 100644 --- a/Sparkle/SUUIBasedUpdateDriver.h +++ b/Sparkle/SUUIBasedUpdateDriver.h @@ -15,6 +15,7 @@ @class SUStatusController; @interface SUUIBasedUpdateDriver : SUBasicUpdateDriver +@property (assign) BOOL showErrors; - (void)showAlert:(NSAlert *)alert; - (IBAction)cancelDownload:(id)sender; diff --git a/Sparkle/SUUIBasedUpdateDriver.m b/Sparkle/SUUIBasedUpdateDriver.m index 5e1de6f3..0400e5aa 100644 --- a/Sparkle/SUUIBasedUpdateDriver.m +++ b/Sparkle/SUUIBasedUpdateDriver.m @@ -45,11 +45,13 @@ @synthesize statusController; @synthesize updateAlert; +@synthesize showErrors; - (instancetype)initWithUpdater:(id)anUpdater { if ((self = [super initWithUpdater:anUpdater])) { self.automaticallyInstallUpdates = NO; + self.showErrors = YES; } return self; } @@ -293,11 +295,13 @@ - (void)abortUpdateWithError:(NSError *)error { - NSAlert *alert = [[NSAlert alloc] init]; - alert.messageText = SULocalizedString(@"Update Error!", nil); - alert.informativeText = [NSString stringWithFormat:@"%@", [error localizedDescription]]; - [alert addButtonWithTitle:SULocalizedString(@"Cancel Update", nil)]; - [self showAlert:alert]; + if (self.showErrors) { + NSAlert *alert = [[NSAlert alloc] init]; + alert.messageText = SULocalizedString(@"Update Error!", nil); + alert.informativeText = [NSString stringWithFormat:@"%@", [error localizedDescription]]; + [alert addButtonWithTitle:SULocalizedString(@"Cancel Update", nil)]; + [self showAlert:alert]; + } [super abortUpdateWithError:error]; }