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
This commit is contained in:
Zorg committed 2015-09-26 20:56:44 -04:00
1 parent e17d4fc99f
commit 6079739534
4 files changed
+25 -7

No files matched your search

+1
View File
@@ -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;
+11
View File
@@ -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);
+11 -5
View File
@@ -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];
}
+2 -2
View File
@@ -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;
}