From 6079739534895659dda4d9391ed85e62ef7bf252 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 26 Sep 2015 20:56:44 -0400 Subject: [PATCH 1/2] Disallow automatic updates when user can't write to the bundle The automatic updates checkbox is also hidden in this scenario, and we also update the layout constraints if the releasenotes are still visible --- Sparkle/SUHost.h | 1 + Sparkle/SUHost.m | 11 +++++++++++ Sparkle/SUUpdateAlert.m | 16 +++++++++++----- Sparkle/SUUpdater.m | 4 ++-- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Sparkle/SUHost.h b/Sparkle/SUHost.h index 3bf0a8e5..732eae28 100644 --- a/Sparkle/SUHost.h +++ b/Sparkle/SUHost.h @@ -28,6 +28,7 @@ typedef struct { - (instancetype)initWithBundle:(NSBundle *)aBundle; @property (readonly, copy) NSString *bundlePath; +@property (readonly) BOOL allowsAutomaticUpdates; @property (readonly, copy) NSString *appCachePath; @property (readonly, copy) NSString *installationPath; @property (readonly, copy) NSString *name; diff --git a/Sparkle/SUHost.m b/Sparkle/SUHost.m index 6f9e7da1..549a7bbe 100644 --- a/Sparkle/SUHost.m +++ b/Sparkle/SUHost.m @@ -62,6 +62,17 @@ return [self.bundle bundlePath]; } +- (BOOL)allowsAutomaticUpdates +{ + // Can we automatically update in the background without bugging the user (e.g, with a administrator password prompt)? + BOOL isWritableAtBundle = [[NSFileManager defaultManager] isWritableFileAtPath:self.bundlePath]; + + // Does the developer want us to disable automatic updates? + NSNumber *developerAllowsAutomaticUpdates = [self objectForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey]; + + return isWritableAtBundle && (developerAllowsAutomaticUpdates == nil || developerAllowsAutomaticUpdates.boolValue); +} + - (NSString *)appCachePath { NSArray *cachePaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index 1ab5eed2..42565b00 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -171,11 +171,7 @@ - (BOOL)allowsAutomaticUpdates { - BOOL allowAutoUpdates = YES; // Defaults to YES. - if ([self.host objectForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey]) - allowAutoUpdates = [self.host boolForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey]; - - return allowAutoUpdates; + return self.host.allowsAutomaticUpdates; } - (void)windowDidLoad @@ -202,6 +198,16 @@ [self.releaseNotesContainerView removeFromSuperview]; } + + // When we show release notes, it looks ugly if the install buttons are not closer to the release notes view + // However when we don't show release notes, it looks ugly if the install buttons are too close to the description field. Shrugs. + if (showReleaseNotes && ![self allowsAutomaticUpdates]) { + NSLayoutConstraint *skipButtonToReleaseNotesContainerConstraint = [NSLayoutConstraint constraintWithItem:self.skipButton attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.releaseNotesContainerView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:12.0]; + + [self.window.contentView addConstraint:skipButtonToReleaseNotesContainerConstraint]; + + [self.automaticallyInstallUpdatesButton removeFromSuperview]; + } [self.window center]; } diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 73ebafea..7a824f3c 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -435,8 +435,8 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults - (BOOL)automaticallyDownloadsUpdates { - // If the SUAllowsAutomaticUpdatesKey exists and is set to NO, return NO. - if ([self.host objectForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey] && [self.host boolForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey] == NO) { + // If the host doesn't allow automatic updates, don't ever let them happen + if (!self.host.allowsAutomaticUpdates) { return NO; } From a7ff41b3ceabead3697351840f1b4c2b21ae7fa3 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 26 Sep 2015 21:10:09 -0400 Subject: [PATCH 2/2] If the developer disables automatic updating, don't check writability --- Sparkle/SUHost.m | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Sparkle/SUHost.m b/Sparkle/SUHost.m index 549a7bbe..6ce40fbb 100644 --- a/Sparkle/SUHost.m +++ b/Sparkle/SUHost.m @@ -64,13 +64,14 @@ - (BOOL)allowsAutomaticUpdates { - // Can we automatically update in the background without bugging the user (e.g, with a administrator password prompt)? - BOOL isWritableAtBundle = [[NSFileManager defaultManager] isWritableFileAtPath:self.bundlePath]; - // Does the developer want us to disable automatic updates? NSNumber *developerAllowsAutomaticUpdates = [self objectForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey]; + if (developerAllowsAutomaticUpdates != nil && !developerAllowsAutomaticUpdates.boolValue) { + return NO; + } - return isWritableAtBundle && (developerAllowsAutomaticUpdates == nil || developerAllowsAutomaticUpdates.boolValue); + // Can we automatically update in the background without bugging the user (e.g, with a administrator password prompt)? + return [[NSFileManager defaultManager] isWritableFileAtPath:self.bundlePath]; } - (NSString *)appCachePath