Add resuming downloaded updates without starting the installer automatically

This allows automatically downloading updates, and having them prompt up later, so the user can perform authorization later for starting up the installer
This commit is contained in:
Zorg committed 2016-07-23 09:08:29 -04:00
1 parent b014737e83
commit 345ed3b60e
18 files changed
+187 -88

No files matched your search

+2 -1
View File
@@ -12,5 +12,6 @@ typedef NS_ENUM(NSUInteger, SUAuthorizationReply)
{
SUAuthorizationReplySuccess = 0,
SUAuthorizationReplyCancelled = 1,
SUAuthorizationReplyFailure = 2
SUAuthorizationReplyFailure = 2,
SUAuthorizationReplyTryAgainLater = 3
};
+11 -7
View File
@@ -175,14 +175,18 @@
submittedInstaller = ([SUSubmitInstaller submitInstallerAtPath:installerPath withHostBundle:hostBundle allowingInteraction:allowingInteraction inSystemDomain:needsSystemAuthorization] == SUAuthorizationReplySuccess);
}
BOOL submittedProgressTool = [self submitProgressToolAtPath:progressToolPath withHostBundle:hostBundle allowingInteraction:allowingInteraction installerPath:installerPath shouldSubmitInstaller:!shouldSubmitInstallerImmediately];
if (!submittedProgressTool) {
completionHandler(SUAuthorizationReplyFailure);
} else if (shouldSubmitInstallerImmediately) {
completionHandler(submittedInstaller ? SUAuthorizationReplySuccess : SUAuthorizationReplyFailure);
if (needsSystemAuthorization && !preflighted && !allowingInteraction) {
completionHandler(SUAuthorizationReplyTryAgainLater);
} else {
[self waitForProgressAgentWithHostBundle:hostBundle completion:completionHandler];
BOOL submittedProgressTool = [self submitProgressToolAtPath:progressToolPath withHostBundle:hostBundle allowingInteraction:allowingInteraction installerPath:installerPath shouldSubmitInstaller:!shouldSubmitInstallerImmediately];
if (!submittedProgressTool) {
completionHandler(SUAuthorizationReplyFailure);
} else if (shouldSubmitInstallerImmediately) {
completionHandler(submittedInstaller ? SUAuthorizationReplySuccess : SUAuthorizationReplyFailure);
} else {
[self waitForProgressAgentWithHostBundle:hostBundle completion:completionHandler];
}
}
});
}
+10 -7
View File
@@ -49,7 +49,7 @@
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary *)httpHeaders completion:(SUUpdateDriverCompletion)completionBlock
{
[self.coreDriver checkForUpdatesAtAppcastURL:appcastURL withUserAgent:userAgent httpHeaders:httpHeaders includesSkippedUpdates:NO completion:completionBlock];
[self.coreDriver checkForUpdatesAtAppcastURL:appcastURL withUserAgent:userAgent httpHeaders:httpHeaders includesSkippedUpdates:NO requiresSilentInstall:YES completion:completionBlock];
}
- (void)resumeUpdateWithCompletion:(SUUpdateDriverCompletion)__unused completionBlock __attribute__((noreturn))
@@ -59,6 +59,13 @@
abort();
}
- (void)resumeDownloadedUpdate:(SUDownloadedUpdate *)__unused downloadedUpdate completion:(SUUpdateDriverCompletion)__unused completionBlock __attribute__((noreturn))
{
// Nothing really to do here.. this shouldn't be called.
SULog(@"Error: resumeDownloadedUpdate:completion: called on SUAutomaticUpdateDriver");
abort();
}
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem
{
self.updateItem = updateItem;
@@ -99,11 +106,6 @@
}
}
- (BOOL)basicDriverShouldSignalShowingUpdateImmediately
{
return (!self.willInstallSilently || self.updateItem.isCriticalUpdate);
}
- (void)basicDriverIsRequestingAbortUpdateWithError:(NSError *)error
{
[self abortUpdateWithError:error];
@@ -121,7 +123,8 @@
- (void)abortUpdateWithError:(NSError *)error
{
[self.coreDriver abortUpdateWithError:error];
BOOL startNextUpdateImmediately = (error == nil) && (!self.willInstallSilently || self.updateItem.isCriticalUpdate);
[self.coreDriver abortUpdateAndSignalShowingNextUpdateImmediately:startNextUpdateImmediately error:error];
}
@end
+3 -3
View File
@@ -20,8 +20,6 @@ NS_ASSUME_NONNULL_BEGIN
- (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error;
- (BOOL)basicDriverShouldSignalShowingUpdateImmediately;
@optional
- (void)basicDriverDidFinishLoadingAppcast;
@@ -36,9 +34,11 @@ NS_ASSUME_NONNULL_BEGIN
- (void)resumeUpdateWithCompletion:(SUUpdateDriverCompletion)completionBlock;
- (void)resumeDownloadedUpdate:(SUDownloadedUpdate *)downloadedUpdate completion:(SUUpdateDriverCompletion)completionBlock;
@property (nullable, nonatomic, readonly) SUAppcastItem *nonDeltaUpdateItem;
- (void)abortUpdateWithError:(nullable NSError *)error;
- (void)abortUpdateAndSignalShowingNextUpdateImmediately:(BOOL)shouldSignalShowingUpdate downloadedUpdate:(SUDownloadedUpdate * _Nullable)downloadedUpdate error:(nullable NSError *)error;
@end
+24 -12
View File
@@ -16,6 +16,7 @@
#import "SUAppcastItem.h"
#import "SUProbeInstallStatus.h"
#import "SUInstallationInfo.h"
#import "SUDownloadedUpdate.h"
@interface SUBasicUpdateDriver () <SUAppcastDriverDelegate>
@@ -64,26 +65,37 @@
}
}
- (void)notifyResumableUpdateItem:(SUAppcastItem *)updateItem
{
if (updateItem == nil) {
[self.delegate basicDriverIsRequestingAbortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUResumeAppcastError userInfo:@{ NSLocalizedDescriptionKey: SULocalizedString(@"Failed to resume installing update.", nil) }]];
} else {
// Kind of lying, but triggering the notification so drivers can know when to stop showing initial fetching progress
[self notifyFinishLoadingAppcast];
SUAppcastItem *nonNullUpdateItem = updateItem;
[self didFindValidUpdateWithAppcastItem:nonNullUpdateItem];
}
}
- (void)resumeUpdateWithCompletion:(SUUpdateDriverCompletion)completionBlock
{
self.completionBlock = completionBlock;
[SUProbeInstallStatus probeInstallerUpdateItemForHost:self.host completion:^(SUInstallationInfo * _Nullable installationInfo) {
dispatch_async(dispatch_get_main_queue(), ^{
SUAppcastItem *updateItem = installationInfo.appcastItem;
if (updateItem == nil) {
[self.delegate basicDriverIsRequestingAbortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUResumeAppcastError userInfo:@{ NSLocalizedDescriptionKey: SULocalizedString(@"Failed to resume installing update.", nil) }]];
} else {
// Kind of lying, but triggering the notification so drivers can know when to stop showing initial fetching progress
[self notifyFinishLoadingAppcast];
SUAppcastItem *nonNullUpdateItem = updateItem;
[self didFindValidUpdateWithAppcastItem:nonNullUpdateItem];
}
[self notifyResumableUpdateItem:installationInfo.appcastItem];
});
}];
}
- (void)resumeDownloadedUpdate:(SUDownloadedUpdate *)downloadedUpdate completion:(SUUpdateDriverCompletion)completionBlock
{
self.completionBlock = completionBlock;
[self notifyResumableUpdateItem:downloadedUpdate.updateItem];
}
- (SUAppcastItem *)nonDeltaUpdateItem
{
return self.appcastDriver.nonDeltaUpdateItem;
@@ -141,7 +153,7 @@
[self.delegate basicDriverIsRequestingAbortUpdateWithError:notFoundError];
}
- (void)abortUpdateWithError:(nullable NSError *)error
- (void)abortUpdateAndSignalShowingNextUpdateImmediately:(BOOL)shouldSignalShowingUpdate downloadedUpdate:(SUDownloadedUpdate * _Nullable)downloadedUpdate error:(nullable NSError *)error
{
if (error != nil) {
if ([error code] != SUNoUpdateError) { // Let's not bother logging this.
@@ -160,7 +172,7 @@
}
if (self.completionBlock != nil) {
self.completionBlock([self.delegate basicDriverShouldSignalShowingUpdateImmediately]);
self.completionBlock(shouldSignalShowingUpdate, downloadedUpdate);
self.completionBlock = nil;
}
}
+8 -4
View File
@@ -25,8 +25,6 @@ NS_ASSUME_NONNULL_BEGIN
- (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error;
- (BOOL)basicDriverShouldSignalShowingUpdateImmediately;
@optional
- (void)basicDriverDidFinishLoadingAppcast;
@@ -53,15 +51,21 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithHost:(SUHost *)host sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater updaterDelegate:(nullable id <SUUpdaterDelegate>)updaterDelegate delegate:(id<SUCoreBasedUpdateDriverDelegate>)delegate;
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary *)httpHeaders includesSkippedUpdates:(BOOL)includesSkippedUpdates completion:(SUUpdateDriverCompletion)completionBlock;
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary *)httpHeaders includesSkippedUpdates:(BOOL)includesSkippedUpdates requiresSilentInstall:(BOOL)silentInstall completion:(SUUpdateDriverCompletion)completionBlock;
- (void)resumeUpdateWithCompletion:(SUUpdateDriverCompletion)completionBlock;
- (void)resumeDownloadedUpdate:(SUDownloadedUpdate *)downloadedUpdate completion:(SUUpdateDriverCompletion)completionBlock;
- (void)downloadUpdateFromAppcastItem:(SUAppcastItem *)updateItem;
- (void)extractDownloadedUpdate;
- (void)clearDownloadedUpdate;
- (void)finishInstallationWithResponse:(SUInstallUpdateStatus)installUpdateStatus displayingUserInterface:(BOOL)displayingUserInterface;
- (void)abortUpdateWithError:(nullable NSError *)error;
- (void)abortUpdateAndSignalShowingNextUpdateImmediately:(BOOL)shouldSignalShowingUpdate error:(nullable NSError *)error;
@end
+40 -10
View File
@@ -28,9 +28,11 @@
@property (nonatomic, readonly) SUInstallerDriver *installerDriver;
@property (nonatomic, weak, readonly) id<SUCoreBasedUpdateDriverDelegate> delegate;
@property (nonatomic) SUAppcastItem *updateItem;
@property (nonatomic) SUDownloadedUpdate *downloadedUpdate;
@property (nonatomic, readonly) SUHost *host;
@property (nonatomic) BOOL resumingUpdate;
@property (nonatomic) BOOL silentInstall;
@property (nonatomic, readonly, weak) id updater; // if we didn't have legacy support, I'd remove this..
@property (nullable, nonatomic, readonly, weak) id <SUUpdaterDelegate>updaterDelegate;
@property (nonatomic) NSString *userAgent;
@@ -46,9 +48,11 @@
@synthesize updateItem = _updateItem;
@synthesize host = _host;
@synthesize resumingUpdate = _resumingUpdate;
@synthesize silentInstall = _silentInstall;
@synthesize updater = _updater;
@synthesize updaterDelegate = _updaterDelegate;
@synthesize userAgent = _userAgent;
@synthesize downloadedUpdate = _downloadedUpdate;
- (instancetype)initWithHost:(SUHost *)host sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater updaterDelegate:(nullable id <SUUpdaterDelegate>)updaterDelegate delegate:(id<SUCoreBasedUpdateDriverDelegate>)delegate
{
@@ -70,9 +74,10 @@
return self;
}
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary *)httpHeaders includesSkippedUpdates:(BOOL)includesSkippedUpdates completion:(SUUpdateDriverCompletion)completionBlock
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary *)httpHeaders includesSkippedUpdates:(BOOL)includesSkippedUpdates requiresSilentInstall:(BOOL)silentInstall completion:(SUUpdateDriverCompletion)completionBlock
{
self.userAgent = userAgent;
self.silentInstall = silentInstall;
[self.basicDriver checkForUpdatesAtAppcastURL:appcastURL withUserAgent:userAgent httpHeaders:httpHeaders includesSkippedUpdates:includesSkippedUpdates completion:completionBlock];
}
@@ -80,9 +85,19 @@
- (void)resumeUpdateWithCompletion:(SUUpdateDriverCompletion)completionBlock
{
self.resumingUpdate = YES;
self.silentInstall = NO;
[self.basicDriver resumeUpdateWithCompletion:completionBlock];
}
- (void)resumeDownloadedUpdate:(SUDownloadedUpdate *)downloadedUpdate completion:(SUUpdateDriverCompletion)completionBlock
{
self.downloadedUpdate = downloadedUpdate;
self.silentInstall = NO;
[self.basicDriver resumeDownloadedUpdate:downloadedUpdate completion:completionBlock];
}
- (void)basicDriverDidFinishLoadingAppcast
{
if ([self.delegate respondsToSelector:@selector(basicDriverDidFinishLoadingAppcast)]) {
@@ -136,15 +151,33 @@
}
- (void)downloadDriverDidDownloadUpdate:(SUDownloadedUpdate *)downloadedUpdate
{
self.downloadedUpdate = downloadedUpdate;
[self extractUpdate:downloadedUpdate];
}
- (void)extractDownloadedUpdate
{
assert(self.downloadedUpdate != nil);
[self extractUpdate:self.downloadedUpdate];
}
- (void)clearDownloadedUpdate
{
self.downloadedUpdate = nil;
}
- (void)extractUpdate:(SUDownloadedUpdate *)downloadedUpdate
{
// Now we have to extract the downloaded archive.
if ([self.delegate respondsToSelector:@selector(coreDriverDidFinishDownloadingUpdate)]) {
[self.delegate coreDriverDidFinishDownloadingUpdate];
}
[self.installerDriver extractDownloadedUpdate:downloadedUpdate completion:^(NSError * _Nullable error) {
[self.installerDriver extractDownloadedUpdate:downloadedUpdate silently:self.silentInstall completion:^(NSError * _Nullable error) {
if (error != nil) {
[self.delegate coreDriverIsRequestingAbortUpdateWithError:(error.code == SUInstallationCancelledError) ? nil : error];
BOOL silentError = (error.code == SUInstallationCancelledError || error.code == SUInstallationTryAgainLaterError);
[self.delegate coreDriverIsRequestingAbortUpdateWithError:silentError ? nil : error];
}
}];
}
@@ -244,16 +277,13 @@
[self downloadUpdateFromAppcastItem:nonDeltaUpdateItem];
}
- (BOOL)basicDriverShouldSignalShowingUpdateImmediately
{
return [self.delegate basicDriverShouldSignalShowingUpdateImmediately];
}
- (void)abortUpdateWithError:(nullable NSError *)error
- (void)abortUpdateAndSignalShowingNextUpdateImmediately:(BOOL)shouldSignalShowingUpdate error:(nullable NSError *)error
{
[self.installerDriver abortInstall];
[self.downloadDriver cleanup];
[self.basicDriver abortUpdateWithError:error];
SUDownloadedUpdate *downloadedUpdate = (error == nil) ? self.downloadedUpdate : nil;
[self.basicDriver abortUpdateAndSignalShowingNextUpdateImmediately:shouldSignalShowingUpdate downloadedUpdate:downloadedUpdate error:error];
}
@end
+2 -1
View File
@@ -54,7 +54,8 @@ typedef NS_ENUM(OSStatus, SUError) {
SURelaunchError = 4004,
SUInstallationError = 4005,
SUDowngradeError = 4006,
SUInstallationCancelledError = 4007
SUInstallationCancelledError = 4007,
SUInstallationTryAgainLaterError = 4008
};
#endif
+1 -1
View File
@@ -33,7 +33,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)resumeUpdateWithUpdateItem:(SUAppcastItem *)updateItem;
- (void)extractDownloadedUpdate:(SUDownloadedUpdate *)downloadedUpdate completion:(void (^)(NSError * _Nullable))completionHandler;
- (void)extractDownloadedUpdate:(SUDownloadedUpdate *)downloadedUpdate silently:(BOOL)silently completion:(void (^)(NSError * _Nullable))completionHandler;
- (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI;
+19 -16
View File
@@ -130,7 +130,7 @@
}
// This can be called multiple times (eg: if a delta update fails, this may be called again with a regular update item)
- (void)extractDownloadedUpdate:(SUDownloadedUpdate *)downloadedUpdate completion:(void (^)(NSError * _Nullable))completionHandler
- (void)extractDownloadedUpdate:(SUDownloadedUpdate *)downloadedUpdate silently:(BOOL)silently completion:(void (^)(NSError * _Nullable))completionHandler
{
self.updateItem = downloadedUpdate.updateItem;
self.temporaryDirectory = downloadedUpdate.temporaryDirectory;
@@ -139,7 +139,7 @@
self.currentStage = SUInstallerNotStarted;
if (self.installerConnection == nil) {
[self launchAutoUpdateWithCompletion:completionHandler];
[self launchAutoUpdateSilently:silently completion:completionHandler];
} else {
// The Install tool is already alive; just send out installation input data again
[self sendInstallationData];
@@ -372,7 +372,7 @@
return cachePath;
}
- (void)launchAutoUpdateWithCompletion:(void (^)(NSError *_Nullable))completionHandler
- (void)launchAutoUpdateSilently:(BOOL)silently completion:(void (^)(NSError *_Nullable))completionHandler
{
// Copy the relauncher into a temporary directory so we can get to it after the new version's installed.
// Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems.
@@ -426,7 +426,8 @@
installerLauncher = launcherConnection.remoteObjectProxy;
}
BOOL shouldAllowInstallerInteraction = NO;
#warning review this...
BOOL shouldAllowInstallerInteraction = !silently;
if ([self.updaterDelegate respondsToSelector:@selector(updaterShouldAllowInstallerInteraction:)]) {
shouldAllowInstallerInteraction = [self.updaterDelegate updaterShouldAllowInstallerInteraction:self.updater];
}
@@ -440,18 +441,20 @@
retrievedLaunchStatus = YES;
[launcherConnection invalidate];
if (result == SUAuthorizationReplyFailure) {
NSError *error =
[NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey:SULocalizedString(@"An error occurred while launching the installer. Please try again later.", nil) }];
completionHandler(error);
} else if (result == SUAuthorizationReplyCancelled) {
NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationCancelledError userInfo:nil];
completionHandler(error);
} else {
[self setUpConnection];
completionHandler(nil);
switch (result) {
case SUAuthorizationReplyFailure:
completionHandler([NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey:SULocalizedString(@"An error occurred while launching the installer. Please try again later.", nil) }]);
break;
case SUAuthorizationReplyCancelled:
completionHandler([NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationCancelledError userInfo:nil]);
break;
case SUAuthorizationReplyTryAgainLater:
completionHandler([NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationTryAgainLaterError userInfo:nil]);
break;
case SUAuthorizationReplySuccess:
[self setUpConnection];
completionHandler(nil);
break;
}
});
}];
+10 -8
View File
@@ -16,12 +16,14 @@
@interface SUProbingUpdateDriver () <SUBasicUpdateDriverDelegate>
@property (nonatomic, readonly) SUBasicUpdateDriver *basicDriver;
@property (nonatomic) SUDownloadedUpdate *downloadedUpdate;
@end
@implementation SUProbingUpdateDriver
@synthesize basicDriver = _basicDriver;
@synthesize downloadedUpdate = _downloadedUpdate;
- (instancetype)initWithHost:(SUHost *)host updater:(id)updater updaterDelegate:(id <SUUpdaterDelegate>)updaterDelegate
{
@@ -37,16 +39,18 @@
[self.basicDriver checkForUpdatesAtAppcastURL:appcastURL withUserAgent:userAgent httpHeaders:httpHeaders includesSkippedUpdates:NO completion:completionBlock];
}
- (BOOL)basicDriverShouldSignalShowingUpdateImmediately
{
return NO;
}
- (void)resumeUpdateWithCompletion:(SUUpdateDriverCompletion)completionBlock
{
[self.basicDriver resumeUpdateWithCompletion:completionBlock];
}
- (void)resumeDownloadedUpdate:(SUDownloadedUpdate *)downloadedUpdate completion:(SUUpdateDriverCompletion)completionBlock
{
self.downloadedUpdate = downloadedUpdate;
[self.basicDriver resumeDownloadedUpdate:downloadedUpdate completion:completionBlock];
}
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)__unused appcastItem
{
// Stop as soon as we have an answer
@@ -55,9 +59,7 @@
- (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error
{
[self abortUpdateWithError:error];
}
- (void)abortUpdate
@@ -67,7 +69,7 @@
- (void)abortUpdateWithError:(nullable NSError *)error
{
[self.basicDriver abortUpdateWithError:error];
[self.basicDriver abortUpdateAndSignalShowingNextUpdateImmediately:NO downloadedUpdate:self.downloadedUpdate error:error];
}
@end
+5
View File
@@ -45,6 +45,11 @@
[self.uiDriver resumeUpdateWithCompletion:completionBlock];
}
- (void)resumeDownloadedUpdate:(SUDownloadedUpdate *)downloadedUpdate completion:(SUUpdateDriverCompletion)completionBlock
{
[self.uiDriver resumeDownloadedUpdate:downloadedUpdate completion:completionBlock];
}
- (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *)__unused error
{
// Don't tell the user that no update was found or some appcast fetch error occurred for scheduled update checks
+11 -2
View File
@@ -318,15 +318,22 @@
#pragma mark Download & Install Updates
- (void)showStatusController
{
if (self.statusController == nil) {
self.statusController = [[SUStatusController alloc] initWithHost:self.host];
[self.statusController showWindow:self];
}
}
- (void)showDownloadInitiatedWithCompletion:(void (^)(SUDownloadUpdateStatus))downloadUpdateStatusCompletion
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.coreComponent registerDownloadStatusHandler:downloadUpdateStatusCompletion];
self.statusController = [[SUStatusController alloc] initWithHost:self.host];
[self showStatusController];
[self.statusController beginActionWithTitle:SULocalizedString(@"Downloading update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil];
[self.statusController setButtonTitle:SULocalizedString(@"Cancel", nil) target:self action:@selector(cancelDownload:) isDefault:NO];
[self.statusController showWindow:self];
});
}
@@ -364,7 +371,9 @@
dispatch_async(dispatch_get_main_queue(), ^{
[self.coreComponent completeDownloadStatus];
[self showStatusController];
[self.statusController beginActionWithTitle:SULocalizedString(@"Extracting update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil];
[self.statusController setButtonTitle:SULocalizedString(@"Cancel", nil) target:nil action:nil isDefault:NO];
[self.statusController setButtonEnabled:NO];
});
}
+3 -1
View File
@@ -22,7 +22,7 @@ NS_ASSUME_NONNULL_BEGIN
@end
@class SUHost;
@class SUHost, SUDownloadedUpdate;
@protocol SUUserDriver, SUUpdaterDelegate;
@interface SUUIBasedUpdateDriver : NSObject
@@ -33,6 +33,8 @@ NS_ASSUME_NONNULL_BEGIN
- (void)resumeUpdateWithCompletion:(SUUpdateDriverCompletion)completionBlock;
- (void)resumeDownloadedUpdate:(SUDownloadedUpdate *)downloadedUpdate completion:(SUUpdateDriverCompletion)completionBlock;
- (void)abortUpdateWithError:(nullable NSError *)error;
@end
+17 -9
View File
@@ -29,6 +29,7 @@
@property (nonatomic, weak, readonly) id<SUUIBasedUpdateDriverDelegate> delegate;
@property (nonatomic, readonly) id<SUUserDriver> userDriver;
@property (nonatomic) BOOL resumingUpdate;
@property (nonatomic) BOOL resumingDownloadedUpdate;
@end
@@ -41,6 +42,7 @@
@synthesize userDriver = _userDriver;
@synthesize delegate = _delegate;
@synthesize resumingUpdate = _resumingUpdate;
@synthesize resumingDownloadedUpdate = _resumingDownloadedUpdate;
- (instancetype)initWithHost:(SUHost *)host sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id <SUUserDriver>)userDriver updaterDelegate:(nullable id <SUUpdaterDelegate>)updaterDelegate delegate:(id<SUUIBasedUpdateDriverDelegate>)delegate
{
@@ -59,7 +61,7 @@
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary *)httpHeaders includesSkippedUpdates:(BOOL)includesSkippedUpdates completion:(SUUpdateDriverCompletion)completionBlock
{
[self.coreDriver checkForUpdatesAtAppcastURL:appcastURL withUserAgent:userAgent httpHeaders:httpHeaders includesSkippedUpdates:includesSkippedUpdates completion:completionBlock];
[self.coreDriver checkForUpdatesAtAppcastURL:appcastURL withUserAgent:userAgent httpHeaders:httpHeaders includesSkippedUpdates:includesSkippedUpdates requiresSilentInstall:NO completion:completionBlock];
}
- (void)resumeUpdateWithCompletion:(SUUpdateDriverCompletion)completionBlock
@@ -68,6 +70,12 @@
[self.coreDriver resumeUpdateWithCompletion:completionBlock];
}
- (void)resumeDownloadedUpdate:(SUDownloadedUpdate *)downloadedUpdate completion:(SUUpdateDriverCompletion)completionBlock
{
self.resumingDownloadedUpdate = YES;
[self.coreDriver resumeDownloadedUpdate:downloadedUpdate completion:completionBlock];
}
- (void)basicDriverDidFinishLoadingAppcast
{
if ([self.delegate respondsToSelector:@selector(basicDriverDidFinishLoadingAppcast)]) {
@@ -77,15 +85,20 @@
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem
{
if (!self.resumingUpdate) {
if (!self.resumingUpdate || self.resumingDownloadedUpdate) {
[self.userDriver showUpdateFoundWithAppcastItem:updateItem reply:^(SUUpdateAlertChoice choice) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey];
switch (choice) {
case SUInstallUpdateChoice:
[self.coreDriver downloadUpdateFromAppcastItem:updateItem];
if (!self.resumingDownloadedUpdate) {
[self.coreDriver downloadUpdateFromAppcastItem:updateItem];
} else {
[self.coreDriver extractDownloadedUpdate];
}
break;
case SUSkipThisVersionChoice:
[self.coreDriver clearDownloadedUpdate];
[self.host setObject:[updateItem versionString] forUserDefaultsKey:SUSkippedVersionKey];
// Fall through
case SUInstallLaterChoice:
@@ -183,11 +196,6 @@
[self.userDriver showUpdateInstallationDidFinish];
}
- (BOOL)basicDriverShouldSignalShowingUpdateImmediately
{
return NO;
}
- (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error
{
// A delegate may want to handle this type of error specially
@@ -203,7 +211,7 @@
{
void (^abortUpdate)(void) = ^{
[self.userDriver dismissUpdateInstallation];
[self.coreDriver abortUpdateWithError:error];
[self.coreDriver abortUpdateAndSignalShowingNextUpdateImmediately:NO error:error];
};
if (error != nil) {
+5 -1
View File
@@ -8,7 +8,9 @@
NS_ASSUME_NONNULL_BEGIN
typedef void (^SUUpdateDriverCompletion)(BOOL shouldShowUpdateImmediately);
@class SUDownloadedUpdate;
typedef void (^SUUpdateDriverCompletion)(BOOL shouldShowUpdateImmediately, SUDownloadedUpdate * _Nullable resumableUpdate);
@protocol SUUpdateDriver <NSObject>
@@ -16,6 +18,8 @@ typedef void (^SUUpdateDriverCompletion)(BOOL shouldShowUpdateImmediately);
- (void)resumeUpdateWithCompletion:(SUUpdateDriverCompletion)completionBlock;
- (void)resumeDownloadedUpdate:(SUDownloadedUpdate *)downloadedUpdate completion:(SUUpdateDriverCompletion)completionBlock;
- (void)abortUpdate;
@end
+11 -5
View File
@@ -27,6 +27,7 @@
#import "SUErrors.h"
#import "SUXPCServiceInfo.h"
#import "SUUpdaterCycle.h"
#import "SUDownloadedUpdate.h"
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
@@ -49,6 +50,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
@property (nonatomic, readonly) SUUpdaterCycle *updaterCycle;
@property (nonatomic) BOOL startedUpdater;
@property (nonatomic, copy) void (^preStartedScheduledUpdateBlock)(void);
@property (nonatomic, nullable) SUDownloadedUpdate *resumableUpdate;
@end
@@ -65,6 +67,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
@synthesize sparkleBundle = _sparkleBundle;
@synthesize startedUpdater = _startedUpdater;
@synthesize preStartedScheduledUpdateBlock = _preStartedScheduledUpdateBlock;
@synthesize resumableUpdate = _resumableUpdate;
#ifdef DEBUG
+ (void)load
@@ -376,7 +379,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
}
id <SUUpdateDriver> updateDriver;
if (!installerIsRunning && [strongSelf automaticallyDownloadsUpdates] && [strongSelf allowsAutomaticUpdates]) {
if (!installerIsRunning && [strongSelf automaticallyDownloadsUpdates] && [strongSelf allowsAutomaticUpdates] && strongSelf.resumableUpdate == nil) {
updateDriver =
[[SUAutomaticUpdateDriver alloc]
initWithHost:strongSelf.host
@@ -479,9 +482,10 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
// Use a NIL URL to cancel quietly.
if (theFeedURL) {
__weak SUUpdater *weakSelf = self;
SUUpdateDriverCompletion completionBlock = ^(BOOL shouldShowUpdateImmediately) {
SUUpdateDriverCompletion completionBlock = ^(BOOL shouldShowUpdateImmediately, SUDownloadedUpdate * _Nullable resumableUpdate) {
SUUpdater *strongSelf = weakSelf;
if (strongSelf != nil) {
strongSelf.resumableUpdate = resumableUpdate;
strongSelf.driver = nil;
[strongSelf updateLastUpdateCheckDate];
[strongSelf scheduleNextUpdateCheckFiringImmediately:shouldShowUpdateImmediately];
@@ -490,10 +494,12 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
[self.userDriver showCanCheckForUpdates:NO];
if (!installerInProgress) {
[self.driver checkForUpdatesAtAppcastURL:theFeedURL withUserAgent:[self userAgentString] httpHeaders:[self httpHeaders] completion:completionBlock];
} else {
if (installerInProgress) {
[self.driver resumeUpdateWithCompletion:completionBlock];
} else if (self.resumableUpdate != nil) {
[self.driver resumeDownloadedUpdate:(SUDownloadedUpdate * _Nonnull)self.resumableUpdate completion:completionBlock];
} else {
[self.driver checkForUpdatesAtAppcastURL:theFeedURL withUserAgent:[self userAgentString] httpHeaders:[self httpHeaders] completion:completionBlock];
}
} else {
[self.driver abortUpdate];
+5
View File
@@ -65,6 +65,11 @@
[self.uiDriver resumeUpdateWithCompletion:completionBlock];
}
- (void)resumeDownloadedUpdate:(SUDownloadedUpdate *)downloadedUpdate completion:(SUUpdateDriverCompletion)completionBlock
{
[self.uiDriver resumeDownloadedUpdate:downloadedUpdate completion:completionBlock];
}
- (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error
{
[self abortUpdateWithError:error];