mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-28 05:14:34 +00:00
Add updater delegate method for installing & relaunching new update
This commit is contained in:
1 parent
9881476008
commit
998a349617
5 files changed
+70
-14
No files matched your search
Vendored
+35
-7
@@ -20,22 +20,28 @@
|
||||
|
||||
@interface SUAutomaticUpdateDriver () <SUCoreBasedUpdateDriverDelegate>
|
||||
|
||||
@property (nonatomic, readonly, weak) id updater;
|
||||
@property (nonatomic, readonly, weak, nullable) id updaterDelegate;
|
||||
@property (nonatomic, readonly) SUCoreBasedUpdateDriver *coreDriver;
|
||||
@property (nonatomic) BOOL foundCriticalUpdate;
|
||||
@property (nonatomic) SUAppcastItem* updateItem;
|
||||
@property (nonatomic) BOOL willInstallSilently;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUAutomaticUpdateDriver
|
||||
|
||||
@synthesize updater = _updater;
|
||||
@synthesize updaterDelegate = _updaterDelegate;
|
||||
@synthesize coreDriver = _coreDriver;
|
||||
@synthesize foundCriticalUpdate = _foundCriticalUpdate;
|
||||
@synthesize updateItem = _updateItem;
|
||||
@synthesize willInstallSilently = _willInstallSilently;
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater updaterDelegate:(nullable id <SUUpdaterDelegate>)updaterDelegate
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_updater = updater;
|
||||
_updaterDelegate = updaterDelegate;
|
||||
_coreDriver = [[SUCoreBasedUpdateDriver alloc] initWithHost:host sparkleBundle:sparkleBundle updater:updater updaterDelegate:updaterDelegate delegate:self];
|
||||
}
|
||||
return self;
|
||||
@@ -55,7 +61,7 @@
|
||||
|
||||
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem
|
||||
{
|
||||
self.foundCriticalUpdate = [updateItem isCriticalUpdate];
|
||||
self.updateItem = updateItem;
|
||||
|
||||
[self.coreDriver downloadUpdateFromAppcastItem:updateItem];
|
||||
}
|
||||
@@ -65,15 +71,37 @@
|
||||
self.willInstallSilently = willInstallSilently;
|
||||
|
||||
if (!willInstallImmediately) {
|
||||
// We are done and can safely abort now
|
||||
// The installer tool will keep the installation alive
|
||||
[self abortUpdate];
|
||||
BOOL installationHandledByDelegate = NO;
|
||||
id<SUUpdaterDelegate> updaterDelegate = self.updaterDelegate;
|
||||
if (self.willInstallSilently && [updaterDelegate respondsToSelector:@selector(updater:willInstallUpdateOnQuit:immediateInstallationBlock:)]) {
|
||||
__weak SUAutomaticUpdateDriver *weakSelf = self;
|
||||
installationHandledByDelegate =
|
||||
[updaterDelegate updater:self.updater willInstallUpdateOnQuit:self.updateItem immediateInstallationBlock:^{
|
||||
[weakSelf.coreDriver finishInstallationWithResponse:SUInstallAndRelaunchUpdateNow displayingUserInterface:NO];
|
||||
}];
|
||||
}
|
||||
|
||||
if (!installationHandledByDelegate) {
|
||||
// We are done and can safely abort now
|
||||
// The installer tool will keep the installation alive
|
||||
[self abortUpdate];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This can only be reached if the updater delegate invokes its immediate installation block above,
|
||||
// otherwise the update driver will abort the update before then
|
||||
- (void)installerIsRequestingAppTermination
|
||||
{
|
||||
id<SUUpdaterDelegate> updaterDelegate = self.updaterDelegate;
|
||||
if ([updaterDelegate respondsToSelector:@selector(updaterIsRequestingQuit:)]) {
|
||||
[updaterDelegate updaterIsRequestingQuit:self.updater];
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)basicDriverShouldSignalShowingUpdateImmediately
|
||||
{
|
||||
return (!self.willInstallSilently || self.foundCriticalUpdate);
|
||||
return (!self.willInstallSilently || self.updateItem.isCriticalUpdate);
|
||||
}
|
||||
|
||||
- (void)basicDriverIsRequestingAbortUpdateWithError:(NSError *)error
|
||||
|
||||
Vendored
+1
-1
@@ -59,7 +59,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (void)downloadUpdateFromAppcastItem:(SUAppcastItem *)updateItem;
|
||||
|
||||
- (void)finishInstallationWithResponse:(SUInstallUpdateStatus)installUpdateStatus;
|
||||
- (void)finishInstallationWithResponse:(SUInstallUpdateStatus)installUpdateStatus displayingUserInterface:(BOOL)displayingUserInterface;
|
||||
|
||||
- (void)abortUpdateWithError:(nullable NSError *)error;
|
||||
|
||||
|
||||
Vendored
+3
-3
@@ -183,17 +183,17 @@
|
||||
[self.delegate installerDidFinishPreparationAndWillInstallImmediately:willInstallImmediately silently:willInstallSilently];
|
||||
}
|
||||
|
||||
- (void)finishInstallationWithResponse:(SUInstallUpdateStatus)installUpdateStatus
|
||||
- (void)finishInstallationWithResponse:(SUInstallUpdateStatus)installUpdateStatus displayingUserInterface:(BOOL)displayingUserInterface
|
||||
{
|
||||
switch (installUpdateStatus) {
|
||||
case SUDismissUpdateInstallation:
|
||||
[self.delegate coreDriverIsRequestingAbortUpdateWithError:nil];
|
||||
break;
|
||||
case SUInstallUpdateNow:
|
||||
[self.installerDriver installWithToolAndRelaunch:NO displayingUserInterface:YES];
|
||||
[self.installerDriver installWithToolAndRelaunch:NO displayingUserInterface:displayingUserInterface];
|
||||
break;
|
||||
case SUInstallAndRelaunchUpdateNow:
|
||||
[self.installerDriver installWithToolAndRelaunch:YES displayingUserInterface:YES];
|
||||
[self.installerDriver installWithToolAndRelaunch:YES displayingUserInterface:displayingUserInterface];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -98,7 +98,7 @@
|
||||
[self.userDriver showResumableUpdateFoundWithAppcastItem:updateItem reply:^(SUInstallUpdateStatus choice) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey];
|
||||
[self.coreDriver finishInstallationWithResponse:choice];
|
||||
[self.coreDriver finishInstallationWithResponse:choice displayingUserInterface:YES];
|
||||
});
|
||||
}];
|
||||
}
|
||||
@@ -167,7 +167,7 @@
|
||||
if (!willInstallImmediately) {
|
||||
[self.userDriver showReadyToInstallAndRelaunch:^(SUInstallUpdateStatus installUpdateStatus) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.coreDriver finishInstallationWithResponse:installUpdateStatus];
|
||||
[self.coreDriver finishInstallationWithResponse:installUpdateStatus displayingUserInterface:YES];
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
Vendored
+29
-1
@@ -290,8 +290,36 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey;
|
||||
\param updater The SUUpdater instance.
|
||||
\param item The appcast item corresponding to the update that is proposed to be installed.
|
||||
\param invocation Can be used to trigger an immediate silent install and relaunch.
|
||||
|
||||
\deprecated See -updater:willInstallUpdateOnQuit:immediateInstallationBlock: and -updaterIsRequestingQuit: instead. This method is no longer invoked.
|
||||
*/
|
||||
- (void)updater:(SUUpdater *)updater willInstallUpdateOnQuit:(SUAppcastItem *)item immediateInstallationInvocation:(NSInvocation *)invocation;
|
||||
- (void)updater:(SUUpdater *)updater willInstallUpdateOnQuit:(SUAppcastItem *)item immediateInstallationInvocation:(NSInvocation *)invocation __deprecated;
|
||||
|
||||
/*!
|
||||
Called when an update is scheduled to be silently installed on quit after downloading the update automatically.
|
||||
|
||||
\param updater The SUUpdater instance.
|
||||
\param item The appcast item corresponding to the update that is proposed to be installed.
|
||||
\param immediateInstallHandler The install handler to immediately install the update.
|
||||
If you plan to invoke this, you must return YES from this method and also implement -updaterIsRequestingQuit:
|
||||
\return Return YES if the delegate will handle installing the update or NO if the updater should be given responsibility.
|
||||
|
||||
If the updater is given responsibility, it can later remind the user an update is available if they have not terminated the application for a long time.
|
||||
Also if the updater is given responsibility and the update item is marked critical, the new update will be presented to the user immediately after.
|
||||
Even if the immediateInstallHandler is not invoked, the installer will attempt to install the update on termination.
|
||||
*/
|
||||
- (BOOL)updater:(SUUpdater *)updater willInstallUpdateOnQuit:(SUAppcastItem *)item immediateInstallationBlock:(void (^)(void))immediateInstallHandler;
|
||||
|
||||
/*!
|
||||
Called when the updater requests to quit the application after the delegate invoked its installation block from -updater:willInstallUpdateOnQuit:immediateInstallationBlock:
|
||||
|
||||
\param updater the SUUpdater instance.
|
||||
|
||||
The delegate should terminate the application so the installer can immediately install the update.
|
||||
After the application is terminated, the installer will install the update and the application will be relaunched.
|
||||
The installer will not show any UI interaction.
|
||||
*/
|
||||
- (void)updaterIsRequestingQuit:(SUUpdater *)updater;
|
||||
|
||||
/*!
|
||||
Calls after an update that was scheduled to be silently installed on quit has been canceled.
|
||||
|
||||
Reference in new issue
Block a user