Skip to content

Commit

Permalink
Merge pull request #1072 from sparkle-project/autoerror
Browse files Browse the repository at this point in the history
Unify handling of aborted updates
  • Loading branch information
kornelski committed May 3, 2017
2 parents 60727bf + a276415 commit 4f96566
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 46 deletions.
20 changes: 0 additions & 20 deletions Sparkle/SUAutomaticUpdateDriver.m
Expand Up @@ -29,7 +29,6 @@ @interface SUUpdateDriver ()
@interface SUAutomaticUpdateDriver ()

@property (assign) BOOL postponingInstallation;
@property (assign) BOOL showErrors;
@property (assign) BOOL willUpdateOnTermination;
@property (assign) BOOL isTerminating;
@property (strong) SUAutomaticUpdateAlert *alert;
Expand All @@ -40,7 +39,6 @@ @interface SUAutomaticUpdateDriver ()
@implementation SUAutomaticUpdateDriver

@synthesize postponingInstallation;
@synthesize showErrors;
@synthesize willUpdateOnTermination;
@synthesize isTerminating;
@synthesize alert;
Expand Down Expand Up @@ -202,7 +200,6 @@ - (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)
[self stopUpdatingOnTermination];
}

self.showErrors = YES;
[super installWithToolAndRelaunch:relaunch displayingUserInterface:showUI];
}

Expand Down Expand Up @@ -231,21 +228,4 @@ - (void)terminateApp
}
}

- (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<SUUpdaterPrivate> updater = self.updater;
id<SUUpdaterDelegate> updaterDelegate = [updater delegate];
if ([updaterDelegate respondsToSelector:@selector(updater:didAbortWithError:)]) {
[updaterDelegate updater:self.updater didAbortWithError:error];
}

[self abortUpdate];
}
}

@end
29 changes: 8 additions & 21 deletions Sparkle/SUScheduledUpdateDriver.m
Expand Up @@ -12,13 +12,17 @@

@interface SUScheduledUpdateDriver ()

@property (assign) BOOL showErrors;

@end

@implementation SUScheduledUpdateDriver

@synthesize showErrors;
- (instancetype)initWithUpdater:(id<SUUpdaterPrivate>)anUpdater
{
if ((self = [super initWithUpdater:anUpdater])) {
self.showErrors = NO;
}
return self;
}

- (void)didFindValidUpdate
{
Expand All @@ -39,25 +43,8 @@ - (void)didNotFindUpdate
[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<SUUpdaterPrivate> updater = self.updater;
id<SUUpdaterDelegate> updaterDelegate = [updater delegate];
if ([updaterDelegate respondsToSelector:@selector(updater:didAbortWithError:)]) {
[updaterDelegate updater:self.updater didAbortWithError:error];
}

[self abortUpdate];
}
}

- (BOOL)shouldDisableKeyboardShortcutForInstallButton {
return YES;
}

@end
1 change: 1 addition & 0 deletions Sparkle/SUUIBasedUpdateDriver.h
Expand Up @@ -15,6 +15,7 @@
@class SUStatusController;

@interface SUUIBasedUpdateDriver : SUBasicUpdateDriver
@property (assign) BOOL showErrors;

- (void)showAlert:(NSAlert *)alert;
- (IBAction)cancelDownload:(id)sender;
Expand Down
14 changes: 9 additions & 5 deletions Sparkle/SUUIBasedUpdateDriver.m
Expand Up @@ -45,11 +45,13 @@ @implementation SUUIBasedUpdateDriver

@synthesize statusController;
@synthesize updateAlert;
@synthesize showErrors;

- (instancetype)initWithUpdater:(id<SUUpdaterPrivate>)anUpdater
{
if ((self = [super initWithUpdater:anUpdater])) {
self.automaticallyInstallUpdates = NO;
self.showErrors = YES;
}
return self;
}
Expand Down Expand Up @@ -293,11 +295,13 @@ - (void)terminateApp

- (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];
}

Expand Down

0 comments on commit 4f96566

Please sign in to comment.