Skip to content

Commit

Permalink
Merge pull request sparkle-project#1 from mosobase/ui-suppresion
Browse files Browse the repository at this point in the history
Patched loophole that allowed Sparkle to present UI even though it wa…
  • Loading branch information
mosobase authored Nov 1, 2016
2 parents b3ce414 + 85478fc commit f6dbebb
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Sparkle/SUAutomaticUpdateDriver.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ @implementation SUAutomaticUpdateDriver

- (void)showUpdateAlert
{

id<SUUpdaterDelegate> updaterDelegate = [self.updater delegate];
if ([updaterDelegate suppressSparkleUI])
{
[self automaticUpdateAlertFinishedWithChoice:SUInstallLaterChoice];
return;
}
// NSLog(@"[Sparkle showUpdateAlert]");

self.interruptible = NO;
self.alert = [[SUAutomaticUpdateAlert alloc] initWithAppcastItem:self.updateItem host:self.host completionBlock:^(SUAutomaticInstallationChoice choice) {
Expand Down Expand Up @@ -98,6 +98,7 @@ - (void)unarchiverDidFinish:(SUUnarchiver *)__unused ua
// If this is marked as a critical update, we'll prompt the user to install it right away.
if ([self.updateItem isCriticalUpdate])
{
// NSLog(@"[Sparkle update deemed critical]");
[self showUpdateAlert];
}
else
Expand Down
1 change: 1 addition & 0 deletions Sparkle/SUErrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ typedef NS_ENUM(OSStatus, SUError) {
// Download phase errors.
SUTemporaryDirectoryError = 2000,
SUDownloadError = 2001,
SUHostDirectoryNotWritable = 2002,

// Extraction phase errors.
SUUnarchivingError = 3000,
Expand Down
6 changes: 5 additions & 1 deletion Sparkle/SUUpdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,13 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey;
@protocol SUUpdaterDelegate <NSObject>
@optional


/*!
Suppress sparkle UI. This should prevent any Sparkle UI from popping up.
Updates should be handled by the host.
*/
-(BOOL)suppressSparkleUI;


/*!
Returns whether to allow Sparkle to pop up.
Expand Down
34 changes: 31 additions & 3 deletions Sparkle/SUUpdater.m
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,30 @@ - (void)checkForUpdatesInBackground
// Background update checks should only happen if we have a network connection.
// Wouldn't want to annoy users on dial-up by establishing a connection every
// hour or so:
SUUpdateDriver *theUpdateDriver = [[([self automaticallyDownloadsUpdates] ? [SUAutomaticUpdateDriver class] : [SUScheduledUpdateDriver class])alloc] initWithUpdater:self];
BOOL canAutomaticallyDownloadUpdates = [self automaticallyDownloadsUpdates];
if (!canAutomaticallyDownloadUpdates)
{
// TB: App is in a non writable directory
if ([self.delegate respondsToSelector:@selector(updater:didAbortWithError:)]) {
NSError *error =
[NSError errorWithDomain:SUSparkleErrorDomain code:SUHostDirectoryNotWritable
userInfo:@{NSLocalizedDescriptionKey: SULocalizedString(@"Host directory is not writable", nil)}];
[self.delegate updater:nil didAbortWithError:error];
}
return;
}

SUUpdateDriver *theUpdateDriver;

if (canAutomaticallyDownloadUpdates || [self.delegate suppressSparkleUI])
{
theUpdateDriver = [[SUAutomaticUpdateDriver alloc] initWithUpdater:self];
}
else {
theUpdateDriver = [[SUScheduledUpdateDriver alloc] initWithUpdater:self];
}

// NSLog(@"[Sparkle driver class: %@]", [theUpdateDriver class]);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self checkForUpdatesInBgReachabilityCheckWithDriver:theUpdateDriver];
});
Expand Down Expand Up @@ -343,6 +365,8 @@ - (void)checkForUpdateInformation

- (void)installUpdatesIfAvailable
{
// NSLog(@"[Sparkle installUpdatesIfAvailable]");

if (self.driver && [self.driver isInterruptible]) {
[self.driver abortUpdate];
}
Expand Down Expand Up @@ -456,11 +480,15 @@ - (BOOL)automaticallyDownloadsUpdates
{
// If the host doesn't allow automatic updates, don't ever let them happen
if (!self.host.allowsAutomaticUpdates) {
// NSLog(@"Host denied automatic updates");
return NO;
}

// Otherwise, automatically downloading updates is allowed. Does the user want it?
return [self.host boolForUserDefaultsKey:SUAutomaticallyUpdateKey];

BOOL automatic = [self.host boolForUserDefaultsKey:SUAutomaticallyUpdateKey];
// NSLog(@"Automatic updates %@", automatic ? @"enabled" : @"disabled");

return automatic;
}

- (void)setFeedURL:(NSURL *)feedURL
Expand Down

0 comments on commit f6dbebb

Please sign in to comment.