Merge pull request #1735 from sparkle-project/prevent-autoupdate-2x

Port preventing new version from being auto installed to 2.x
This commit is contained in:
Mayur Pawashe authored and GitHub committed 2021-01-24 10:16:42 -08:00
commit 6da14f7c46
16 files changed
+41 -22

No files matched your search

+3 -3
View File
@@ -77,12 +77,12 @@
SULog(SULogLevelError, @"Error: resumeDownloadedUpdate:completion: called on SPUAutomaticUpdateDriver");
}
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate
{
self.updateItem = updateItem;
if (updateItem.isInformationOnlyUpdate) {
[self.coreDriver deferInformationalUpdate:updateItem];
if (updateItem.isInformationOnlyUpdate || preventsAutoupdate) {
[self.coreDriver deferInformationalUpdate:updateItem preventsAutoupdate:preventsAutoupdate];
[self abortUpdate];
} else {
[self.coreDriver downloadUpdateFromAppcastItem:updateItem inBackground:YES];
+1 -1
View File
@@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
@protocol SPUBasicUpdateDriverDelegate <NSObject>
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)appcastItem;
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)appcastItem preventsAutoupdate:(BOOL)preventsAutoupdate;
- (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error;
+3 -3
View File
@@ -87,7 +87,7 @@
[self notifyFinishLoadingAppcast];
SUAppcastItem *nonNullUpdateItem = updateItem;
[self didFindValidUpdateWithAppcastItem:nonNullUpdateItem];
[self didFindValidUpdateWithAppcastItem:nonNullUpdateItem preventsAutoupdate:NO];
}
}
@@ -141,7 +141,7 @@
}
}
- (void)didFindValidUpdateWithAppcastItem:(SUAppcastItem *)updateItem
- (void)didFindValidUpdateWithAppcastItem:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate
{
if (!self.aborted) {
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFindValidUpdateNotification
@@ -152,7 +152,7 @@
[self.updaterDelegate updater:self.updater didFindValidUpdate:updateItem];
}
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem];
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem preventsAutoupdate:preventsAutoupdate];
}
}
+2 -2
View File
@@ -17,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
@protocol SPUCoreBasedUpdateDriverDelegate <NSObject>
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem;
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate;
- (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately silently:(BOOL)willInstallSilently;
@@ -63,7 +63,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)downloadUpdateFromAppcastItem:(SUAppcastItem *)updateItem inBackground:(BOOL)background;
- (void)deferInformationalUpdate:(SUAppcastItem *)updateItem;
- (void)deferInformationalUpdate:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate;
- (void)extractDownloadedUpdate;
+6 -6
View File
@@ -141,24 +141,24 @@
}
}
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate
{
self.updateItem = updateItem;
if (self.resumingInstallingUpdate) {
[self.installerDriver resumeInstallingUpdateWithUpdateItem:updateItem];
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem];
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem preventsAutoupdate:preventsAutoupdate];
} else {
if (!self.preventsInstallerInteraction) {
// Simple case - delegate allows interaction, so we should continue along
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem];
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem preventsAutoupdate:preventsAutoupdate];
} else {
// Package type installations will always require installer interaction as long as we don't support running as root
// If it's not a package type installation, we should be okay since we did an auth check before checking for updates above
if (![updateItem.installationType isEqualToString:SPUInstallationTypeApplication]) {
[self.delegate coreDriverIsRequestingAbortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUNotAllowedInteractionError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:SULocalizedString(@"A new update is available but cannot be installed because interaction has been prevented.", nil)] }]];
} else {
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem];
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem preventsAutoupdate:preventsAutoupdate];
}
}
}
@@ -204,9 +204,9 @@
[self extractUpdate:downloadedUpdate];
}
- (void)deferInformationalUpdate:(SUAppcastItem *)updateItem
- (void)deferInformationalUpdate:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate
{
self.resumableUpdate = [[SPUInformationalUpdate alloc] initWithAppcastItem:updateItem];
self.resumableUpdate = [[SPUInformationalUpdate alloc] initWithAppcastItem:updateItem preventsAutoupdate:preventsAutoupdate];
}
- (void)extractDownloadedUpdate
+1 -1
View File
@@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface SPUInformationalUpdate : NSObject <SPUResumableUpdate>
- (instancetype)initWithAppcastItem:(SUAppcastItem *)updateItem;
- (instancetype)initWithAppcastItem:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate;
@end
+3 -1
View File
@@ -16,12 +16,14 @@
// If we ever enable auto-synthesize in the future, we'll still need this synthesize
// because the property is declared in a protocol
@synthesize updateItem = _updateItem;
@synthesize preventsAutoupdate = _preventsAutoupdate;
- (instancetype)initWithAppcastItem:(SUAppcastItem *)updateItem
- (instancetype)initWithAppcastItem:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate
{
self = [super init];
if (self != nil) {
_updateItem = updateItem;
_preventsAutoupdate = preventsAutoupdate;
}
return self;
}
+1 -1
View File
@@ -54,7 +54,7 @@
[self.basicDriver resumeUpdate:resumableUpdate completion:completionBlock];
}
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)__unused appcastItem
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)__unused appcastItem preventsAutoupdate:(BOOL)__unused preventsAutoupdate
{
// Stop as soon as we have an answer
[self abortUpdate];
+1
View File
@@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
@protocol SPUResumableUpdate <NSObject>
@property (nonatomic, readonly) SUAppcastItem *updateItem;
@property (nonatomic, readonly) BOOL preventsAutoupdate;
@end
+3 -2
View File
@@ -91,7 +91,8 @@
- (void)resumeUpdate:(id<SPUResumableUpdate>)resumableUpdate completion:(SPUUpdateDriverCompletion)completionBlock
{
// Informational downloads shouldn't be presented as updates to be downloaded
if (!resumableUpdate.updateItem.isInformationOnlyUpdate) {
// Neither should items that prevent auto updating
if (!resumableUpdate.updateItem.isInformationOnlyUpdate && !resumableUpdate.preventsAutoupdate) {
self.resumingDownloadedUpdate = YES;
}
[self.coreDriver resumeUpdate:resumableUpdate completion:completionBlock];
@@ -104,7 +105,7 @@
}
}
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate
{
if (updateItem.isInformationOnlyUpdate) {
assert(!self.resumingDownloadedUpdate);
+1 -1
View File
@@ -17,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)didFailToFetchAppcastWithError:(NSError *)error;
- (void)didFinishLoadingAppcast:(SUAppcast *)appcast;
- (void)didFindValidUpdateWithAppcastItem:(SUAppcastItem *)appcastItem;
- (void)didFindValidUpdateWithAppcastItem:(SUAppcastItem *)appcastItem preventsAutoupdate:(BOOL)preventsAutoupdate;
- (void)didNotFindUpdate;
@end
+6 -1
View File
@@ -104,7 +104,7 @@
if ([self itemContainsValidUpdate:item includesSkippedUpdates:includesSkippedUpdates]) {
self.nonDeltaUpdateItem = nonDeltaUpdateItem;
[self.delegate didFindValidUpdateWithAppcastItem:item];
[self.delegate didFindValidUpdateWithAppcastItem:item preventsAutoupdate:[self itemPreventsAutoupdate:item]];
} else {
[self.delegate didNotFindUpdate];
}
@@ -177,6 +177,11 @@
return [[self versionComparator] compareVersion:[self.host version] toVersion:[ui versionString]] == NSOrderedAscending;
}
- (BOOL)itemPreventsAutoupdate:(SUAppcastItem *)ui
{
return ([ui minimumAutoupdateVersion] && ! [[ui minimumAutoupdateVersion] isEqualToString:@""] && ([[self versionComparator] compareVersion:[self.host version] toVersion:[ui minimumAutoupdateVersion]] == NSOrderedAscending));
}
- (BOOL)itemContainsSkippedVersion:(SUAppcastItem *)ui
{
NSString *skippedVersion = [self.host objectForUserDefaultsKey:SUSkippedVersionKey];
+1
View File
@@ -36,6 +36,7 @@ SU_EXPORT @interface SUAppcastItem : NSObject<NSSecureCoding>
@property (copy, readonly) NSDictionary *deltaUpdates;
@property (strong, readonly) NSURL *infoURL;
@property (nonatomic, copy, readonly) NSString *installationType;
@property (copy, readonly) NSString *minimumAutoupdateVersion;
// Initializes with data from a dictionary provided by the RSS class.
- (instancetype)initWithDictionary:(NSDictionary *)dict;
+7
View File
@@ -49,6 +49,7 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT
@synthesize osString = _osString;
@synthesize propertiesDictionary = _propertiesDictionary;
@synthesize installationType = _installationType;
@synthesize minimumAutoupdateVersion = _minimumAutoupdateVersion;
+ (BOOL)supportsSecureCoding
{
@@ -76,6 +77,7 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT
_itemDescription = [(NSString *)[decoder decodeObjectOfClass:[NSString class] forKey:SUAppcastItemDescriptionKey] copy];
_maximumSystemVersion = [(NSString *)[decoder decodeObjectOfClass:[NSString class] forKey:SUAppcastItemMaximumSystemVersionKey] copy];
_minimumSystemVersion = [(NSString *)[decoder decodeObjectOfClass:[NSString class] forKey:SUAppcastItemMinimumSystemVersionKey] copy];
_minimumAutoupdateVersion = [(NSString *)[decoder decodeObjectOfClass:[NSString class] forKey:SUAppcastElementMinimumAutoupdateVersion] copy];
_releaseNotesURL = [decoder decodeObjectOfClass:[NSURL class] forKey:SUAppcastItemReleaseNotesURLKey];
_title = [(NSString *)[decoder decodeObjectOfClass:[NSString class] forKey:SUAppcastItemTitleKey] copy];
_versionString = [(NSString *)[decoder decodeObjectOfClass:[NSString class] forKey:SUAppcastItemVersionStringKey] copy];
@@ -122,6 +124,10 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT
[encoder encodeObject:self.minimumSystemVersion forKey:SUAppcastItemMinimumSystemVersionKey];
}
if (self.minimumAutoupdateVersion != nil) {
[encoder encodeObject:self.minimumAutoupdateVersion forKey:SUAppcastElementMinimumAutoupdateVersion];
}
if (self.releaseNotesURL != nil) {
[encoder encodeObject:self.releaseNotesURL forKey:SUAppcastItemReleaseNotesURLKey];
}
@@ -268,6 +274,7 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT
_versionString = [(NSString *)newVersion copy];
_minimumSystemVersion = [(NSString *)[dict objectForKey:SUAppcastElementMinimumSystemVersion] copy];
_maximumSystemVersion = [(NSString *)[dict objectForKey:SUAppcastElementMaximumSystemVersion] copy];
_minimumAutoupdateVersion = [(NSString *)[dict objectForKey:SUAppcastElementMinimumAutoupdateVersion] copy];
NSString *shortVersionString = [enclosure objectForKey:SUAppcastAttributeShortVersionString];
if (nil == shortVersionString) {
+1
View File
@@ -76,6 +76,7 @@ extern NSString *const SUAppcastAttributeInstallationType;
extern NSString *const SUAppcastElementCriticalUpdate;
extern NSString *const SUAppcastElementDeltas;
extern NSString *const SUAppcastElementMinimumAutoupdateVersion;
extern NSString *const SUAppcastElementMinimumSystemVersion;
extern NSString *const SUAppcastElementMaximumSystemVersion;
extern NSString *const SUAppcastElementReleaseNotesLink;
+1
View File
@@ -69,6 +69,7 @@ NSString *const SUAppcastAttributeInstallationType = @"sparkle:installationType"
NSString *const SUAppcastElementCriticalUpdate = @"sparkle:criticalUpdate";
NSString *const SUAppcastElementDeltas = @"sparkle:deltas";
NSString *const SUAppcastElementMinimumAutoupdateVersion = @"sparkle:minimumAutoupdateVersion";
NSString *const SUAppcastElementMinimumSystemVersion = @"sparkle:minimumSystemVersion";
NSString *const SUAppcastElementMaximumSystemVersion = @"sparkle:maximumSystemVersion";
NSString *const SUAppcastElementReleaseNotesLink = @"sparkle:releaseNotesLink";