Clean up code relating to interactive pkg installations (#2803)

This commit is contained in:
Zorg authored and GitHub committed 2025-11-15 17:25:42 -08:00
1 parent fc7350329e
commit a5401bbf3f
16 files changed
+42 -76

No files matched your search

+16 -28
View File
@@ -599,7 +599,7 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
} else if (identifier == SPUSentUpdateAppcastItemData) {
SUAppcastItem *updateItem = (data != nil) ? (SUAppcastItem *)SPUUnarchiveRootObjectSecurely(data, [SUAppcastItem class]) : nil;
if (updateItem != nil) {
SPUInstallationInfo *installationInfo = [[SPUInstallationInfo alloc] initWithAppcastItem:updateItem canSilentlyInstall:[_installer canInstallSilently]];
SPUInstallationInfo *installationInfo = [[SPUInstallationInfo alloc] initWithAppcastItem:updateItem];
NSData *archivedData = SPUArchiveRootObjectSecurely(installationInfo);
if (archivedData != nil) {
@@ -612,7 +612,7 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
uint8_t showsUI = *((const uint8_t *)data.bytes + 1);
dispatch_async(dispatch_get_main_queue(), ^{
// This flag has an impact on interactive type installations and showing UI progress during non-interactive installations
// This flag has an impact on showing UI progress during installations
self->_shouldShowUI = (BOOL)showsUI;
// Don't test if the application was alive initially, leave that to the progress agent if we decide to relaunch
self->_shouldRelaunch = (BOOL)relaunch;
@@ -679,8 +679,6 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
return;
}
uint8_t canPerformSilentInstall = (uint8_t)[installer canInstallSilently];
dispatch_async(dispatch_get_main_queue(), ^{
self->_installer = installer;
@@ -688,9 +686,9 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
self->_performedStage1Installation = YES;
os_unfair_lock_unlock(&self->_newConnectionLock);
uint8_t sendInformation[] = {canPerformSilentInstall, (uint8_t)self->_targetTerminated};
uint8_t targetTerminated = (uint8_t)self->_targetTerminated;
NSData *sendData = [NSData dataWithBytes:sendInformation length:sizeof(sendInformation)];
NSData *sendData = [NSData dataWithBytes:&targetTerminated length:sizeof(targetTerminated)];
[self->_communicator handleMessageWithIdentifier:SPUInstallationFinishedStage1 data:sendData];
@@ -705,37 +703,27 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
- (void)performStage2Installation SPU_OBJC_DIRECT
{
BOOL canPerformSecondStage = _shouldShowUI || [_installer canInstallSilently];
if (canPerformSecondStage) {
_performedStage2Installation = YES;
_performedStage2Installation = YES;
dispatch_async(dispatch_get_main_queue(), ^{
uint8_t targetTerminated = (uint8_t)self->_targetTerminated;
dispatch_async(dispatch_get_main_queue(), ^{
uint8_t targetTerminated = (uint8_t)self->_targetTerminated;
NSData *sendData = [NSData dataWithBytes:&targetTerminated length:sizeof(targetTerminated)];
[self->_communicator handleMessageWithIdentifier:SPUInstallationFinishedStage2 data:sendData];
// Don't check if the target is already terminated, leave that to the progress agent
// We could be slightly off if there were multiple instances running
[self->_agentConnection.agent sendTerminationSignal];
});
} else {
_installer = nil;
NSData *sendData = [NSData dataWithBytes:&targetTerminated length:sizeof(targetTerminated)];
[self->_communicator handleMessageWithIdentifier:SPUInstallationFinishedStage2 data:sendData];
dispatch_async(dispatch_get_main_queue(), ^{
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Error: Failed to resume installer on stage 2 because installation cannot be installed silently" }]];
});
}
// Don't check if the target is already terminated, leave that to the progress agent
// We could be slightly off if there were multiple instances running
[self->_agentConnection.agent sendTerminationSignal];
});
}
- (void)finishInstallationAfterHostTermination SPU_OBJC_DIRECT
{
assert(self->_targetTerminated);
// Show our installer progress UI tool if only after a certain amount of time passes,
// and if our installer is silent (i.e, doesn't show progress on its own)
// Show our installer progress UI tool if only after a certain amount of time passes
__block BOOL shouldShowUIProgress = YES;
if (self->_shouldShowUI && [self->_installer canInstallSilently]) {
if (self->_shouldShowUI) {
// Ask the updater if it is still alive
// If they are, we will receive a pong response back
// Reset if we received a pong just to be on the safe side
+1 -2
View File
@@ -14,10 +14,9 @@ NS_ASSUME_NONNULL_BEGIN
SPU_OBJC_DIRECT_MEMBERS @interface SPUInstallationInfo : NSObject <NSSecureCoding>
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem canSilentlyInstall:(BOOL)canSilentlyInstall;
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem;
@property (nonatomic, readonly) SUAppcastItem *appcastItem;
@property (nonatomic, readonly) BOOL canSilentlyInstall;
@property (nonatomic) BOOL systemDomain;
+8 -8
View File
@@ -19,23 +19,21 @@ static NSString *SUSystemDomainKey = @"SUSystemDomain";
@implementation SPUInstallationInfo
@synthesize appcastItem = _appcastItem;
@synthesize canSilentlyInstall = _canSilentlyInstall;
@synthesize systemDomain = _systemDomain;
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem canSilentlyInstall:(BOOL)canSilentlyInstall systemDomain:(BOOL)systemDomain
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem systemDomain:(BOOL)systemDomain
{
self = [super init];
if (self != nil) {
_appcastItem = appcastItem;
_canSilentlyInstall = canSilentlyInstall;
_systemDomain = systemDomain;
}
return self;
}
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem canSilentlyInstall:(BOOL)canSilentlyInstall
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem
{
return [self initWithAppcastItem:appcastItem canSilentlyInstall:canSilentlyInstall systemDomain:NO];
return [self initWithAppcastItem:appcastItem systemDomain:NO];
}
- (nullable instancetype)initWithCoder:(NSCoder *)decoder
@@ -45,16 +43,18 @@ static NSString *SUSystemDomainKey = @"SUSystemDomain";
return nil;
}
BOOL canSilentlyInstall = [decoder decodeBoolForKey:SUCanSilentlyInstallKey];
BOOL systemDomain = [decoder decodeBoolForKey:SUSystemDomainKey];
return [self initWithAppcastItem:appcastItem canSilentlyInstall:canSilentlyInstall systemDomain:systemDomain];
return [self initWithAppcastItem:appcastItem systemDomain:systemDomain];
}
- (void)encodeWithCoder:(NSCoder *)coder
{
[coder encodeObject:_appcastItem forKey:SUAppcastItemKey];
[coder encodeBool:_canSilentlyInstall forKey:SUCanSilentlyInstallKey];
[coder encodeBool:_systemDomain forKey:SUSystemDomainKey];
// Installation types can always be silently installed for newer versions of Sparkle
// Still encode this key to maintain backwards compatibility with older Sparkle clients
[coder encodeBool:YES forKey:SUCanSilentlyInstallKey];
}
+ (BOOL)supportsSecureCoding
-5
View File
@@ -82,11 +82,6 @@
{
}
- (BOOL)canInstallSilently
{
return YES;
}
@end
#endif
-5
View File
@@ -28,11 +28,6 @@ NS_ASSUME_NONNULL_BEGIN
// Should be able to be called from any thread
- (void)performCleanup;
// Indicates whether or not this installer can install the update silently in the background, without hindering the user
// If this returns NO, then the installation can fail if the user did not directly request for the install to occur.
// Should be thread safe
- (BOOL)canInstallSilently;
@end
NS_ASSUME_NONNULL_END
-5
View File
@@ -406,9 +406,4 @@
}
}
- (BOOL)canInstallSilently
{
return YES;
}
@end
+5 -5
View File
@@ -31,7 +31,7 @@
__weak id<SPUUserDriver> _userDriver;
__weak id _updaterDelegate;
BOOL _willInstallSilently;
BOOL _installerDidFinishPreparation;
}
- (instancetype)initWithHost:(SUHost *)host applicationBundle:(NSBundle *)applicationBundle updater:(id)updater userDriver:(id <SPUUserDriver>)userDriver updaterDelegate:(nullable id <SPUUpdaterDelegate>)updaterDelegate
@@ -95,14 +95,14 @@
return NO;
}
- (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately silently:(BOOL)willInstallSilently
- (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately
{
_willInstallSilently = willInstallSilently;
_installerDidFinishPreparation = YES;
if (!willInstallImmediately) {
BOOL installationHandledByDelegate = NO;
id<SPUUpdaterDelegate> updaterDelegate = _updaterDelegate;
if (_willInstallSilently && [updaterDelegate respondsToSelector:@selector(updater:willInstallUpdateOnQuit:immediateInstallationBlock:)]) {
if ([updaterDelegate respondsToSelector:@selector(updater:willInstallUpdateOnQuit:immediateInstallationBlock:)]) {
__weak __typeof__(self) weakSelf = self;
installationHandledByDelegate = [updaterDelegate updater:_updater willInstallUpdateOnQuit:_updateItem immediateInstallationBlock:^{
dispatch_async(dispatch_get_main_queue(), ^{
@@ -139,7 +139,7 @@
- (void)abortUpdateWithError:(NSError *)error
{
BOOL showNextUpdateImmediately = (error == nil || error.code == SUInstallationAuthorizeLaterError) && (!_willInstallSilently || _updateItem.criticalUpdate || _updateItem.isInformationOnlyUpdate);
BOOL showNextUpdateImmediately = (error == nil || error.code == SUInstallationAuthorizeLaterError) && (!_installerDidFinishPreparation || _updateItem.criticalUpdate || _updateItem.isInformationOnlyUpdate);
[_coreDriver abortUpdateAndShowNextUpdateImmediately:showNextUpdateImmediately error:error];
}
+1 -1
View File
@@ -20,7 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryAppcastItem;
- (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately silently:(BOOL)willInstallSilently;
- (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately;
- (void)coreDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error;
+2 -2
View File
@@ -295,9 +295,9 @@
}
}
- (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately silently:(BOOL)willInstallSilently
- (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately
{
[_delegate installerDidFinishPreparationAndWillInstallImmediately:willInstallImmediately silently:willInstallSilently];
[_delegate installerDidFinishPreparationAndWillInstallImmediately:willInstallImmediately];
}
- (void)finishInstallationWithResponse:(SPUUserUpdateChoice)response displayingUserInterface:(BOOL)displayingUserInterface
+1 -1
View File
@@ -11,7 +11,7 @@
#define SPUInstallationTypeApplication @"application" // the default installation type for ordinary application updates
#define SPUInstallationTypeGuidedPackage @"package" // the preferred installation type for package installations
#define SPUInstallationTypeInteractivePackage @"interactive-package" // the deprecated installation type; use guided package instead
#define SPUInstallationTypeInteractivePackage @"interactive-package" // removed installation type; use guided package instead
#define SPUInstallationTypesArray (@[SPUInstallationTypeApplication, SPUInstallationTypeGuidedPackage])
#define SPUValidInstallationType(x) ((x != nil) && [SPUInstallationTypesArray containsObject:(NSString * _Nonnull)x])
+1 -1
View File
@@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)installerDidStartInstallingWithApplicationTerminated:(BOOL)applicationTerminated;
- (void)installerDidStartExtracting;
- (void)installerDidExtractUpdateWithProgress:(double)progress;
- (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately silently:(BOOL)willInstallSilently;
- (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately;
- (void)installerWillFinishInstallationAndRelaunch:(BOOL)relaunch;
- (void)installerDidFinishInstallationAndRelaunched:(BOOL)relaunch acknowledgement:(void(^)(void))acknowledgement;
+3 -8
View File
@@ -342,17 +342,12 @@
SULog(SULogLevelError, @"Error: Archived data to send for appcast item is nil");
}
BOOL canInstallSilently = NO;
if (data.length >= sizeof(uint8_t)) {
canInstallSilently = (BOOL)*(const uint8_t *)data.bytes;
}
BOOL hasTargetTerminated = NO;
if (data.length >= sizeof(uint8_t) * 2) {
hasTargetTerminated = (BOOL)*((const uint8_t *)data.bytes + 1);
if (data.length >= sizeof(uint8_t)) {
hasTargetTerminated = (BOOL)*((const uint8_t *)data.bytes);
}
[delegate installerDidFinishPreparationAndWillInstallImmediately:hasTargetTerminated silently:canInstallSilently];
[delegate installerDidFinishPreparationAndWillInstallImmediately:hasTargetTerminated];
} else if (identifier == SPUInstallationFinishedStage2) {
_currentStage = identifier;
+1 -1
View File
@@ -355,7 +355,7 @@
[_userDriver showExtractionReceivedProgress:progress];
}
- (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately silently:(BOOL)__unused willInstallSilently
- (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately
{
if (!willInstallImmediately) {
[_userDriver showReadyToInstallAndRelaunch:^(SPUUserUpdateChoice choice) {
+1 -1
View File
@@ -524,7 +524,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
// Proceed as normal if there's no resumable updates
completionHandler(regularCheckInterval);
} else {
if (!installationInfo.canSilentlyInstall || [installationInfo.appcastItem isCriticalUpdate] || [installationInfo.appcastItem isInformationOnlyUpdate]) {
if ([installationInfo.appcastItem isCriticalUpdate] || [installationInfo.appcastItem isInformationOnlyUpdate]) {
completionHandler(MIN(regularCheckInterval, SUImpatientUpdateCheckInterval));
} else {
completionHandler(MAX(regularCheckInterval, SUImpatientUpdateCheckInterval));
+1 -2
View File
@@ -648,8 +648,7 @@ static NSString *SUAppcastItemDeltaFromSparkleLocalesKey = @"SUAppcastItemDeltaF
#if SPARKLE_BUILD_PACKAGE_SUPPORT
NSString *attributeInstallationType = [enclosure objectForKey:SUAppcastAttributeInstallationType];
if (attributeInstallationType == nil) {
// If we have a flat package, assume installation type is guided
// (flat / non-archived interactive packages are not supported anymore)
// If we have a bare package, assume installation type is guided package
// Otherwise assume we have a normal application inside an archive
if ([_fileURL.pathExtension isEqualToString:@"pkg"] || [_fileURL.pathExtension isEqualToString:@"mpkg"]) {
chosenInstallationType = SPUInstallationTypeGuidedPackage;
+1 -1
View File
@@ -45,7 +45,7 @@ static void printUsage(char **argv)
fprintf(stderr, " --%s\n List of allowed Sparkle channels to look for updates in. By default,\n only the default channel is used.\n", CHANNELS_FLAG);
fprintf(stderr, " --%s\n URL for appcast feed. This URL will be used for the feed instead of the one\n in the bundle's Info.plist or in the bundle's user defaults.\n", FEED_URL_FLAG);
fprintf(stderr, " --%s\n Display name that will be included as a part of the User-Agent string.\n We encourage setting this so developers know what is querying their feed.\n Otherwise, this value may be set and inferred automatically.\n", USER_AGENT_NAME);
fprintf(stderr, " --%s\n Allows prompting the user for an authorization dialog prompt if the\n installer needs elevated privileges, or allows performing an interactive\n installer package. Without passing this, an exit status of 3 is returned\n if an update requires user interaction. An exit status of 5 is returned\n if the user cancels the authorization prompt.\n", INTERACTIVE_FLAG);
fprintf(stderr, " --%s\n Allows prompting the user for an authorization dialog prompt if the\n installer needs elevated privileges.\n Without passing this, an exit status of 3 is returned if an update\n requires user interaction. An exit status of 5 is returned\n if the user cancels the authorization prompt.\n", INTERACTIVE_FLAG);
fprintf(stderr, " --%s\n If update permission is requested, this enables automatic update checks.\n Note that this behavior may overwrite the user's defaults for the bundle.\n This option has no effect if --%s is passed, or if the\n user has replied to this request already, or if the developer configured\n to skip it. Without passing this, an exit status of 6 is returned\n if permission is needed.\n", GRANT_AUTOMATIC_CHECKING_FLAG, CHECK_NOW_FLAG);
fprintf(stderr, " --%s\n Choose to send system profile information if update permission is requested.\n This option can only take effect if --%s is passed.\n", SEND_PROFILE_FLAG, GRANT_AUTOMATIC_CHECKING_FLAG);
fprintf(stderr, " --%s\n Defer installation until after the application terminates on its own. The\n application will not be relaunched unless the installation is resumed later.\n", DEFER_FLAG);