From 005392963f21e8a8404e5c5b08dd7f9b8908443b Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 16 Sep 2022 20:41:08 -0700 Subject: [PATCH] Allow developer to always force allowing automatic updates (#2266) By default, if the SUAllowsAutomaticUpdates Info.plist key is not specified, the update alert option to allow automatic downloading/installing of updates will only be shown if automatic checking of updates is enabled. However, the developer can now override this by setting SUAllowsAutomaticUpdates to true in Info.plist which indicates the option should be available even if automatic checking of updates is not enabled. --- Sparkle/SPUUpdaterSettings.h | 6 ++++++ Sparkle/SPUUpdaterSettings.m | 8 +++++++- Sparkle/SUUpdateAlert.m | 13 ++++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Sparkle/SPUUpdaterSettings.h b/Sparkle/SPUUpdaterSettings.h index e2969b66..a480a42a 100644 --- a/Sparkle/SPUUpdaterSettings.h +++ b/Sparkle/SPUUpdaterSettings.h @@ -31,6 +31,12 @@ SU_EXPORT @interface SPUUpdaterSettings : NSObject */ @property (readonly, nonatomic) NSTimeInterval updateCheckInterval; +/** + * Indicates whether or not automatically downloading updates is allowed to be turned on by the user. + * If this value is nil, the developer has not explicitly specified this option. + */ +@property (readonly, nonatomic, nullable) NSNumber *allowsAutomaticUpdatesOption; + /** * Indicates whether or not automatically downloading updates is allowed to be turned on by the user. */ diff --git a/Sparkle/SPUUpdaterSettings.m b/Sparkle/SPUUpdaterSettings.m index 9e5deeb2..691231d2 100644 --- a/Sparkle/SPUUpdaterSettings.m +++ b/Sparkle/SPUUpdaterSettings.m @@ -52,9 +52,15 @@ } // For allowing automatic downloaded updates to be turned on or off -- (BOOL)allowsAutomaticUpdates +- (NSNumber * _Nullable)allowsAutomaticUpdatesOption { NSNumber *developerAllowsAutomaticUpdates = [self.host objectForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey]; + return [developerAllowsAutomaticUpdates isKindOfClass:[NSNumber class]] ? developerAllowsAutomaticUpdates : nil; +} + +- (BOOL)allowsAutomaticUpdates +{ + NSNumber *developerAllowsAutomaticUpdates = [self allowsAutomaticUpdatesOption]; return (developerAllowsAutomaticUpdates == nil || developerAllowsAutomaticUpdates.boolValue); } diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index da170e78..96d32158 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -98,7 +98,18 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE _didBecomeKeyBlock = [didBecomeKeyBlock copy]; SPUUpdaterSettings *updaterSettings = [[SPUUpdaterSettings alloc] initWithHostBundle:host.bundle]; - _allowsAutomaticUpdates = updaterSettings.allowsAutomaticUpdates && updaterSettings.automaticallyChecksForUpdates && !item.informationOnlyUpdate; + + BOOL allowsAutomaticUpdates; + NSNumber *allowsAutomaticUpdatesOption = updaterSettings.allowsAutomaticUpdatesOption; + if (item.informationOnlyUpdate) { + allowsAutomaticUpdates = NO; + } else if (allowsAutomaticUpdatesOption == nil) { + allowsAutomaticUpdates = updaterSettings.automaticallyChecksForUpdates; + } else { + allowsAutomaticUpdates = allowsAutomaticUpdatesOption.boolValue; + } + _allowsAutomaticUpdates = allowsAutomaticUpdates; + [self setShouldCascadeWindows:NO]; } else { assert(false);