Add installation did finish event. This is not complete.

For sparkle-cli and out-of-process updaters, I added a did finish installing event.

I also have logic dealing with whether an update can be silently installed or not.

I made closing status windows before app termination a reponsibility for the user driver now, not
the installer drivers.

I improved checking for updates before starting the updater, if Sparle didn't ask the user for permission yet.

Currently, Autoupdate can persist in the background even when the app is terminated,
if we don't have sufficient privilleges to install right away for example, or if an update isn't silent.
After much thinking, I need to ditch this strategy because:

1. An app can be manually replaced and so the installer would have to monitor that
2. We leave a zombie process running
This commit is contained in:
Zorg committed 2016-04-29 00:37:21 -04:00
1 parent 7183d9ebc5
commit fdee19ec69
18 files changed
+238 -117

No files matched your search

+45 -32
View File
@@ -59,6 +59,7 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
@property (nonatomic) BOOL performedStage1Installation;
@property (nonatomic) BOOL performedStage2Installation;
@property (nonatomic) BOOL performedStage3Installation;
@property (nonatomic) BOOL waitingForStage2Feedback;
@end
@@ -79,6 +80,7 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
@synthesize performedStage1Installation = _performedStage1Installation;
@synthesize performedStage2Installation = _performedStage2Installation;
@synthesize performedStage3Installation = _performedStage3Installation;
@synthesize waitingForStage2Feedback = _waitingForStage2Feedback;
/*
* hostPath - path to host (original) application
@@ -379,7 +381,9 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
dispatch_async(dispatch_get_main_queue(), ^{
if (self.performedStage1Installation) {
// Resume the installation if we aren't done with stage 2 yet, and remind the client we are prepared to relaunch
[self resumeInstallation];
dispatch_async(self.installerQueue, ^{
[self performStage2InstallationIfNeeded];
});
}
});
}];
@@ -424,18 +428,32 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
dispatch_async(dispatch_get_main_queue(), ^{
self.installer = installer;
NSData *silentData = [NSData dataWithBytes:&canPerformSilentInstall length:sizeof(canPerformSilentInstall)];
[self.remotePort sendMessageWithIdentifier:SUInstallationFinishedStage1 data:silentData completion:^(BOOL success) {
uint8_t targetTerminated = (uint8_t)self.terminationListener.terminated;
uint8_t sendInformation[] = {canPerformSilentInstall, targetTerminated};
NSData *sendData = [NSData dataWithBytes:sendInformation length:sizeof(sendInformation)];
self.waitingForStage2Feedback = (canPerformSilentInstall == 0);
[self.remotePort sendMessageWithIdentifier:SUInstallationFinishedStage1 data:sendData completion:^(BOOL success) {
if (!success) {
SULog(@"Error sending stage 1 finish");
if (self.waitingForStage2Feedback) {
SULog(@"Exiting because sending Stage 1 Installation Failed and we need to wait for continuation response");
[self cleanupAndExitWithStatus:EXIT_FAILURE];
}
}
}];
self.performedStage1Installation = YES;
// Stage 2 can still be run before we finish installation
// if the updater requests for it before the app is terminated
[self finishInstallationAfterHostTermination];
if (!self.waitingForStage2Feedback) {
// Stage 2 can still be run before we finish installation
// if the updater requests for it before the app is terminated
[self finishInstallationAfterHostTermination];
}
});
});
}
@@ -447,6 +465,7 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
}
if (self.shouldShowUI && [self.installer mayNeedToRequestAuthorization]) {
#warning should probably do this on main thread
// We should activate our app so that the auth prompt will be active
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
}
@@ -462,43 +481,29 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
});
} else {
self.performedStage2Installation = YES;
}
}
// Can be called multiple times without harm
- (void)resumeInstallation
{
dispatch_async(self.installerQueue, ^{
[self performStage2InstallationIfNeeded];
dispatch_async(dispatch_get_main_queue(), ^{
[self.remotePort sendMessageWithIdentifier:SUInstallationFinishedStage2 data:[NSData data] completion:^(BOOL success) {
uint8_t targetTerminated = (uint8_t)self.terminationListener.terminated;
NSData *sendData = [NSData dataWithBytes:&targetTerminated length:sizeof(targetTerminated)];
[self.remotePort sendMessageWithIdentifier:SUInstallationFinishedStage2 data:sendData completion:^(BOOL success) {
if (!success) {
SULog(@"Error sending stage 2 finish");
}
}];
// Stage 3 will perform when the target terminates
if (self.waitingForStage2Feedback) {
self.waitingForStage2Feedback = NO;
[self finishInstallationAfterHostTermination];
} // otherwise stage 3 will perform when the target terminates
});
});
}
}
- (void)finishInstallationAfterHostTermination
{
[self.terminationListener startListeningWithCompletion:^(BOOL success) {
self.terminationListener = nil;
if (!success) {
SULog(@"Timed out waiting for target to terminate. Target path is %@", self.host.bundlePath);
[self.installer cleanup];
self.installer = nil;
dispatch_async(dispatch_get_main_queue(), ^{
[self cleanupAndExitWithStatus:EXIT_FAILURE];
});
return;
}
[self.terminationListener startListeningWithCompletion:^{
// Launch our installer progress UI tool if only after a certain amount of time passes
__block NSRunningApplication *installerProgressRunningApplication = nil;
__block BOOL shouldLaunchInstallerProgress = YES;
@@ -513,7 +518,9 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(SUDisplayProgressTimeDelay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (shouldLaunchInstallerProgress) {
// Make sure we're still eligible for showing the installer progress
// Also if the updater process is still alive, showing the progress should not be our duty
if (shouldLaunchInstallerProgress && self.remotePort == nil) {
NSError *launchError = nil;
NSArray *arguments = @[self.host.bundlePath];
@@ -552,6 +559,12 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
[installerProgressRunningApplication terminate];
shouldLaunchInstallerProgress = NO;
[self.remotePort sendMessageWithIdentifier:SUInstallationFinishedStage3 data:[NSData data] completion:^(BOOL success) {
if (!success) {
SULog(@"Error sending stage 3 finish");
}
}];
// Invalidate the local port before re-launching the updated app
// If we don't do this, the updated app could think the installation can be resumable,
// if it checks for updates immediately on launch
+2 -1
View File
@@ -24,7 +24,8 @@ typedef NS_ENUM(int32_t, SUInstallerMessageType)
SUValidationStarted = 4,
SUInstallationStartedStage1 = 5,
SUInstallationFinishedStage1 = 6,
SUInstallationFinishedStage2 = 7
SUInstallationFinishedStage2 = 7,
SUInstallationFinishedStage3 = 8
};
typedef NS_ENUM(int32_t, SUUpdaterMessageType)
+3
View File
@@ -37,6 +37,9 @@ BOOL SUInstallerMessageTypeIsLegal(SUInstallerMessageType oldMessageType, SUInst
case SUInstallationFinishedStage2:
legal = (oldMessageType == SUInstallationFinishedStage1);
break;
case SUInstallationFinishedStage3:
legal = (oldMessageType == SUInstallationFinishedStage2);
break;
}
return legal;
}
+3 -1
View File
@@ -14,7 +14,9 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithBundle:(NSBundle *)bundle;
- (void)startListeningWithCompletion:(void (^)(BOOL))completionBlock;
@property (nonatomic, readonly) BOOL terminated;
- (void)startListeningWithCompletion:(void (^)(void))completionBlock;
@end
+42 -29
View File
@@ -10,14 +10,16 @@
@interface TerminationListener ()
@property (nonatomic, readonly) NSRunningApplication *runningApplication;
@property (nonatomic, copy) void (^completionBlock)(BOOL);
@property (nonatomic, readonly) NSBundle *bundle;
@property (nonatomic) NSRunningApplication *listeningApplication;
@property (nonatomic, copy) void (^completionBlock)(void);
@end
@implementation TerminationListener
@synthesize runningApplication = _runningApplication;
@synthesize bundle = _bundle;
@synthesize listeningApplication = _listeningApplication;
@synthesize completionBlock = _completionBlock;
- (instancetype)initWithBundle:(NSBundle *)bundle
@@ -26,47 +28,58 @@
return nil;
}
NSString *bundlePath = bundle.bundlePath;
NSString *bundleIdentifier = bundle.bundleIdentifier;
NSArray *runningApplications =
(bundleIdentifier != nil) ?
[NSRunningApplication runningApplicationsWithBundleIdentifier:bundleIdentifier] :
[[NSWorkspace sharedWorkspace] runningApplications];
for (NSRunningApplication *runningApplication in runningApplications) {
// Comparing the URLs hasn't worked well for me in practice, so I'm comparing the file paths instead
if ([runningApplication.bundleURL.path isEqualToString:bundlePath]) {
_runningApplication = runningApplication;
break;
}
}
_bundle = bundle;
return self;
}
- (void)cleanupWithSuccess:(BOOL)success completion:(void (^)(BOOL))completionBlock
// Don't cache the running application instance because it can change later any number of times after initialization
// If for example, the user re-launches the application and we haven't started listening yet
- (NSRunningApplication *)runningApplication
{
completionBlock(success);
NSString *bundlePath = self.bundle.bundlePath;
NSString *bundleIdentifier = self.bundle.bundleIdentifier;
NSArray *runningApplications =
(bundleIdentifier != nil) ?
[NSRunningApplication runningApplicationsWithBundleIdentifier:bundleIdentifier] :
[[NSWorkspace sharedWorkspace] runningApplications];
for (NSRunningApplication *runningApplication in runningApplications) {
// Comparing the URLs hasn't worked well for me in practice, so I'm comparing the file paths instead
if ([runningApplication.bundleURL.path isEqualToString:bundlePath]) {
return runningApplication;
}
}
return nil;
}
- (void)startListeningWithCompletion:(void (^)(BOOL))completionBlock
- (BOOL)terminated
{
BOOL alreadyTerminated = (self.runningApplication == nil || self.runningApplication.isTerminated);
if (alreadyTerminated) {
[self cleanupWithSuccess:YES completion:completionBlock];
NSRunningApplication *runningApplication = [self runningApplication];
return (runningApplication == nil || runningApplication.isTerminated);
}
- (void)startListeningWithCompletion:(void (^)(void))completionBlock
{
NSRunningApplication *runningApplication = [self runningApplication];
if (runningApplication == nil || runningApplication.terminated) {
completionBlock();
} else {
self.completionBlock = completionBlock;
[self.runningApplication addObserver:self forKeyPath:NSStringFromSelector(@selector(isTerminated)) options:NSKeyValueObservingOptionNew context:NULL];
// We must strongly reference the listening application, so it doesn't deallocate while we have KVO observer to it
self.listeningApplication = runningApplication;
[self.listeningApplication addObserver:self forKeyPath:NSStringFromSelector(@selector(isTerminated)) options:NSKeyValueObservingOptionNew context:NULL];
}
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)__unused change context:(void *)__unused context
{
if (object == self.runningApplication && [keyPath isEqualToString:NSStringFromSelector(@selector(isTerminated))]) {
if (self.runningApplication.isTerminated) {
[self.runningApplication removeObserver:self forKeyPath:keyPath];
[self cleanupWithSuccess:YES completion:self.completionBlock];
if (object == self.listeningApplication && [keyPath isEqualToString:NSStringFromSelector(@selector(isTerminated))]) {
if (self.listeningApplication.terminated) {
[self.listeningApplication removeObserver:self forKeyPath:keyPath];
self.completionBlock();
self.completionBlock = nil;
}
}
+10 -8
View File
@@ -22,7 +22,7 @@
@property (nonatomic, readonly) SUCoreBasedUpdateDriver *coreDriver;
@property (nonatomic) BOOL foundCriticalUpdate;
@property (nonatomic) BOOL canInstallSilently;
@property (nonatomic) BOOL willInstallSilently;
@end
@@ -30,7 +30,7 @@
@synthesize coreDriver = _coreDriver;
@synthesize foundCriticalUpdate = _foundCriticalUpdate;
@synthesize canInstallSilently = _canInstallSilently;
@synthesize willInstallSilently = _willInstallSilently;
- (instancetype)initWithHost:(SUHost *)host sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater updaterDelegate:(nullable id <SUUpdaterDelegate>)updaterDelegate
{
@@ -60,18 +60,20 @@
[self.coreDriver downloadUpdateFromAppcastItem:updateItem];
}
- (void)installerDidFinishPreparationAndCanInstallSilently:(BOOL)canInstallSilently
- (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately silently:(BOOL)willInstallSilently
{
self.canInstallSilently = canInstallSilently;
self.willInstallSilently = willInstallSilently;
// We are done and can safely abort now
// The installer tool will keep the installation alive
[self abortUpdate];
if (!willInstallImmediately) {
// We are done and can safely abort now
// The installer tool will keep the installation alive
[self abortUpdate];
}
}
- (BOOL)basicDriverShouldSignalShowingUpdateImmediately
{
return (!self.canInstallSilently || self.foundCriticalUpdate);
return (!self.willInstallSilently || self.foundCriticalUpdate);
}
- (void)basicDriverIsRequestingAbortUpdateWithError:(NSError *)error
+4 -2
View File
@@ -19,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem;
- (void)installerDidFinishPreparationAndCanInstallSilently:(BOOL)canInstallSilently;
- (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately silently:(BOOL)willInstallSilently;
- (void)coreDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error;
@@ -43,7 +43,9 @@ NS_ASSUME_NONNULL_BEGIN
- (void)installerDidExtractUpdateWithProgress:(double)progress;
- (void)coreDriverIsRequestingAppTermination;
- (void)installerIsRequestingAppTermination;
- (void)installerDidFinishInstallation;
@end
+17 -6
View File
@@ -193,9 +193,9 @@
}
}
- (void)installerDidFinishPreparationAndCanInstallSilently:(BOOL)canInstallSilently
- (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately silently:(BOOL)willInstallSilently
{
[self.delegate installerDidFinishPreparationAndCanInstallSilently:canInstallSilently];
[self.delegate installerDidFinishPreparationAndWillInstallImmediately:willInstallImmediately silently:willInstallSilently];
}
- (void)finishInstallationWithResponse:(SUInstallUpdateStatus)installUpdateStatus
@@ -213,20 +213,31 @@
}
}
- (void)installerIsRequestingAppTermination
- (void)installerWillFinishInstallation
{
if ([self.updaterDelegate respondsToSelector:@selector(updater:willInstallUpdate:)]) {
[self.updaterDelegate updater:self.updater willInstallUpdate:self.updateItem];
}
#warning should only notify if we are really about to restart the target...
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterWillRestartNotification object:self];
if ([self.updaterDelegate respondsToSelector:@selector(updaterWillRelaunchApplication:)]) {
[self.updaterDelegate updaterWillRelaunchApplication:self.updater];
}
}
- (void)installerDidFinishInstallation
{
if ([self.delegate respondsToSelector:@selector(installerDidFinishInstallation)]) {
[self.delegate installerDidFinishInstallation];
}
}
- (void)installerIsRequestingAppTermination
{
// If they don't respond or do anything, we'll just install after the user terminates the app anyway
if ([self.delegate respondsToSelector:@selector(coreDriverIsRequestingAppTermination)]) {
[self.delegate coreDriverIsRequestingAppTermination];
if ([self.delegate respondsToSelector:@selector(installerIsRequestingAppTermination)]) {
[self.delegate installerIsRequestingAppTermination];
}
}
+3 -1
View File
@@ -17,8 +17,10 @@ NS_ASSUME_NONNULL_BEGIN
- (void)installerDidStartInstalling;
- (void)installerDidExtractUpdateWithProgress:(double)progress;
- (void)installerDidFinishPreparationAndCanInstallSilently:(BOOL)canInstallSilently;
- (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately silently:(BOOL)willInstallSilently;
- (void)installerIsRequestingAppTermination;
- (void)installerWillFinishInstallation;
- (void)installerDidFinishInstallation;
- (void)installerIsRequestingAbortInstallWithError:(nullable NSError *)error;
- (void)installerDidFailToApplyDeltaUpdate;
+31 -4
View File
@@ -37,6 +37,7 @@
@property (nonatomic, readonly) NSBundle *sparkleBundle;
@property (nonatomic, weak, readonly) id<SUInstallerDriverDelegate> delegate;
@property (nonatomic) SUInstallerMessageType currentStage;
@property (nonatomic) BOOL startedInstalling;
@property (nonatomic) SULocalMessagePort *localPort;
@property (nonatomic) id <SURemoteMessagePort> remotePort;
@property (nonatomic) BOOL postponedOnce;
@@ -56,6 +57,7 @@
@synthesize sparkleBundle = _sparkleBundle;
@synthesize delegate = _delegate;
@synthesize currentStage = _currentStage;
@synthesize startedInstalling = _startedInstalling;
@synthesize localPort = _localPort;
@synthesize remotePort = _remotePort;
@synthesize postponedOnce = _postponedOnce;
@@ -303,6 +305,7 @@
} else if (identifier == SUInstallationStartedStage1) {
self.currentStage = identifier;
[self.delegate installerDidStartInstalling];
self.startedInstalling = YES;
} else if (identifier == SUInstallationFinishedStage1) {
self.currentStage = identifier;
@@ -322,21 +325,45 @@
}
BOOL canInstallSilently = NO;
if (data.length == sizeof(uint8_t)) {
if (data.length >= sizeof(uint8_t)) {
canInstallSilently = (BOOL)*(const uint8_t *)data.bytes;
}
[self.delegate installerDidFinishPreparationAndCanInstallSilently:canInstallSilently];
BOOL hasTargetTerminated = NO;
if (data.length >= sizeof(uint8_t) * 2) {
hasTargetTerminated = (BOOL)*((const uint8_t *)data.bytes + 1);
}
[self.delegate installerDidFinishPreparationAndWillInstallImmediately:(hasTargetTerminated && canInstallSilently) silently:canInstallSilently];
} else if (identifier == SUInstallationFinishedStage2) {
// Don't have to store current stage because we're severing our connection to the installer
self.currentStage = identifier;
if (!self.startedInstalling) {
// It's possible we can start from resuming to stage 2 rather than doing stage 1 again, so we should notify to start installing if we haven't done so already
self.startedInstalling = YES;
[self.delegate installerDidStartInstalling];
}
BOOL hasTargetTerminated = NO;
if (data.length >= sizeof(uint8_t)) {
hasTargetTerminated = (BOOL)*(const uint8_t *)data.bytes;
}
[self.remotePort invalidate];
self.remotePort = nil;
[self.delegate installerWillFinishInstallation];
if (!hasTargetTerminated) {
[self.delegate installerIsRequestingAppTermination];
}
} else if (identifier == SUInstallationFinishedStage3) {
self.currentStage = identifier;
[self.localPort invalidate];
self.localPort = nil;
[self.delegate installerIsRequestingAppTermination];
[self.delegate installerDidFinishInstallation];
[self.delegate installerIsRequestingAbortInstallWithError:nil];
}
}
+13 -1
View File
@@ -160,7 +160,7 @@
#pragma mark Install & Relaunch Update
- (void)showExtractionFinishedAndReadyToInstallAndRelaunch:(void (^)(SUInstallUpdateStatus))installUpdateHandler
- (void)showReadyToInstallAndRelaunch:(void (^)(SUInstallUpdateStatus))installUpdateHandler
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.statusController beginActionWithTitle:SULocalizedString(@"Ready to Install", nil) maxProgressValue:1.0 statusText:nil];
@@ -349,11 +349,23 @@
});
}
- (void)showUpdateInstallationDidFinish
{
//...
}
#pragma mark Aborting Everything
- (void)terminateApplication
{
dispatch_async(dispatch_get_main_queue(), ^{
// if a user chooses to NOT relaunch the app (as is the case with WebKit
// when it asks you if you are sure you want to close the app with multiple
// tabs open), the status window still stays on the screen and obscures
// other windows; with this fix, it doesn't
[self.statusController close];
self.statusController = nil;
[[NSApplication sharedApplication] terminate:nil];
});
}
+15 -13
View File
@@ -95,6 +95,7 @@
if (!self.resumingUpdate) {
[self.coreDriver downloadUpdateFromAppcastItem:updateItem];
} else {
#warning why should we have to relaunch??
[self.coreDriver finishInstallationWithResponse:SUInstallAndRelaunchUpdateNow];
}
break;
@@ -156,24 +157,25 @@
[self.userDriver showExtractionReceivedProgress:progress];
}
- (void)installerDidFinishPreparationAndCanInstallSilently:(BOOL)__unused canInstallSilently
- (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately silently:(BOOL)__unused willInstallSilently
{
[self.userDriver showExtractionFinishedAndReadyToInstallAndRelaunch:^(SUInstallUpdateStatus installUpdateStatus) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.coreDriver finishInstallationWithResponse:installUpdateStatus];
});
}];
if (!willInstallImmediately) {
[self.userDriver showReadyToInstallAndRelaunch:^(SUInstallUpdateStatus installUpdateStatus) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.coreDriver finishInstallationWithResponse:installUpdateStatus];
});
}];
}
}
- (void)coreDriverIsRequestingAppTermination
- (void)installerIsRequestingAppTermination
{
[self.userDriver terminateApplication];
// if a user chooses to NOT relaunch the app (as is the case with WebKit
// when it asks you if you are sure you want to close the app with multiple
// tabs open), the status window still stays on the screen and obscures
// other windows; with this fix, it doesn't
[self.userDriver dismissUpdateInstallation];
}
- (void)installerDidFinishInstallation
{
[self.userDriver showUpdateInstallationDidFinish];
}
- (BOOL)basicDriverShouldSignalShowingUpdateImmediately
+6 -8
View File
@@ -222,6 +222,10 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
if ([self.host objectForUserDefaultsKey:SUEnableAutomaticChecksKey]) {
shouldPrompt = NO;
}
// If the developer wants to check for updates, we shouldn't bug the user about a prompt yet
else if (self.preStartedScheduledUpdateBlock != nil) {
shouldPrompt = NO;
}
// Does the delegate want to take care of the logic for when we should ask permission to update?
else if ([self.delegate respondsToSelector:@selector(updaterShouldPromptForPermissionToCheckForUpdates:)]) {
shouldPrompt = [self.delegate updaterShouldPromptForPermissionToCheckForUpdates:self];
@@ -253,14 +257,8 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
SUUpdater *strongSelf = weakSelf;
if (strongSelf != nil) {
[strongSelf updatePermissionPromptFinishedWithResult:result];
if (strongSelf.preStartedScheduledUpdateBlock != nil) {
strongSelf.preStartedScheduledUpdateBlock();
strongSelf.preStartedScheduledUpdateBlock = nil;
} else {
// Schedule checks, but make sure we ignore the delayed call from KVO
[strongSelf resetUpdateCycle];
}
// Schedule checks, but make sure we ignore the delayed call from KVO
[strongSelf resetUpdateCycle];
}
});
}];
+18 -5
View File
@@ -216,9 +216,10 @@ NS_ASSUME_NONNULL_BEGIN
- (void)showExtractionReceivedProgress:(double)progress;
/*!
* Show the user that the update finished extracting and is ready to install
* Show the user that the update is ready to install
*
* Let the user know that the update is ready and ask them whether they want to install or not
* Let the user know that the update is ready and ask them whether they want to install or not.
* Note if the target application is already terminated and an update can be performed silently, this method may not be invoked.
*
* @param installUpdateHandler A reply of SUInstallAndRelaunchUpdateNow installs the update immediately.
* A reply of SUDismissUpdateInstallation dismisses the update installation. Note the update may still be installed after
@@ -226,7 +227,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* This can be called from any thread
*/
- (void)showExtractionFinishedAndReadyToInstallAndRelaunch:(void (^)(SUInstallUpdateStatus))installUpdateHandler;
- (void)showReadyToInstallAndRelaunch:(void (^)(SUInstallUpdateStatus))installUpdateHandler;
/*!
* Show the user that the update is installing
@@ -240,13 +241,25 @@ NS_ASSUME_NONNULL_BEGIN
/*!
* Terminate the application
*
* Sparkle is signaling that it wants the application to be terminated immediately.
* If an implementor has already delayed application termination, now would be the appropriate time to stop.
* Sparkle is signaling that it wants the application to request for application termination.
* Care should be taken if the request for application termination fails or is delayed.
* Eg: may want to hide installation status windows in case termination doesn't happen right away
*
* This can be called from any thread
*/
- (void)terminateApplication;
/*!
* Show the user that the update installation finished
*
* Let the user know that the update finished installing.
* This will only be invoked if the updater process is still alive, which is typically not the case if
* the updater's lifetime is tied to the application it is updating.
*
* This can be called from any thread
*/
- (void)showUpdateInstallationDidFinish;
/*!
* Dismiss the current update installation
*
+11 -1
View File
@@ -188,7 +188,7 @@
#pragma mark Install & Relaunch Update
- (void)showExtractionFinishedAndReadyToInstallAndRelaunch:(void (^)(SUInstallUpdateStatus))installUpdateHandler
- (void)showReadyToInstallAndRelaunch:(void (^)(SUInstallUpdateStatus))installUpdateHandler
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.coreComponent registerInstallUpdateHandler:installUpdateHandler];
@@ -303,11 +303,21 @@
});
}
- (void)showUpdateInstallationDidFinish
{
dispatch_async(dispatch_get_main_queue(), ^{
[self addUpdateButtonWithTitle:@"Installation Finished!"];
});
}
#pragma mark Aborting Everything
- (void)terminateApplication
{
dispatch_async(dispatch_get_main_queue(), ^{
// In case our termination request fails or is delayed
[self removeUpdateButton];
[[NSApplication sharedApplication] terminate:nil];
});
}
+3 -1
View File
@@ -49,10 +49,12 @@
- (void)showExtractionReceivedProgress:(double)__unused progress {}
- (void)showExtractionFinishedAndReadyToInstallAndRelaunch:(void (^)(SUInstallUpdateStatus))__unused installUpdateHandler {}
- (void)showReadyToInstallAndRelaunch:(void (^)(SUInstallUpdateStatus))__unused installUpdateHandler {}
- (void)showInstallingUpdate {}
- (void)showUpdateInstallationDidFinish {}
- (void)dismissUpdateInstallation {}
- (void)terminateApplication {}
+3 -2
View File
@@ -42,13 +42,14 @@
- (void)applicationDidFinishLaunching:(NSNotification *)__unused aNotification
{
// Kick off a scheduled update check once we start the updater later
[self.updater checkForUpdates];
NSError *updaterError = nil;
if (![self.updater startUpdater:&updaterError]) {
printf("Error: Failed to initialize updater with error (%ld): %s\n", updaterError.code, updaterError.localizedDescription.UTF8String);
exit(EXIT_FAILURE);
}
[self.updater checkForUpdates];
}
@end
+9 -2
View File
@@ -66,7 +66,7 @@
- (void)requestUpdatePermissionWithSystemProfile:(NSArray *)__unused systemProfile reply:(void (^)(SUUpdatePermissionPromptResult *))__unused reply
{
dispatch_async(dispatch_get_main_queue(), ^{
printf("Asked about making update permission decision.. Aborting because I do not want to make this decision.");
printf("Asked about making update permission decision.. Aborting because I do not want to make this decision.\n");
exit(EXIT_FAILURE);
});
}
@@ -154,7 +154,7 @@
});
}
- (void)showExtractionFinishedAndReadyToInstallAndRelaunch:(void (^)(SUInstallUpdateStatus))installUpdateHandler
- (void)showReadyToInstallAndRelaunch:(void (^)(SUInstallUpdateStatus))installUpdateHandler
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.coreComponent registerInstallUpdateHandler:installUpdateHandler];
@@ -169,6 +169,13 @@
});
}
- (void)showUpdateInstallationDidFinish
{
dispatch_async(dispatch_get_main_queue(), ^{
printf("Installation Finished...\n");
});
}
- (void)dismissUpdateInstallation
{
dispatch_async(dispatch_get_main_queue(), ^{