Skip to content

Commit a5401bb

Browse files
authored
Clean up code relating to interactive pkg installations (#2803)
1 parent fc73503 commit a5401bb

16 files changed

+42
-76
lines changed

Autoupdate/AppInstaller.m

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ - (void)handleMessageWithIdentifier:(int32_t)identifier data:(NSData *)data
599599
} else if (identifier == SPUSentUpdateAppcastItemData) {
600600
SUAppcastItem *updateItem = (data != nil) ? (SUAppcastItem *)SPUUnarchiveRootObjectSecurely(data, [SUAppcastItem class]) : nil;
601601
if (updateItem != nil) {
602-
SPUInstallationInfo *installationInfo = [[SPUInstallationInfo alloc] initWithAppcastItem:updateItem canSilentlyInstall:[_installer canInstallSilently]];
602+
SPUInstallationInfo *installationInfo = [[SPUInstallationInfo alloc] initWithAppcastItem:updateItem];
603603

604604
NSData *archivedData = SPUArchiveRootObjectSecurely(installationInfo);
605605
if (archivedData != nil) {
@@ -612,7 +612,7 @@ - (void)handleMessageWithIdentifier:(int32_t)identifier data:(NSData *)data
612612
uint8_t showsUI = *((const uint8_t *)data.bytes + 1);
613613

614614
dispatch_async(dispatch_get_main_queue(), ^{
615-
// This flag has an impact on interactive type installations and showing UI progress during non-interactive installations
615+
// This flag has an impact on showing UI progress during installations
616616
self->_shouldShowUI = (BOOL)showsUI;
617617
// Don't test if the application was alive initially, leave that to the progress agent if we decide to relaunch
618618
self->_shouldRelaunch = (BOOL)relaunch;
@@ -679,18 +679,16 @@ - (void)startInstallation SPU_OBJC_DIRECT
679679
return;
680680
}
681681

682-
uint8_t canPerformSilentInstall = (uint8_t)[installer canInstallSilently];
683-
684682
dispatch_async(dispatch_get_main_queue(), ^{
685683
self->_installer = installer;
686684

687685
os_unfair_lock_lock(&self->_newConnectionLock);
688686
self->_performedStage1Installation = YES;
689687
os_unfair_lock_unlock(&self->_newConnectionLock);
690688

691-
uint8_t sendInformation[] = {canPerformSilentInstall, (uint8_t)self->_targetTerminated};
689+
uint8_t targetTerminated = (uint8_t)self->_targetTerminated;
692690

693-
NSData *sendData = [NSData dataWithBytes:sendInformation length:sizeof(sendInformation)];
691+
NSData *sendData = [NSData dataWithBytes:&targetTerminated length:sizeof(targetTerminated)];
694692

695693
[self->_communicator handleMessageWithIdentifier:SPUInstallationFinishedStage1 data:sendData];
696694

@@ -705,37 +703,27 @@ - (void)startInstallation SPU_OBJC_DIRECT
705703

706704
- (void)performStage2Installation SPU_OBJC_DIRECT
707705
{
708-
BOOL canPerformSecondStage = _shouldShowUI || [_installer canInstallSilently];
709-
if (canPerformSecondStage) {
710-
_performedStage2Installation = YES;
706+
_performedStage2Installation = YES;
707+
708+
dispatch_async(dispatch_get_main_queue(), ^{
709+
uint8_t targetTerminated = (uint8_t)self->_targetTerminated;
711710

712-
dispatch_async(dispatch_get_main_queue(), ^{
713-
uint8_t targetTerminated = (uint8_t)self->_targetTerminated;
714-
715-
NSData *sendData = [NSData dataWithBytes:&targetTerminated length:sizeof(targetTerminated)];
716-
[self->_communicator handleMessageWithIdentifier:SPUInstallationFinishedStage2 data:sendData];
717-
718-
// Don't check if the target is already terminated, leave that to the progress agent
719-
// We could be slightly off if there were multiple instances running
720-
[self->_agentConnection.agent sendTerminationSignal];
721-
});
722-
} else {
723-
_installer = nil;
711+
NSData *sendData = [NSData dataWithBytes:&targetTerminated length:sizeof(targetTerminated)];
712+
[self->_communicator handleMessageWithIdentifier:SPUInstallationFinishedStage2 data:sendData];
724713

725-
dispatch_async(dispatch_get_main_queue(), ^{
726-
[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" }]];
727-
});
728-
}
714+
// Don't check if the target is already terminated, leave that to the progress agent
715+
// We could be slightly off if there were multiple instances running
716+
[self->_agentConnection.agent sendTerminationSignal];
717+
});
729718
}
730719

731720
- (void)finishInstallationAfterHostTermination SPU_OBJC_DIRECT
732721
{
733722
assert(self->_targetTerminated);
734723

735-
// Show our installer progress UI tool if only after a certain amount of time passes,
736-
// and if our installer is silent (i.e, doesn't show progress on its own)
724+
// Show our installer progress UI tool if only after a certain amount of time passes
737725
__block BOOL shouldShowUIProgress = YES;
738-
if (self->_shouldShowUI && [self->_installer canInstallSilently]) {
726+
if (self->_shouldShowUI) {
739727
// Ask the updater if it is still alive
740728
// If they are, we will receive a pong response back
741729
// Reset if we received a pong just to be on the safe side

Autoupdate/SPUInstallationInfo.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ NS_ASSUME_NONNULL_BEGIN
1414

1515
SPU_OBJC_DIRECT_MEMBERS @interface SPUInstallationInfo : NSObject <NSSecureCoding>
1616

17-
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem canSilentlyInstall:(BOOL)canSilentlyInstall;
17+
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem;
1818

1919
@property (nonatomic, readonly) SUAppcastItem *appcastItem;
20-
@property (nonatomic, readonly) BOOL canSilentlyInstall;
2120

2221
@property (nonatomic) BOOL systemDomain;
2322

Autoupdate/SPUInstallationInfo.m

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,21 @@
1919
@implementation SPUInstallationInfo
2020

2121
@synthesize appcastItem = _appcastItem;
22-
@synthesize canSilentlyInstall = _canSilentlyInstall;
2322
@synthesize systemDomain = _systemDomain;
2423

25-
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem canSilentlyInstall:(BOOL)canSilentlyInstall systemDomain:(BOOL)systemDomain
24+
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem systemDomain:(BOOL)systemDomain
2625
{
2726
self = [super init];
2827
if (self != nil) {
2928
_appcastItem = appcastItem;
30-
_canSilentlyInstall = canSilentlyInstall;
3129
_systemDomain = systemDomain;
3230
}
3331
return self;
3432
}
3533

36-
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem canSilentlyInstall:(BOOL)canSilentlyInstall
34+
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem
3735
{
38-
return [self initWithAppcastItem:appcastItem canSilentlyInstall:canSilentlyInstall systemDomain:NO];
36+
return [self initWithAppcastItem:appcastItem systemDomain:NO];
3937
}
4038

4139
- (nullable instancetype)initWithCoder:(NSCoder *)decoder
@@ -45,16 +43,18 @@ - (nullable instancetype)initWithCoder:(NSCoder *)decoder
4543
return nil;
4644
}
4745

48-
BOOL canSilentlyInstall = [decoder decodeBoolForKey:SUCanSilentlyInstallKey];
4946
BOOL systemDomain = [decoder decodeBoolForKey:SUSystemDomainKey];
50-
return [self initWithAppcastItem:appcastItem canSilentlyInstall:canSilentlyInstall systemDomain:systemDomain];
47+
return [self initWithAppcastItem:appcastItem systemDomain:systemDomain];
5148
}
5249

5350
- (void)encodeWithCoder:(NSCoder *)coder
5451
{
5552
[coder encodeObject:_appcastItem forKey:SUAppcastItemKey];
56-
[coder encodeBool:_canSilentlyInstall forKey:SUCanSilentlyInstallKey];
5753
[coder encodeBool:_systemDomain forKey:SUSystemDomainKey];
54+
55+
// Installation types can always be silently installed for newer versions of Sparkle
56+
// Still encode this key to maintain backwards compatibility with older Sparkle clients
57+
[coder encodeBool:YES forKey:SUCanSilentlyInstallKey];
5858
}
5959

6060
+ (BOOL)supportsSecureCoding

Autoupdate/SUGuidedPackageInstaller.m

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@ - (void)performCleanup
8282
{
8383
}
8484

85-
- (BOOL)canInstallSilently
86-
{
87-
return YES;
88-
}
89-
9085
@end
9186

9287
#endif

Autoupdate/SUInstallerProtocol.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ NS_ASSUME_NONNULL_BEGIN
2828
// Should be able to be called from any thread
2929
- (void)performCleanup;
3030

31-
// Indicates whether or not this installer can install the update silently in the background, without hindering the user
32-
// If this returns NO, then the installation can fail if the user did not directly request for the install to occur.
33-
// Should be thread safe
34-
- (BOOL)canInstallSilently;
35-
3631
@end
3732

3833
NS_ASSUME_NONNULL_END

Autoupdate/SUPlainInstaller.m

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,4 @@ - (void)performCleanup
406406
}
407407
}
408408

409-
- (BOOL)canInstallSilently
410-
{
411-
return YES;
412-
}
413-
414409
@end

Sparkle/SPUAutomaticUpdateDriver.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ @implementation SPUAutomaticUpdateDriver
3131
__weak id<SPUUserDriver> _userDriver;
3232
__weak id _updaterDelegate;
3333

34-
BOOL _willInstallSilently;
34+
BOOL _installerDidFinishPreparation;
3535
}
3636

3737
- (instancetype)initWithHost:(SUHost *)host applicationBundle:(NSBundle *)applicationBundle updater:(id)updater userDriver:(id <SPUUserDriver>)userDriver updaterDelegate:(nullable id <SPUUpdaterDelegate>)updaterDelegate
@@ -95,14 +95,14 @@ - (BOOL)showingUpdate
9595
return NO;
9696
}
9797

98-
- (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately silently:(BOOL)willInstallSilently
98+
- (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately
9999
{
100-
_willInstallSilently = willInstallSilently;
100+
_installerDidFinishPreparation = YES;
101101

102102
if (!willInstallImmediately) {
103103
BOOL installationHandledByDelegate = NO;
104104
id<SPUUpdaterDelegate> updaterDelegate = _updaterDelegate;
105-
if (_willInstallSilently && [updaterDelegate respondsToSelector:@selector(updater:willInstallUpdateOnQuit:immediateInstallationBlock:)]) {
105+
if ([updaterDelegate respondsToSelector:@selector(updater:willInstallUpdateOnQuit:immediateInstallationBlock:)]) {
106106
__weak __typeof__(self) weakSelf = self;
107107
installationHandledByDelegate = [updaterDelegate updater:_updater willInstallUpdateOnQuit:_updateItem immediateInstallationBlock:^{
108108
dispatch_async(dispatch_get_main_queue(), ^{
@@ -139,7 +139,7 @@ - (void)abortUpdate
139139

140140
- (void)abortUpdateWithError:(NSError *)error
141141
{
142-
BOOL showNextUpdateImmediately = (error == nil || error.code == SUInstallationAuthorizeLaterError) && (!_willInstallSilently || _updateItem.criticalUpdate || _updateItem.isInformationOnlyUpdate);
142+
BOOL showNextUpdateImmediately = (error == nil || error.code == SUInstallationAuthorizeLaterError) && (!_installerDidFinishPreparation || _updateItem.criticalUpdate || _updateItem.isInformationOnlyUpdate);
143143

144144
[_coreDriver abortUpdateAndShowNextUpdateImmediately:showNextUpdateImmediately error:error];
145145
}

Sparkle/SPUCoreBasedUpdateDriver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
2020

2121
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryAppcastItem;
2222

23-
- (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately silently:(BOOL)willInstallSilently;
23+
- (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately;
2424

2525
- (void)coreDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error;
2626

Sparkle/SPUCoreBasedUpdateDriver.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,9 @@ - (void)installerDidExtractUpdateWithProgress:(double)progress
295295
}
296296
}
297297

298-
- (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately silently:(BOOL)willInstallSilently
298+
- (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately
299299
{
300-
[_delegate installerDidFinishPreparationAndWillInstallImmediately:willInstallImmediately silently:willInstallSilently];
300+
[_delegate installerDidFinishPreparationAndWillInstallImmediately:willInstallImmediately];
301301
}
302302

303303
- (void)finishInstallationWithResponse:(SPUUserUpdateChoice)response displayingUserInterface:(BOOL)displayingUserInterface

Sparkle/SPUInstallationType.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#define SPUInstallationTypeApplication @"application" // the default installation type for ordinary application updates
1313
#define SPUInstallationTypeGuidedPackage @"package" // the preferred installation type for package installations
14-
#define SPUInstallationTypeInteractivePackage @"interactive-package" // the deprecated installation type; use guided package instead
14+
#define SPUInstallationTypeInteractivePackage @"interactive-package" // removed installation type; use guided package instead
1515

1616
#define SPUInstallationTypesArray (@[SPUInstallationTypeApplication, SPUInstallationTypeGuidedPackage])
1717
#define SPUValidInstallationType(x) ((x != nil) && [SPUInstallationTypesArray containsObject:(NSString * _Nonnull)x])

0 commit comments

Comments
 (0)