Add user driver method to show informational only updates

This will increase the chance of a user driver implementing being able to show informational only updates. Also it's better to use a new method rather than re-use another existing one inappropriately.
This commit is contained in:
Zorg committed 2017-01-02 18:00:17 -05:00
1 parent c25f127188
commit dca2114934
8 files changed
+99 -8

No files matched your search

+10
View File
@@ -157,6 +157,16 @@
}];
}
- (void)showInformationalUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)__unused userInitiated reply:(void (^)(SPUInformationalUpdateAlertChoice))reply
{
[self showUpdateFoundWithAlertHandler:^SUUpdateAlert *(SPUStandardUserDriver *weakSelf, SUHost *host, id<SUVersionDisplay> versionDisplayer) {
return [[SUUpdateAlert alloc] initWithAppcastItem:appcastItem host:host versionDisplayer:versionDisplayer informationalCompletionBlock:^(SPUInformationalUpdateAlertChoice choice) {
reply(choice);
weakSelf.activeUpdateAlert = nil;
}];
}];
}
- (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData
{
dispatch_async(dispatch_get_main_queue(), ^{
+5
View File
@@ -37,4 +37,9 @@ typedef NS_ENUM(NSInteger, SPUUpdateAlertChoice) {
SPUSkipThisVersionChoice
};
typedef NS_ENUM(NSInteger, SPUInformationalUpdateAlertChoice) {
SPUDismissInformationalNoticeChoice,
SPUSkipThisInformationalVersionChoice
};
#endif /* SPUStatusCompletionResults_h */
+18 -6
View File
@@ -107,7 +107,23 @@
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem
{
if (self.resumingDownloadedUpdate) {
if (updateItem.isInformationOnlyUpdate) {
assert(!self.resumingDownloadedUpdate);
assert(!self.resumingInstallingUpdate);
[self.userDriver showInformationalUpdateFoundWithAppcastItem:updateItem userInitiated:self.userInitiated reply:^(SPUInformationalUpdateAlertChoice choice) {
dispatch_async(dispatch_get_main_queue(), ^{
switch (choice) {
case SPUSkipThisInformationalVersionChoice:
[self.host setObject:[updateItem versionString] forUserDefaultsKey:SUSkippedVersionKey];
// Fall through
case SPUDismissInformationalNoticeChoice:
[self.delegate uiDriverIsRequestingAbortUpdateWithError:nil];
break;
}
});
}];
} else if (self.resumingDownloadedUpdate) {
[self.userDriver showDownloadedUpdateFoundWithAppcastItem:updateItem userInitiated:self.userInitiated reply:^(SPUUpdateAlertChoice choice) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey];
@@ -131,11 +147,7 @@
[self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey];
switch (choice) {
case SPUInstallUpdateChoice:
if (!updateItem.isInformationOnlyUpdate) {
[self.coreDriver downloadUpdateFromAppcastItem:updateItem];
} else {
[self.delegate uiDriverIsRequestingAbortUpdateWithError:nil];
}
[self.coreDriver downloadUpdateFromAppcastItem:updateItem];
break;
case SPUSkipThisVersionChoice:
[self.host setObject:[updateItem versionString] forUserDefaultsKey:SUSkippedVersionKey];
+22 -2
View File
@@ -84,7 +84,7 @@ SU_EXPORT @protocol SPUUserDriver <NSObject>
- (void)dismissUserInitiatedUpdateCheck;
/*!
* Show the user a new update is found
* Show the user a new update is found and can be downloaded and installed
*
* Let the user know a new update is found and ask them what they want to do.
*
@@ -94,7 +94,6 @@ SU_EXPORT @protocol SPUUserDriver <NSObject>
*
* @param reply
* A reply of SPUInstallUpdateChoice begins downloading and installing the new update.
* Note if the update is only informational (appcastItem.isInformationOnlyUpdate), this response shouldn't be made.
*
* A reply of SPUInstallLaterChoice reminds the user later of the update, which can act as a "do nothing" option.
*
@@ -133,6 +132,27 @@ SU_EXPORT @protocol SPUUserDriver <NSObject>
*/
- (void)showResumableUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated reply:(void (^)(SPUInstallUpdateStatus))reply;
/*!
* Show the user a new informational only update has been found
*
* Let the user know a new informational update is found and ask them what they want to do.
*
* @param appcastItem The Appcast Item containing information that reflects the new update.
* The infoURL property for the appcastItem may be of interest.
*
* @param userInitiated A flag indicating whether or not a user initiated this update check
*
* @param reply
* A reply of SPUDismissInformationalNoticeChoice dismisses this notice.
* An implementor may decide to invoke another action before dismissing the notice.
*
* A reply of SPUSkipThisInformationalVersionChoice skips this particular version and won't bother the user again,
* unless they initiate an update check themselves.
*
* This can be called from any thread
*/
- (void)showInformationalUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated reply:(void (^)(SPUInformationalUpdateAlertChoice))reply;
/*!
* Show the user the release notes for the new update
*
+2
View File
@@ -24,6 +24,8 @@
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost versionDisplayer:(id <SUVersionDisplay>)aVersionDisplayer resumableCompletionBlock:(void (^)(SPUInstallUpdateStatus))block;
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost versionDisplayer:(id <SUVersionDisplay>)aVersionDisplayer informationalCompletionBlock:(void (^)(SPUInformationalUpdateAlertChoice))block;
- (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData;
- (void)showReleaseNotesFailedToDownload;
+23
View File
@@ -40,6 +40,7 @@
@property (nonatomic) BOOL allowsAutomaticUpdates;
@property (nonatomic, copy, nullable) void(^completionBlock)(SPUUpdateAlertChoice);
@property (nonatomic, copy, nullable) void(^resumableCompletionBlock)(SPUInstallUpdateStatus);
@property (nonatomic, copy, nullable) void(^informationalCompletionBlock)(SPUInformationalUpdateAlertChoice);
@property (strong) NSProgressIndicator *releaseNotesSpinner;
@property (assign) BOOL webViewFinishedLoading;
@@ -59,6 +60,7 @@
@synthesize completionBlock = _completionBlock;
@synthesize alreadyDownloaded = _alreadyDownloaded;
@synthesize resumableCompletionBlock = _resumableCompletionBlock;
@synthesize informationalCompletionBlock = _informationalCompletionBlock;
@synthesize versionDisplayer;
@synthesize updateItem;
@@ -118,6 +120,16 @@
return self;
}
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost versionDisplayer:(id <SUVersionDisplay>)aVersionDisplayer informationalCompletionBlock:(void (^)(SPUInformationalUpdateAlertChoice))block
{
self = [self initWithAppcastItem:item host:aHost versionDisplayer:aVersionDisplayer];
if (self != nil)
{
_informationalCompletionBlock = [block copy];
}
return self;
}
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], [self.host bundlePath]]; }
@@ -144,6 +156,17 @@
abort();
}
self.resumableCompletionBlock = nil;
} else if (self.informationalCompletionBlock != nil) {
switch (choice) {
case SPUInstallLaterChoice:
self.informationalCompletionBlock(SPUDismissInformationalNoticeChoice);
break;
case SPUSkipThisVersionChoice:
self.informationalCompletionBlock(SPUSkipThisInformationalVersionChoice);
break;
case SPUInstallUpdateChoice:
abort();
}
}
}
@@ -184,6 +184,16 @@
});
}
- (void)showInformationalUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)__unused userInitiated reply:(void (^)(SPUInformationalUpdateAlertChoice))reply
{
// Todo: show user interface for this
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Found info URL: %@", appcastItem.infoURL);
reply(SPUDismissInformationalNoticeChoice);
});
}
- (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData
{
[self.installUpdateViewController showReleaseNotesWithDownloadData:downloadData];
+9
View File
@@ -153,6 +153,15 @@
});
}
- (void)showInformationalUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)__unused userInitiated reply:(void (^)(SPUInformationalUpdateAlertChoice))reply
{
dispatch_async(dispatch_get_main_queue(), ^{
fprintf(stderr, "Found information for new update: %s\n", appcastItem.infoURL.absoluteString.UTF8String);
reply(SPUDismissInformationalNoticeChoice);
});
}
- (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData
{
dispatch_async(dispatch_get_main_queue(), ^{