diff --git a/Sparkle/SUHost.h b/Sparkle/SUHost.h index 5433bad1..7ef4836b 100644 --- a/Sparkle/SUHost.h +++ b/Sparkle/SUHost.h @@ -13,6 +13,7 @@ - (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 *appCachePath; @property (readonly, copy) NSString *installationPath; diff --git a/Sparkle/SUHost.m b/Sparkle/SUHost.m index 8b9b81ff..827f0103 100644 --- a/Sparkle/SUHost.m +++ b/Sparkle/SUHost.m @@ -18,6 +18,10 @@ #error This is a "core" class and should NOT import AppKit #endif +// This class should also be process independent +// For example, it should not have code that tests writabilty to somewhere on disk, +// as that may depend on the privileges of the process owner + @interface SUHost () @property (strong, readwrite) NSBundle *bundle; @@ -62,16 +66,12 @@ 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 { - // Does the developer want us to disable automatic updates? NSNumber *developerAllowsAutomaticUpdates = [self objectForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey]; - if (developerAllowsAutomaticUpdates != nil && !developerAllowsAutomaticUpdates.boolValue) { - return NO; - } - - // Can we automatically update in the background without bugging the user (e.g, with a administrator password prompt)? - return [[NSFileManager defaultManager] isWritableFileAtPath:self.bundlePath]; + return (developerAllowsAutomaticUpdates == nil || developerAllowsAutomaticUpdates.boolValue); } - (NSString *)appCachePath diff --git a/Sparkle/SUSparkleUserUpdaterDriver.m b/Sparkle/SUSparkleUserUpdaterDriver.m index 1122f938..1328ff9f 100644 --- a/Sparkle/SUSparkleUserUpdaterDriver.m +++ b/Sparkle/SUSparkleUserUpdaterDriver.m @@ -200,11 +200,11 @@ #pragma mark Update Found -- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem versionDisplayer:(id)versionDisplayer reply:(void (^)(SUUpdateAlertChoice))reply +- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem versionDisplayer:(id)versionDisplayer allowsAutomaticUpdates:(BOOL)allowsAutomaticUpdates reply:(void (^)(SUUpdateAlertChoice))reply { dispatch_async(dispatch_get_main_queue(), ^{ __weak SUSparkleUserUpdaterDriver *weakSelf = self; - SUUpdateAlert *updateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:appcastItem host:self.host completionBlock:^(SUUpdateAlertChoice choice) { + SUUpdateAlert *updateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:appcastItem host:self.host allowsAutomaticUpdates:allowsAutomaticUpdates completionBlock:^(SUUpdateAlertChoice choice) { reply(choice); weakSelf.activeUpdateAlert = nil; }]; diff --git a/Sparkle/SUUIBasedUpdateDriver.m b/Sparkle/SUUIBasedUpdateDriver.m index bd83d897..1dadae9c 100644 --- a/Sparkle/SUUIBasedUpdateDriver.m +++ b/Sparkle/SUUIBasedUpdateDriver.m @@ -44,7 +44,7 @@ versDisp = [[self.updater delegate] versionDisplayerForUpdater:self.updater]; } - [self.updater.userUpdaterDriver showUpdateFoundWithAppcastItem:self.updateItem versionDisplayer:versDisp reply:^(SUUpdateAlertChoice choice) { + [self.updater.userUpdaterDriver showUpdateFoundWithAppcastItem:self.updateItem versionDisplayer:versDisp allowsAutomaticUpdates:self.updater.allowsAutomaticUpdates reply:^(SUUpdateAlertChoice choice) { dispatch_async(dispatch_get_main_queue(), ^{ [self updateAlertFinishedWithChoice:choice]; }); diff --git a/Sparkle/SUUpdateAlert.h b/Sparkle/SUUpdateAlert.h index 202a94e9..d6ccda23 100644 --- a/Sparkle/SUUpdateAlert.h +++ b/Sparkle/SUUpdateAlert.h @@ -20,7 +20,7 @@ @property (weak) id versionDisplayer; -- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)host completionBlock:(void(^)(SUUpdateAlertChoice))c; +- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)host allowsAutomaticUpdates:(BOOL)allowsAutomaticUpdates completionBlock:(void(^)(SUUpdateAlertChoice))c; - (IBAction)installUpdate:sender; - (IBAction)skipThisVersion:sender; diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index d277247e..3863d8df 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -34,6 +34,7 @@ @property (strong) SUAppcastItem *updateItem; @property (strong) SUHost *host; +@property (nonatomic) BOOL allowsAutomaticUpdates; @property (strong) void(^completionBlock)(SUUpdateAlertChoice); @property (strong) NSProgressIndicator *releaseNotesSpinner; @@ -56,6 +57,7 @@ @synthesize updateItem; @synthesize host; +@synthesize allowsAutomaticUpdates = _allowsAutomaticUpdates; @synthesize releaseNotesSpinner; @synthesize webViewFinishedLoading; @@ -68,7 +70,7 @@ @synthesize skipButton; @synthesize laterButton; -- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost completionBlock:(void (^)(SUUpdateAlertChoice))block +- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost allowsAutomaticUpdates:(BOOL)allowsAutomaticUpdates completionBlock:(void (^)(SUUpdateAlertChoice))block { self = [super initWithWindowNibName:@"SUUpdateAlert"]; if (self) @@ -76,6 +78,7 @@ self.completionBlock = block; host = aHost; updateItem = item; + _allowsAutomaticUpdates = allowsAutomaticUpdates; [self setShouldCascadeWindows:NO]; // Alex: This dummy line makes sure that the binary is linked against WebKit. @@ -170,11 +173,6 @@ return [shouldShowReleaseNotes boolValue]; } -- (BOOL)allowsAutomaticUpdates -{ - return self.host.allowsAutomaticUpdates; -} - - (void)windowDidLoad { BOOL showReleaseNotes = [self showsReleaseNotes]; diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 0e1a2f40..445aa305 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -401,11 +401,23 @@ static void SUCheckForUpdatesInBgReachabilityCheck(__weak SUUpdater *updater, SU 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 +{ + // 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)setFeedURL:(NSURL *)feedURL { if (![NSThread isMainThread]) diff --git a/Sparkle/SUUpdater_Private.h b/Sparkle/SUUpdater_Private.h index 40091549..d055b2d6 100644 --- a/Sparkle/SUUpdater_Private.h +++ b/Sparkle/SUUpdater_Private.h @@ -12,4 +12,6 @@ @property (readonly) BOOL mayUpdateAndRestart; +@property (readonly, nonatomic) BOOL allowsAutomaticUpdates; + @end diff --git a/Sparkle/SUUserUpdaterDriver.h b/Sparkle/SUUserUpdaterDriver.h index 726e2484..74aee2b2 100644 --- a/Sparkle/SUUserUpdaterDriver.h +++ b/Sparkle/SUUserUpdaterDriver.h @@ -27,7 +27,7 @@ - (void)showUserInitiatedUpdateCheckWithCompletion:(void (^)(SUUserInitiatedCheckStatus))updateCheckStatusCompletion; - (void)dismissUserInitiatedUpdateCheck; -- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem versionDisplayer:(id)versionDisplayer reply:(void (^)(SUUpdateAlertChoice))reply; +- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem versionDisplayer:(id)versionDisplayer allowsAutomaticUpdates:(BOOL)allowsAutomaticUpdates reply:(void (^)(SUUpdateAlertChoice))reply; #warning maybe this should take a versionDisplayer too? - (void)showAutomaticUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem reply:(void (^)(SUAutomaticInstallationChoice))reply;