diff --git a/Autoupdate/AppInstaller.m b/Autoupdate/AppInstaller.m index 3d69c0eb..0136182f 100644 --- a/Autoupdate/AppInstaller.m +++ b/Autoupdate/AppInstaller.m @@ -422,7 +422,8 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7; } else if (identifier == SPUSentUpdateAppcastItemData) { SUAppcastItem *updateItem = (SUAppcastItem *)SPUUnarchiveRootObjectSecurely(data, [SUAppcastItem class]); if (updateItem != nil) { - SPUInstallationInfo *installationInfo = [[SPUInstallationInfo alloc] initWithAppcastItem:updateItem canSilentlyInstall:[self.installer canInstallSilently]]; + BOOL canInstallSilently = [self.installer canInstallSilently]; + SPUInstallationInfo *installationInfo = [[SPUInstallationInfo alloc] initWithAppcastItem:updateItem canSilentlyInstall:canInstallSilently]; NSData *archivedData = SPUArchiveRootObjectSecurely(installationInfo); if (archivedData != nil) { @@ -432,7 +433,11 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7; dispatch_async(dispatch_get_main_queue(), ^{ if (!notifiedRegistrationCompleted) { notifiedRegistrationCompleted = YES; - [self.communicator handleMessageWithIdentifier:SPUInstallerRegisteredAppcastItem data:[NSData data]]; + + uint8_t targetTerminated = (uint8_t)self.terminationListener.terminated; + uint8_t sendInformation[] = {targetTerminated, (uint8_t)canInstallSilently}; + + [self.communicator handleMessageWithIdentifier:SPUInstallerRegisteredAppcastItem data:[NSData dataWithBytes:sendInformation length:sizeof(sendInformation)]]; } }); }]; @@ -442,7 +447,13 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(UPDATER_APPCAST_ITEM_REGISTRATION_TIMEOUT * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ if (!notifiedRegistrationCompleted) { notifiedRegistrationCompleted = YES; - [self.communicator handleMessageWithIdentifier:SPUInstallerRegisteredAppcastItem data:[NSData data]]; + + SULog(SULogLevelError, @"Warning: did not receive appcast item registration from Updater in timely manner. Proceeding.."); + + uint8_t targetTerminated = (uint8_t)self.terminationListener.terminated; + uint8_t sendInformation[] = {targetTerminated, (uint8_t)canInstallSilently}; + + [self.communicator handleMessageWithIdentifier:SPUInstallerRegisteredAppcastItem data:[NSData dataWithBytes:sendInformation length:sizeof(sendInformation)]]; } }); } @@ -501,18 +512,10 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7; return; } - uint8_t canPerformSilentInstall = (uint8_t)[installer canInstallSilently]; - dispatch_async(dispatch_get_main_queue(), ^{ self.installer = installer; - uint8_t targetTerminated = (uint8_t)self.terminationListener.terminated; - - uint8_t sendInformation[] = {canPerformSilentInstall, targetTerminated}; - - NSData *sendData = [NSData dataWithBytes:sendInformation length:sizeof(sendInformation)]; - - [self.communicator handleMessageWithIdentifier:SPUInstallationFinishedStage1 data:sendData]; + [self.communicator handleMessageWithIdentifier:SPUInstallationFinishedStage1 data:[NSData data]]; self.performedStage1Installation = YES; diff --git a/Documentation/Installation.md b/Documentation/Installation.md index 2396da50..9be474c0 100644 --- a/Documentation/Installation.md +++ b/Documentation/Installation.md @@ -84,7 +84,9 @@ Otherwise a `SPUInstallationFinishedStage1` message is sent back to the updater The installer then listens and waits for the target application to relaunch terminates. If it is already terminated, then it resumes to stage 2 and 3 of the installation immediately on the assumption that the installer does not have permission to show UI interaction to the user. Thus if the installer has to show user interaction here and hasn't received an OK from the updater (it won't if the target application is already terminated), the install will fail. If the target is already terminated, the installer will also assume that the target should not be relaunched after installation. ### Installation Waiting Period -The updater receives `SPUInstallationFinishedStage1` message. The updater sends a message `SPUSentUpdateAppcastItemData` with the appcast data in case the updater may request for it later (due to installer resumability, discussed later). It also reads if the target has already been terminated (implying that the installer will continue installing the update immediately), and if the installation will be done silently. +The updater receives `SPUInstallationFinishedStage1` message. The updater sends a message `SPUSentUpdateAppcastItemData` with the appcast data in case the updater may request for it later (due to installer resumability, discussed later). + +The updater waits to receive a `SPUInstallerRegisteredAppcastItem` message indicating the installer registered receiving the appcast item data (it waits for this registration to avoid a race of asking for it later and not being provided with info). The updater also reads if the target has already been terminated (implying that the installer will continue installing the update immediately), and if the installation will be done silently. For UI based update drivers, the updater tells the user driver to show that the application is ready to be relaunched - the user can continue to install & relaunch the app. The user driver is only alerted however if the installation isn't happening immediately (that is, if the target application to relaunch is still alive). The user driver can decide whether to a) install b) install & relaunch or c) delay installation. If installation is delayed, it can be resumed later, or if the target application terminates, the installer will try to continue installation if it is capable to without user interaction. diff --git a/Sparkle/SPUInstallerDriver.m b/Sparkle/SPUInstallerDriver.m index f290a1eb..d771fd8e 100644 --- a/Sparkle/SPUInstallerDriver.m +++ b/Sparkle/SPUInstallerDriver.m @@ -66,8 +66,6 @@ @implementation SPUInstallerDriver { void (^_updateWillInstallHandler)(void); - BOOL _canInstallSilently; - BOOL _hasTargetTerminated; } @synthesize host = _host; @@ -318,27 +316,20 @@ } else { 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); - } - - // The installer letting us know when the appcast item was registered (SPUInstallerRegisteredAppcastItem) - // was added later. In earlier versions of Sparkle, we could have notified the update too early - // before the installer finished registering the appcast item. - // Note we don't need to handle an "old" installer because Sparkle and the installer should still be aligned at this point. - _canInstallSilently = canInstallSilently; - _hasTargetTerminated = hasTargetTerminated; } else if (identifier == SPUInstallerRegisteredAppcastItem) { self.currentStage = identifier; - [self.delegate installerDidFinishPreparationAndWillInstallImmediately:_hasTargetTerminated silently:_canInstallSilently]; + BOOL hasTargetTerminated = NO; + if (data.length >= sizeof(uint8_t)) { + hasTargetTerminated = (BOOL)*(const uint8_t *)data.bytes; + } + + BOOL canInstallSilently = NO; + if (data.length >= sizeof(uint8_t) * 2) { + canInstallSilently = (BOOL)*((const uint8_t *)data.bytes + 1); + } + + [self.delegate installerDidFinishPreparationAndWillInstallImmediately:hasTargetTerminated silently:canInstallSilently]; } else if (identifier == SPUInstallationFinishedStage2) { self.currentStage = identifier;