Move automatic updates property from SUHost into SUUpdater

SUHost cannot properly detect if automatic updates are allowed due to write permissions,
thus it should not be a property of SUHost at all.
This commit is contained in:
Zorg committed 2016-03-27 13:33:28 -04:00
1 parent 9c7d41dd90
commit 7fc6896170
10 files changed
+23 -40

No files matched your search

-2
View File
@@ -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;
-8
View File
@@ -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) {
+1 -1
View File
@@ -17,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface SUScheduledUpdateDriver : NSObject <SUUpdateDriver>
- (instancetype)initWithHost:(SUHost *)host sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id <SUUserDriver>)userDriver updaterDelegate:(nullable id <SUUpdaterDelegate>)updaterDelegate;
- (instancetype)initWithHost:(SUHost *)host allowsAutomaticUpdates:(BOOL)allowsAutomaticUpdates sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id <SUUserDriver>)userDriver updaterDelegate:(nullable id <SUUpdaterDelegate>)updaterDelegate;
@end
+2 -2
View File
@@ -26,11 +26,11 @@
@synthesize uiDriver = _uiDriver;
- (instancetype)initWithHost:(SUHost *)host sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id <SUUserDriver>)userDriver updaterDelegate:(nullable id <SUUpdaterDelegate>)updaterDelegate
- (instancetype)initWithHost:(SUHost *)host allowsAutomaticUpdates:(BOOL)allowsAutomaticUpdates sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id <SUUserDriver>)userDriver updaterDelegate:(nullable id <SUUpdaterDelegate>)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;
}
+1 -1
View File
@@ -27,7 +27,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface SUUIBasedUpdateDriver : NSObject
- (instancetype)initWithHost:(SUHost *)host sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id <SUUserDriver>)userDriver updaterDelegate:(nullable id <SUUpdaterDelegate>)updaterDelegate delegate:(id<SUUIBasedUpdateDriverDelegate>)delegate;
- (instancetype)initWithHost:(SUHost *)host allowsAutomaticUpdates:(BOOL)allowsAutomaticUpdates sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id <SUUserDriver>)userDriver updaterDelegate:(nullable id <SUUpdaterDelegate>)updaterDelegate delegate:(id<SUUIBasedUpdateDriverDelegate>)delegate;
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary *)httpHeaders includesSkippedUpdates:(BOOL)includesSkippedUpdates completion:(SUUpdateDriverCompletion)completionBlock;
+5 -9
View File
@@ -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<SUUpdaterDelegate> updaterDelegate;
@property (nonatomic, weak, readonly) id<SUUIBasedUpdateDriverDelegate> 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 <SUUserDriver>)userDriver updaterDelegate:(nullable id <SUUpdaterDelegate>)updaterDelegate delegate:(id<SUUIBasedUpdateDriverDelegate>)delegate
- (instancetype)initWithHost:(SUHost *)host allowsAutomaticUpdates:(BOOL)allowsAutomaticUpdates sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id <SUUserDriver>)userDriver updaterDelegate:(nullable id <SUUpdaterDelegate>)updaterDelegate delegate:(id<SUUIBasedUpdateDriverDelegate>)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];
+2
View File
@@ -68,6 +68,8 @@ SU_EXPORT @interface SUUpdater : NSObject
@property BOOL sendsSystemProfile;
@property (nonatomic, readonly) BOOL allowsAutomaticUpdates;
@property BOOL automaticallyDownloadsUpdates;
/*!
+9 -14
View File
@@ -296,8 +296,7 @@ static void SUCheckForUpdatesInBgReachabilityCheck(__weak SUUpdater *updater, id
// hour or so:
id <SUUpdateDriver> 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 <SUUpdateDriver> theUpdateDriver = [[SUUserInitiatedUpdateDriver alloc] initWithHost:self.host sparkleBundle:self.sparkleBundle updater:self userDriver:self.userDriver updaterDelegate:self.delegate];
id <SUUpdateDriver> 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])
+1 -1
View File
@@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface SUUserInitiatedUpdateDriver : NSObject <SUUpdateDriver>
- (instancetype)initWithHost:(SUHost *)host sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id <SUUserDriver>)userDriver updaterDelegate:(nullable id <SUUpdaterDelegate>)updaterDelegate;
- (instancetype)initWithHost:(SUHost *)host allowsAutomaticUpdates:(BOOL)allowsAutomaticUpdates sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id <SUUserDriver>)userDriver updaterDelegate:(nullable id <SUUpdaterDelegate>)updaterDelegate;
@end
+2 -2
View File
@@ -28,11 +28,11 @@
@synthesize userDriver = _userDriver;
@synthesize canceledCheckForUpdates = _canceledCheckForUpdates;
- (instancetype)initWithHost:(SUHost *)host sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id <SUUserDriver>)userDriver updaterDelegate:(nullable id <SUUpdaterDelegate>)updaterDelegate
- (instancetype)initWithHost:(SUHost *)host allowsAutomaticUpdates:(BOOL)allowsAutomaticUpdates sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id <SUUserDriver>)userDriver updaterDelegate:(nullable id <SUUpdaterDelegate>)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;