diff --git a/Sparkle/SUHost.h b/Sparkle/SUHost.h index 364851bb..927b354d 100644 --- a/Sparkle/SUHost.h +++ b/Sparkle/SUHost.h @@ -13,8 +13,6 @@ - (instancetype)initWithBundle:(NSBundle *)aBundle; @property (readonly, copy) NSString *bundlePath; -// Even if automatic updates are allowed, this does not indicate that the user has writable permissions to do so conveniently -@property (readonly) BOOL allowsAutomaticUpdates; @property (readonly, copy) NSString *installationPath; @property (readonly, copy) NSString *name; @property (readonly, copy) NSString *version; diff --git a/Sparkle/SUHost.m b/Sparkle/SUHost.m index a5c0d0ba..31d66395 100644 --- a/Sparkle/SUHost.m +++ b/Sparkle/SUHost.m @@ -67,14 +67,6 @@ return [self.bundle bundlePath]; } -// We can't determine whether or not the updater has sufficient privilleges to install automatic updates without interrupting the user -// To find that out, ask the SUUpdater which has responsibility for that -- (BOOL)allowsAutomaticUpdates -{ - NSNumber *developerAllowsAutomaticUpdates = [self objectForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey]; - return (developerAllowsAutomaticUpdates == nil || developerAllowsAutomaticUpdates.boolValue); -} - - (NSString *)installationPath { if (SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME) { diff --git a/Sparkle/SUScheduledUpdateDriver.h b/Sparkle/SUScheduledUpdateDriver.h index 183a5e61..30b780cb 100644 --- a/Sparkle/SUScheduledUpdateDriver.h +++ b/Sparkle/SUScheduledUpdateDriver.h @@ -17,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN @interface SUScheduledUpdateDriver : NSObject -- (instancetype)initWithHost:(SUHost *)host sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id )userDriver updaterDelegate:(nullable id )updaterDelegate; +- (instancetype)initWithHost:(SUHost *)host allowsAutomaticUpdates:(BOOL)allowsAutomaticUpdates sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id )userDriver updaterDelegate:(nullable id )updaterDelegate; @end diff --git a/Sparkle/SUScheduledUpdateDriver.m b/Sparkle/SUScheduledUpdateDriver.m index 6bc7483d..f35a3db8 100644 --- a/Sparkle/SUScheduledUpdateDriver.m +++ b/Sparkle/SUScheduledUpdateDriver.m @@ -26,11 +26,11 @@ @synthesize uiDriver = _uiDriver; -- (instancetype)initWithHost:(SUHost *)host sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id )userDriver updaterDelegate:(nullable id )updaterDelegate +- (instancetype)initWithHost:(SUHost *)host allowsAutomaticUpdates:(BOOL)allowsAutomaticUpdates sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id )userDriver updaterDelegate:(nullable id )updaterDelegate { self = [super init]; if (self != nil) { - _uiDriver = [[SUUIBasedUpdateDriver alloc] initWithHost:host sparkleBundle:sparkleBundle updater:updater userDriver:userDriver updaterDelegate:updaterDelegate delegate:self]; + _uiDriver = [[SUUIBasedUpdateDriver alloc] initWithHost:host allowsAutomaticUpdates:allowsAutomaticUpdates sparkleBundle:sparkleBundle updater:updater userDriver:userDriver updaterDelegate:updaterDelegate delegate:self]; } return self; } diff --git a/Sparkle/SUUIBasedUpdateDriver.h b/Sparkle/SUUIBasedUpdateDriver.h index 443352df..7a628ec4 100644 --- a/Sparkle/SUUIBasedUpdateDriver.h +++ b/Sparkle/SUUIBasedUpdateDriver.h @@ -27,7 +27,7 @@ NS_ASSUME_NONNULL_BEGIN @interface SUUIBasedUpdateDriver : NSObject -- (instancetype)initWithHost:(SUHost *)host sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id )userDriver updaterDelegate:(nullable id )updaterDelegate delegate:(id)delegate; +- (instancetype)initWithHost:(SUHost *)host allowsAutomaticUpdates:(BOOL)allowsAutomaticUpdates sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id )userDriver updaterDelegate:(nullable id )updaterDelegate delegate:(id)delegate; - (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary *)httpHeaders includesSkippedUpdates:(BOOL)includesSkippedUpdates completion:(SUUpdateDriverCompletion)completionBlock; diff --git a/Sparkle/SUUIBasedUpdateDriver.m b/Sparkle/SUUIBasedUpdateDriver.m index 64c88e5b..e904a2ed 100644 --- a/Sparkle/SUUIBasedUpdateDriver.m +++ b/Sparkle/SUUIBasedUpdateDriver.m @@ -22,6 +22,7 @@ @property (nonatomic, readonly) SUCoreBasedUpdateDriver *coreDriver; @property (nonatomic, readonly) SUHost *host; +@property (nonatomic, readonly) BOOL allowsAutomaticUpdates; @property (nonatomic, weak, readonly) id updater; @property (weak, nonatomic, readonly) id updaterDelegate; @property (nonatomic, weak, readonly) id delegate; @@ -34,13 +35,14 @@ @synthesize coreDriver = _coreDriver; @synthesize host = _host; +@synthesize allowsAutomaticUpdates = _allowsAutomaticUpdates; @synthesize updater = _updater; @synthesize updaterDelegate = _updaterDelegate; @synthesize userDriver = _userDriver; @synthesize delegate = _delegate; @synthesize resumingUpdate = _resumingUpdate; -- (instancetype)initWithHost:(SUHost *)host sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id )userDriver updaterDelegate:(nullable id )updaterDelegate delegate:(id)delegate +- (instancetype)initWithHost:(SUHost *)host allowsAutomaticUpdates:(BOOL)allowsAutomaticUpdates sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id )userDriver updaterDelegate:(nullable id )updaterDelegate delegate:(id)delegate { self = [super init]; if (self != nil) { @@ -49,6 +51,7 @@ _updater = updater; _updaterDelegate = updaterDelegate; _host = host; + _allowsAutomaticUpdates = allowsAutomaticUpdates; _coreDriver = [[SUCoreBasedUpdateDriver alloc] initWithHost:host sparkleBundle:sparkleBundle updater:updater updaterDelegate:updaterDelegate delegate:self]; } @@ -75,20 +78,13 @@ - (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem { - [self.userDriver showUpdateFoundWithAppcastItem:updateItem allowsAutomaticUpdates:[self allowsAutomaticUpdates] alreadyDownloaded:self.resumingUpdate reply:^(SUUpdateAlertChoice choice) { + [self.userDriver showUpdateFoundWithAppcastItem:updateItem allowsAutomaticUpdates:self.allowsAutomaticUpdates alreadyDownloaded:self.resumingUpdate reply:^(SUUpdateAlertChoice choice) { dispatch_async(dispatch_get_main_queue(), ^{ [self updateAlertFinishedForUpdateItem:updateItem withChoice:choice]; }); }]; } -- (BOOL)allowsAutomaticUpdates -{ - // Make sure the host allows automatic updates and - // make sure we can automatically update in the background without bugging the user (e.g, with a administrator password prompt) - return (self.host.allowsAutomaticUpdates && [[NSFileManager defaultManager] isWritableFileAtPath:self.host.bundlePath]); -} - - (void)updateAlertFinishedForUpdateItem:(SUAppcastItem *)updateItem withChoice:(SUUpdateAlertChoice)choice { [self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; diff --git a/Sparkle/SUUpdater.h b/Sparkle/SUUpdater.h index d09c672e..c53be169 100644 --- a/Sparkle/SUUpdater.h +++ b/Sparkle/SUUpdater.h @@ -68,6 +68,8 @@ SU_EXPORT @interface SUUpdater : NSObject @property BOOL sendsSystemProfile; +@property (nonatomic, readonly) BOOL allowsAutomaticUpdates; + @property BOOL automaticallyDownloadsUpdates; /*! diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 412a1136..5d32eef2 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -296,8 +296,7 @@ static void SUCheckForUpdatesInBgReachabilityCheck(__weak SUUpdater *updater, id // hour or so: id updateDriver; - BOOL inProgress = [SUProbeInstallStatus probeInstallerInProgressForHost:self.host]; - if ([self automaticallyDownloadsUpdates] && !inProgress) { + if ([self automaticallyDownloadsUpdates] && [self allowsAutomaticUpdates] && ![SUProbeInstallStatus probeInstallerInProgressForHost:self.host]) { updateDriver = [[SUAutomaticUpdateDriver alloc] initWithHost:self.host @@ -308,6 +307,7 @@ static void SUCheckForUpdatesInBgReachabilityCheck(__weak SUUpdater *updater, id updateDriver = [[SUScheduledUpdateDriver alloc] initWithHost:self.host + allowsAutomaticUpdates:[self allowsAutomaticUpdates] sparkleBundle:self.sparkleBundle updater:self userDriver:self.userDriver @@ -330,7 +330,7 @@ static void SUCheckForUpdatesInBgReachabilityCheck(__weak SUUpdater *updater, id return; } - id theUpdateDriver = [[SUUserInitiatedUpdateDriver alloc] initWithHost:self.host sparkleBundle:self.sparkleBundle updater:self userDriver:self.userDriver updaterDelegate:self.delegate]; + id theUpdateDriver = [[SUUserInitiatedUpdateDriver alloc] initWithHost:self.host allowsAutomaticUpdates:[self allowsAutomaticUpdates] sparkleBundle:self.sparkleBundle updater:self userDriver:self.userDriver updaterDelegate:self.delegate]; [self checkForUpdatesWithDriver:theUpdateDriver]; } @@ -441,20 +441,15 @@ static void SUCheckForUpdatesInBgReachabilityCheck(__weak SUUpdater *updater, id - (BOOL)automaticallyDownloadsUpdates { - // If the host doesn't allow automatic updates, don't ever let them happen - if (!self.host.allowsAutomaticUpdates) { - return NO; - } - - // Can we automatically update in the background without bugging the user (e.g, with a administrator password prompt)? - if (![[NSFileManager defaultManager] isWritableFileAtPath:self.host.bundlePath]) { - return NO; - } - - // Otherwise, automatically downloading updates is allowed. Does the user want it? return [self.host boolForUserDefaultsKey:SUAutomaticallyUpdateKey]; } +- (BOOL)allowsAutomaticUpdates +{ + NSNumber *developerAllowsAutomaticUpdates = [self.host objectForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey]; + return (developerAllowsAutomaticUpdates == nil || developerAllowsAutomaticUpdates.boolValue) && [[NSFileManager defaultManager] isWritableFileAtPath:self.host.bundlePath]; +} + - (void)setFeedURL:(NSURL *)feedURL { if (![NSThread isMainThread]) diff --git a/Sparkle/SUUserInitiatedUpdateDriver.h b/Sparkle/SUUserInitiatedUpdateDriver.h index ca24c1a8..4349b539 100644 --- a/Sparkle/SUUserInitiatedUpdateDriver.h +++ b/Sparkle/SUUserInitiatedUpdateDriver.h @@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN @interface SUUserInitiatedUpdateDriver : NSObject -- (instancetype)initWithHost:(SUHost *)host sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id )userDriver updaterDelegate:(nullable id )updaterDelegate; +- (instancetype)initWithHost:(SUHost *)host allowsAutomaticUpdates:(BOOL)allowsAutomaticUpdates sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id )userDriver updaterDelegate:(nullable id )updaterDelegate; @end diff --git a/Sparkle/SUUserInitiatedUpdateDriver.m b/Sparkle/SUUserInitiatedUpdateDriver.m index 6d743af2..637895a5 100644 --- a/Sparkle/SUUserInitiatedUpdateDriver.m +++ b/Sparkle/SUUserInitiatedUpdateDriver.m @@ -28,11 +28,11 @@ @synthesize userDriver = _userDriver; @synthesize canceledCheckForUpdates = _canceledCheckForUpdates; -- (instancetype)initWithHost:(SUHost *)host sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id )userDriver updaterDelegate:(nullable id )updaterDelegate +- (instancetype)initWithHost:(SUHost *)host allowsAutomaticUpdates:(BOOL)allowsAutomaticUpdates sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id )userDriver updaterDelegate:(nullable id )updaterDelegate { self = [super init]; if (self != nil) { - _uiDriver = [[SUUIBasedUpdateDriver alloc] initWithHost:host sparkleBundle:sparkleBundle updater:updater userDriver:userDriver updaterDelegate:updaterDelegate delegate:self]; + _uiDriver = [[SUUIBasedUpdateDriver alloc] initWithHost:host allowsAutomaticUpdates:allowsAutomaticUpdates sparkleBundle:sparkleBundle updater:updater userDriver:userDriver updaterDelegate:updaterDelegate delegate:self]; _userDriver = userDriver; } return self;