From 233fa268b5917c955574a1319e300175c974cac0 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 9 Apr 2016 00:36:09 -0400 Subject: [PATCH] Add tool for showing installer progress This tool is only launched if a certain amount of time has passed, and if we're allowed to show UI --- Configurations/ConfigCommon.xcconfig | 3 +- .../ConfigInstallerProgress.xcconfig | 8 ++ Sparkle.xcodeproj/project.pbxproj | 116 +++++++++++++++++ Sparkle/Autoupdate/AppInstaller.m | 42 ++++++ Sparkle/Autoupdate/SUInstallationInputData.h | 3 +- Sparkle/Autoupdate/SUInstallationInputData.m | 12 +- .../InstallerProgress-Info.plist | 30 +++++ Sparkle/InstallerProgress/InstallerProgress.m | 122 ++++++++++++++++++ Sparkle/SUInstallerDriver.m | 104 ++++++++------- 9 files changed, 390 insertions(+), 50 deletions(-) create mode 100644 Configurations/ConfigInstallerProgress.xcconfig create mode 100644 Sparkle/InstallerProgress/InstallerProgress-Info.plist create mode 100644 Sparkle/InstallerProgress/InstallerProgress.m diff --git a/Configurations/ConfigCommon.xcconfig b/Configurations/ConfigCommon.xcconfig index 58b9186e..421f79c4 100644 --- a/Configurations/ConfigCommon.xcconfig +++ b/Configurations/ConfigCommon.xcconfig @@ -2,6 +2,7 @@ SPARKLE_BUNDLE_IDENTIFIER = org.sparkle-project.Sparkle SPARKLE_RELAUNCH_TOOL_NAME = Autoupdate +SPARKLE_INSTALLER_PROGRESS_TOOL_NAME = Updater SPARKLE_APPEND_VERSION_NUMBER = 1 @@ -31,7 +32,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.8 PRODUCT_NAME = ${TARGET_NAME} PRODUCT_BUNDLE_IDENTIFIER = org.sparkle-project.Sparkle.${PRODUCT_NAME:rfc1034identifier} -GCC_PREPROCESSOR_DEFINITIONS_COMMON = SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME=$(SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME) SPARKLE_AUTOMATED_DOWNGRADES=$(SPARKLE_AUTOMATED_DOWNGRADES) SPARKLE_APPEND_VERSION_NUMBER=$(SPARKLE_APPEND_VERSION_NUMBER) SPARKLE_BUNDLE_IDENTIFIER=\"$(SPARKLE_BUNDLE_IDENTIFIER)\" SPARKLE_RELAUNCH_TOOL_NAME=\"$(SPARKLE_RELAUNCH_TOOL_NAME)\" +GCC_PREPROCESSOR_DEFINITIONS_COMMON = SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME=$(SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME) SPARKLE_AUTOMATED_DOWNGRADES=$(SPARKLE_AUTOMATED_DOWNGRADES) SPARKLE_APPEND_VERSION_NUMBER=$(SPARKLE_APPEND_VERSION_NUMBER) SPARKLE_BUNDLE_IDENTIFIER=\"$(SPARKLE_BUNDLE_IDENTIFIER)\" SPARKLE_RELAUNCH_TOOL_NAME=\"$(SPARKLE_RELAUNCH_TOOL_NAME)\" SPARKLE_INSTALLER_PROGRESS_TOOL_NAME=\"$(SPARKLE_INSTALLER_PROGRESS_TOOL_NAME)\" CLANG_ENABLE_OBJC_ARC = YES GCC_ENABLE_PASCAL_STRINGS = NO diff --git a/Configurations/ConfigInstallerProgress.xcconfig b/Configurations/ConfigInstallerProgress.xcconfig new file mode 100644 index 00000000..99603eb6 --- /dev/null +++ b/Configurations/ConfigInstallerProgress.xcconfig @@ -0,0 +1,8 @@ +// Installer Progress only + +INFOPLIST_FILE = Sparkle/InstallerProgress/InstallerProgress-Info.plist +PRODUCT_NAME = $(SPARKLE_INSTALLER_PROGRESS_TOOL_NAME) +SKIP_INSTALL = YES +ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon +CLANG_ENABLE_MODULES = NO +OTHER_LDFLAGS = -Wl,-U,_NSURLQuarantinePropertiesKey diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 0f4ba4fb..48ec13bd 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -124,6 +124,14 @@ 7210C7681B9A9A1500EB90AC /* SUUnarchiverTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7210C7671B9A9A1500EB90AC /* SUUnarchiverTest.swift */; }; 72162B061C82C8B30013C1C5 /* SUParameterAssert.h in Headers */ = {isa = PBXBuildFile; fileRef = 72162B051C82C8B30013C1C5 /* SUParameterAssert.h */; }; 72162B081C82C9600013C1C5 /* SULocalizations.h in Headers */ = {isa = PBXBuildFile; fileRef = 72162B071C82C9600013C1C5 /* SULocalizations.h */; }; + 721C245A1CB75756005440CB /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 525A278F133D6AE900FD8D70 /* Cocoa.framework */; }; + 721C245B1CB75765005440CB /* SURemoteMessagePort.m in Sources */ = {isa = PBXBuildFile; fileRef = 729746441C91212400FC134E /* SURemoteMessagePort.m */; }; + 721C245C1CB7576E005440CB /* SUStatusController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6196CFE409C71ADE000DC222 /* SUStatusController.m */; }; + 721C245D1CB757C4005440CB /* SUApplicationInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 725602D41C83551C00DAA70E /* SUApplicationInfo.m */; }; + 721C245E1CB757DE005440CB /* SUConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A5F09CA6EB100B7442F /* SUConstants.m */; }; + 721C245F1CB75A6B005440CB /* SUMessageTypes.m in Sources */ = {isa = PBXBuildFile; fileRef = 729746561C936D5E00FC134E /* SUMessageTypes.m */; }; + 721C24611CB75C5D005440CB /* SUHost.m in Sources */ = {isa = PBXBuildFile; fileRef = 61EF67550E25B58D00F754E0 /* SUHost.m */; }; + 721C24621CB75C68005440CB /* SULog.m in Sources */ = {isa = PBXBuildFile; fileRef = 55C14F05136EF6DB00649790 /* SULog.m */; }; 721CF1A71AD7643600D9AC09 /* bsdiff.c in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8DB0FD68CB9005AE3F6 /* bsdiff.c */; settings = {COMPILER_FLAGS = "-w"; }; }; 721CF1A81AD7644100D9AC09 /* bspatch.c in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8DC0FD68CB9005AE3F6 /* bspatch.c */; settings = {COMPILER_FLAGS = "-w"; }; }; 721CF1A91AD7644C00D9AC09 /* sais.c in Sources */ = {isa = PBXBuildFile; fileRef = 7223E7611AD1AEFF008E3161 /* sais.c */; settings = {COMPILER_FLAGS = "-w"; }; }; @@ -269,6 +277,10 @@ 72E45CFC1B641961005C701A /* sparkletestcast.xml in Resources */ = {isa = PBXBuildFile; fileRef = 72E45CFB1B641961005C701A /* sparkletestcast.xml */; }; 72E45CFE1B641D0D005C701A /* test_app_only_dsa_priv_dont_ever_do_this_for_real.pem in Resources */ = {isa = PBXBuildFile; fileRef = 72E45CFD1B641D0D005C701A /* test_app_only_dsa_priv_dont_ever_do_this_for_real.pem */; }; 72E45DDD1B65C3BD005C701A /* sign_update in Resources */ = {isa = PBXBuildFile; fileRef = 72E45DDC1B65C3BD005C701A /* sign_update */; }; + 72EB87EA1CB8798800C37F42 /* InstallerProgress.m in Sources */ = {isa = PBXBuildFile; fileRef = 72EB87E91CB8798800C37F42 /* InstallerProgress.m */; }; + 72EB87EB1CB8859100C37F42 /* Updater.app in CopyFiles */ = {isa = PBXBuildFile; fileRef = 721C24451CB753E6005440CB /* Updater.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; + 72EB87EC1CB8887E00C37F42 /* SUStatus.xib in Resources */ = {isa = PBXBuildFile; fileRef = 55C14BD8136EF00C00649790 /* SUStatus.xib */; }; + 72EB87ED1CB8896600C37F42 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1420DF4F196247F900203BB0 /* Images.xcassets */; }; 767B61AC1972D488004E0C3C /* SUGuidedPackageInstaller.h in Headers */ = {isa = PBXBuildFile; fileRef = 767B61AA1972D488004E0C3C /* SUGuidedPackageInstaller.h */; }; 767B61AE1972D488004E0C3C /* SUGuidedPackageInstaller.m in Sources */ = {isa = PBXBuildFile; fileRef = 767B61AB1972D488004E0C3C /* SUGuidedPackageInstaller.m */; }; C23E885B1BE7B24F0050BB73 /* SparkleTestCodeSignApp.enc.dmg in Resources */ = {isa = PBXBuildFile; fileRef = C23E88591BE7AF890050BB73 /* SparkleTestCodeSignApp.enc.dmg */; }; @@ -431,6 +443,7 @@ dstPath = ""; dstSubfolderSpec = 12; files = ( + 72EB87EB1CB8859100C37F42 /* Updater.app in CopyFiles */, 142E0E0419A6A26F00E4312B /* Autoupdate.app in CopyFiles */, ); runOnlyForDeploymentPostprocessing = 0; @@ -705,6 +718,9 @@ 7210C7671B9A9A1500EB90AC /* SUUnarchiverTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SUUnarchiverTest.swift; sourceTree = ""; }; 72162B051C82C8B30013C1C5 /* SUParameterAssert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUParameterAssert.h; sourceTree = ""; }; 72162B071C82C9600013C1C5 /* SULocalizations.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SULocalizations.h; sourceTree = ""; }; + 721C24451CB753E6005440CB /* Updater.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Updater.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 721C24571CB754E8005440CB /* ConfigInstallerProgress.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigInstallerProgress.xcconfig; sourceTree = ""; }; + 721C24581CB7567D005440CB /* InstallerProgress-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "InstallerProgress-Info.plist"; path = "Sparkle/InstallerProgress/InstallerProgress-Info.plist"; sourceTree = SOURCE_ROOT; }; 7223E7611AD1AEFF008E3161 /* sais.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sais.c; sourceTree = ""; }; 7223E7621AD1AEFF008E3161 /* sais.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sais.h; sourceTree = ""; }; 7229E1B51C97C91100CB50D0 /* SUUpdateDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUpdateDriver.h; sourceTree = ""; }; @@ -846,6 +862,7 @@ 72E45CFB1B641961005C701A /* sparkletestcast.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = sparkletestcast.xml; sourceTree = ""; }; 72E45CFD1B641D0D005C701A /* test_app_only_dsa_priv_dont_ever_do_this_for_real.pem */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = test_app_only_dsa_priv_dont_ever_do_this_for_real.pem; sourceTree = ""; }; 72E45DDC1B65C3BD005C701A /* sign_update */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; name = sign_update; path = bin/sign_update; sourceTree = SOURCE_ROOT; }; + 72EB87E91CB8798800C37F42 /* InstallerProgress.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = InstallerProgress.m; path = Sparkle/InstallerProgress/InstallerProgress.m; sourceTree = SOURCE_ROOT; }; 767B61AA1972D488004E0C3C /* SUGuidedPackageInstaller.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUGuidedPackageInstaller.h; sourceTree = ""; }; 767B61AB1972D488004E0C3C /* SUGuidedPackageInstaller.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUGuidedPackageInstaller.m; sourceTree = ""; }; 8DC2EF5A0486A6940098B216 /* Sparkle-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Sparkle-Info.plist"; sourceTree = ""; }; @@ -923,6 +940,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 721C24421CB753E6005440CB /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 721C245A1CB75756005440CB /* Cocoa.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 726B2B5A1C645FC900388755 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -995,6 +1020,7 @@ 726E07EF1CAF37BD001A286B /* UpdateDownloader.xpc */, 728638F31CAF5A5F00783084 /* AppcastDownloader.xpc */, 72E41A3E1CB20BA7003D47E0 /* RemoteMessagePort.xpc */, + 721C24451CB753E6005440CB /* Updater.app */, ); name = Products; sourceTree = ""; @@ -1110,6 +1136,7 @@ children = ( 61299B3909CB055000B7442F /* Appcast Support */, 55C14BD5136EEFD000649790 /* Autoupdate */, + 721C24461CB753E6005440CB /* Installer Progress */, 729746481C91483B00FC134E /* IPC */, 089C1665FE841158C02AAC07 /* Framework Resources */, 61B5F8F309C4CE5900B25A18 /* Other Sources */, @@ -1369,6 +1396,16 @@ name = "Update Control"; sourceTree = ""; }; + 721C24461CB753E6005440CB /* Installer Progress */ = { + isa = PBXGroup; + children = ( + 72EB87E91CB8798800C37F42 /* InstallerProgress.m */, + 721C24581CB7567D005440CB /* InstallerProgress-Info.plist */, + ); + name = "Installer Progress"; + path = "../Installer Progress"; + sourceTree = ""; + }; 725F97811C8A997300265BE4 /* User Driver */ = { isa = PBXGroup; children = ( @@ -1515,6 +1552,7 @@ FA1941CE0D94A70100DD942E /* ConfigRelaunch.xcconfig */, FA1941D30D94A70100DD942E /* ConfigRelaunchDebug.xcconfig */, FA1941D40D94A70100DD942E /* ConfigRelaunchRelease.xcconfig */, + 721C24571CB754E8005440CB /* ConfigInstallerProgress.xcconfig */, FA1941CD0D94A70100DD942E /* ConfigTestApp.xcconfig */, FA1941CB0D94A70100DD942E /* ConfigTestAppDebug.xcconfig */, FA1941D20D94A70100DD942E /* ConfigTestAppRelease.xcconfig */, @@ -1727,6 +1765,23 @@ productReference = 61B5F90209C4CEE200B25A18 /* Sparkle Test App.app */; productType = "com.apple.product-type.application"; }; + 721C24441CB753E6005440CB /* Installer Progress */ = { + isa = PBXNativeTarget; + buildConfigurationList = 721C24561CB753E7005440CB /* Build configuration list for PBXNativeTarget "Installer Progress" */; + buildPhases = ( + 721C24411CB753E6005440CB /* Sources */, + 721C24421CB753E6005440CB /* Frameworks */, + 721C24431CB753E6005440CB /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "Installer Progress"; + productName = "Installer Progress"; + productReference = 721C24451CB753E6005440CB /* Updater.app */; + productType = "com.apple.product-type.application"; + }; 726B2B5C1C645FC900388755 /* UI Tests */ = { isa = PBXNativeTarget; buildConfigurationList = 726B2B671C645FC900388755 /* Build configuration list for PBXNativeTarget "UI Tests" */; @@ -1882,6 +1937,9 @@ }; }; }; + 721C24441CB753E6005440CB = { + CreatedOnToolsVersion = 7.3; + }; 726B2B5C1C645FC900388755 = { CreatedOnToolsVersion = 7.2.1; TestTargetID = 61B5F90109C4CEE200B25A18; @@ -1969,6 +2027,7 @@ "fr-CA", "pt-PT", "pt-BR", + Base, ); mainGroup = 0867D691FE84028FC02AAC07 /* Sparkle */; productRefGroup = 034768DFFF38A50411DB9C8B /* Products */; @@ -1985,6 +2044,7 @@ 612279D80DB5470200AB99EA /* Sparkle Unit Tests */, 5D06E8CF0FD68C7C005AE3F6 /* BinaryDelta */, 55C14BB6136EEF1500649790 /* Autoupdate */, + 721C24441CB753E6005440CB /* Installer Progress */, 14732BC51960F69300593899 /* Distribution */, 1420DF491962329200203BB0 /* Documentation */, 1495005F195FB89400BC5B5B /* All */, @@ -2037,6 +2097,15 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 721C24431CB753E6005440CB /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 72EB87ED1CB8896600C37F42 /* Images.xcassets in Resources */, + 72EB87EC1CB8887E00C37F42 /* SUStatus.xib in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 726B2B5B1C645FC900388755 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -2286,6 +2355,21 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 721C24411CB753E6005440CB /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 721C24621CB75C68005440CB /* SULog.m in Sources */, + 72EB87EA1CB8798800C37F42 /* InstallerProgress.m in Sources */, + 721C24611CB75C5D005440CB /* SUHost.m in Sources */, + 721C245F1CB75A6B005440CB /* SUMessageTypes.m in Sources */, + 721C245E1CB757DE005440CB /* SUConstants.m in Sources */, + 721C245D1CB757C4005440CB /* SUApplicationInfo.m in Sources */, + 721C245C1CB7576E005440CB /* SUStatusController.m in Sources */, + 721C245B1CB75765005440CB /* SURemoteMessagePort.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 726B2B591C645FC900388755 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -2831,6 +2915,27 @@ }; name = Release; }; + 721C24531CB753E7005440CB /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 721C24571CB754E8005440CB /* ConfigInstallerProgress.xcconfig */; + buildSettings = { + }; + name = Debug; + }; + 721C24541CB753E7005440CB /* Coverage */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 721C24571CB754E8005440CB /* ConfigInstallerProgress.xcconfig */; + buildSettings = { + }; + name = Coverage; + }; + 721C24551CB753E7005440CB /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 721C24571CB754E8005440CB /* ConfigInstallerProgress.xcconfig */; + buildSettings = { + }; + name = Release; + }; 726B2B641C645FC900388755 /* Debug */ = { isa = XCBuildConfiguration; baseConfigurationReference = 729F10FF1C65A9B500DFCCC5 /* ConfigUITestDebug.xcconfig */; @@ -3064,6 +3169,16 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 721C24561CB753E7005440CB /* Build configuration list for PBXNativeTarget "Installer Progress" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 721C24531CB753E7005440CB /* Debug */, + 721C24541CB753E7005440CB /* Coverage */, + 721C24551CB753E7005440CB /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; 726B2B671C645FC900388755 /* Build configuration list for PBXNativeTarget "UI Tests" */ = { isa = XCConfigurationList; buildConfigurations = ( @@ -3122,6 +3237,7 @@ 72E41A4D1CB20BA7003D47E0 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/Sparkle/Autoupdate/AppInstaller.m b/Sparkle/Autoupdate/AppInstaller.m index 68dc2091..73dda8b2 100644 --- a/Sparkle/Autoupdate/AppInstaller.m +++ b/Sparkle/Autoupdate/AppInstaller.m @@ -21,6 +21,7 @@ #import "SUSecureCoding.h" #import "SUInstallationInputData.h" #import "SUUnarchiver.h" +#import "SUFileManager.h" /*! * Terminate the application after a delay from launching the new update to avoid OS activation issues @@ -29,6 +30,13 @@ */ static const NSTimeInterval SUTerminationTimeDelay = 0.5; +/*! + * Show display progress UI after a delay from starting the final part of the installation. + * This should be long enough so that we don't show progress for very fast installations, but + * short enough so that we don't leave the user wondering why nothing is happening. + */ +static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7; + @interface AppInstaller () @property (nonatomic, strong) TerminationListener *terminationListener; @@ -478,12 +486,42 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5; return; } + // Launch our installer progress UI tool if only after a certain amount of time passes + __block NSRunningApplication *installerProgressRunningApplication = nil; + __block BOOL shouldLaunchInstallerProgress = YES; + + NSString *progressToolPath = self.installationData.progressToolPath; + if (progressToolPath != nil && self.shouldShowUI) { + NSURL *progressToolURL = [NSURL fileURLWithPath:progressToolPath]; + if (progressToolURL != nil) { + NSError *quarantineError = nil; + if (![[SUFileManager fileManagerAllowingAuthorization:NO] releaseItemFromQuarantineAtRootURL:progressToolURL error:&quarantineError]) { + SULog(@"Error: Failed releasing quarantine from installer progress tool: %@", quarantineError); + } + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(SUDisplayProgressTimeDelay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + if (shouldLaunchInstallerProgress) { + NSError *launchError = nil; + NSArray *arguments = @[self.host.bundlePath]; + NSRunningApplication *runningApplication = [[NSWorkspace sharedWorkspace] launchApplicationAtURL:progressToolURL options:(NSWorkspaceLaunchOptions)(NSWorkspaceLaunchDefault | NSWorkspaceLaunchNewInstance) configuration:@{NSWorkspaceLaunchConfigurationArguments : arguments} error:&launchError]; + + if (runningApplication == nil) { + SULog(@"Failed to launch installer progress tool with error: %@", launchError); + } else { + installerProgressRunningApplication = runningApplication; + } + } + }); + } + } + dispatch_async(self.installerQueue, ^{ [self performStage2InstallationIfNeeded]; NSError *thirdStageError = nil; if (![self.installer performThirdStage:&thirdStageError]) { SULog(@"Failed to finalize installation with error: %@", thirdStageError); + [self.installer cleanup]; self.installer = nil; @@ -496,6 +534,10 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5; self.performedStage3Installation = YES; dispatch_async(dispatch_get_main_queue(), ^{ + // Make sure to terminate our displayed progress before we move onto cleanup + [installerProgressRunningApplication terminate]; + shouldLaunchInstallerProgress = NO; + NSString *installationPath = [SUInstaller installationPathForHost:self.host]; if (self.shouldRelaunch) { diff --git a/Sparkle/Autoupdate/SUInstallationInputData.h b/Sparkle/Autoupdate/SUInstallationInputData.h index c7bd4ae3..2b3449d7 100644 --- a/Sparkle/Autoupdate/SUInstallationInputData.h +++ b/Sparkle/Autoupdate/SUInstallationInputData.h @@ -12,9 +12,10 @@ NS_ASSUME_NONNULL_BEGIN @interface SUInstallationInputData : NSObject -- (instancetype)initWithRelaunchPath:(NSString *)relaunchPath hostBundlePath:(NSString *)hostBundlePath updateDirectoryPath:(NSString *)updateDirectoryPath downloadPath:(NSString *)downloadPath dsaSignature:(NSString *)dsaSignature decryptionPassword:(nullable NSString *)decryptionPassword; +- (instancetype)initWithRelaunchPath:(NSString *)relaunchPath progressToolPath:(nullable NSString *)progressToolPath hostBundlePath:(NSString *)hostBundlePath updateDirectoryPath:(NSString *)updateDirectoryPath downloadPath:(NSString *)downloadPath dsaSignature:(NSString *)dsaSignature decryptionPassword:(nullable NSString *)decryptionPassword; @property (nonatomic, copy, readonly) NSString *relaunchPath; +@property (nonatomic, copy, readonly, nullable) NSString *progressToolPath; @property (nonatomic, copy, readonly) NSString *hostBundlePath; @property (nonatomic, copy, readonly) NSString *updateDirectoryPath; @property (nonatomic, copy, readonly) NSString *downloadPath; diff --git a/Sparkle/Autoupdate/SUInstallationInputData.m b/Sparkle/Autoupdate/SUInstallationInputData.m index 5c09a16f..c741eaa0 100644 --- a/Sparkle/Autoupdate/SUInstallationInputData.m +++ b/Sparkle/Autoupdate/SUInstallationInputData.m @@ -9,6 +9,7 @@ #import "SUInstallationInputData.h" static NSString *SURelaunchPathKey = @"SURelaunchPath"; +static NSString *SUProgressToolPathKey = @"SUProgressToolPath"; static NSString *SUHostBundlePathKey = @"SUHostBundlePath"; static NSString *SUUpdateDirectoryPathKey = @"SUUpdateDirectoryPath"; static NSString *SUDownloadPathKey = @"SUDownloadPath"; @@ -18,17 +19,19 @@ static NSString *SUDecryptionPasswordKey = @"SUDecryptionPassword"; @implementation SUInstallationInputData @synthesize relaunchPath = _relaunchPath; +@synthesize progressToolPath = _progressToolPath; @synthesize hostBundlePath = _hostBundlePath; @synthesize updateDirectoryPath = _updateDirectoryPath; @synthesize downloadPath = _downloadPath; @synthesize dsaSignature = _dsaSignature; @synthesize decryptionPassword = _decryptionPassword; -- (instancetype)initWithRelaunchPath:(NSString *)relaunchPath hostBundlePath:(NSString *)hostBundlePath updateDirectoryPath:(NSString *)updateDirectoryPath downloadPath:(NSString *)downloadPath dsaSignature:(NSString *)dsaSignature decryptionPassword:(nullable NSString *)decryptionPassword +- (instancetype)initWithRelaunchPath:(NSString *)relaunchPath progressToolPath:(nullable NSString *)progressToolPath hostBundlePath:(NSString *)hostBundlePath updateDirectoryPath:(NSString *)updateDirectoryPath downloadPath:(NSString *)downloadPath dsaSignature:(NSString *)dsaSignature decryptionPassword:(nullable NSString *)decryptionPassword { self = [super init]; if (self != nil) { _relaunchPath = [relaunchPath copy]; + _progressToolPath = [progressToolPath copy]; _hostBundlePath = [hostBundlePath copy]; _updateDirectoryPath = [updateDirectoryPath copy]; _downloadPath = [downloadPath copy]; @@ -45,6 +48,8 @@ static NSString *SUDecryptionPasswordKey = @"SUDecryptionPassword"; return nil; } + NSString *progressToolPath = [decoder decodeObjectOfClass:[NSString class] forKey:SUProgressToolPathKey]; + NSString *hostBundlePath = [decoder decodeObjectOfClass:[NSString class] forKey:SUHostBundlePathKey]; if (hostBundlePath == nil) { return nil; @@ -67,12 +72,15 @@ static NSString *SUDecryptionPasswordKey = @"SUDecryptionPassword"; NSString *decryptionPassword = [decoder decodeObjectOfClass:[NSString class] forKey:SUDecryptionPasswordKey]; - return [self initWithRelaunchPath:relaunchPath hostBundlePath:hostBundlePath updateDirectoryPath:updateDirectoryPath downloadPath:downloadPath dsaSignature:dsaSignature decryptionPassword:decryptionPassword]; + return [self initWithRelaunchPath:relaunchPath progressToolPath:progressToolPath hostBundlePath:hostBundlePath updateDirectoryPath:updateDirectoryPath downloadPath:downloadPath dsaSignature:dsaSignature decryptionPassword:decryptionPassword]; } - (void)encodeWithCoder:(NSCoder *)coder { [coder encodeObject:self.relaunchPath forKey:SURelaunchPathKey]; + if (self.progressToolPath != nil) { + [coder encodeObject:self.progressToolPath forKey:SUProgressToolPathKey]; + } [coder encodeObject:self.hostBundlePath forKey:SUHostBundlePathKey]; [coder encodeObject:self.updateDirectoryPath forKey:SUUpdateDirectoryPathKey]; [coder encodeObject:self.downloadPath forKey:SUDownloadPathKey]; diff --git a/Sparkle/InstallerProgress/InstallerProgress-Info.plist b/Sparkle/InstallerProgress/InstallerProgress-Info.plist new file mode 100644 index 00000000..6f42e62b --- /dev/null +++ b/Sparkle/InstallerProgress/InstallerProgress-Info.plist @@ -0,0 +1,30 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIconFile + + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + ${CURRENT_PROJECT_VERSION} + CFBundleSignature + ???? + CFBundleVersion + ${CURRENT_PROJECT_VERSION} + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + NSPrincipalClass + NSApplication + + diff --git a/Sparkle/InstallerProgress/InstallerProgress.m b/Sparkle/InstallerProgress/InstallerProgress.m new file mode 100644 index 00000000..5600a008 --- /dev/null +++ b/Sparkle/InstallerProgress/InstallerProgress.m @@ -0,0 +1,122 @@ +// +// InstallerProgress.m +// Installer Progress +// +// Created by Mayur Pawashe on 4/7/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import +#import "SURemoteMessagePort.h" +#import "SUMessageTypes.h" +#import "SUStatusController.h" +#import "SUHost.h" +#import "SULocalizations.h" +#import "SULog.h" + +/*! + * Terminate the application after a delay from launching the new update to avoid OS activation issues + * This delay should be be high enough to increase the likelihood that our updated app will be launched up front, + * but should be low enough so that the user doesn't ponder why the updater hasn't finished terminating yet + */ +static const NSTimeInterval SUTerminationTimeDelay = 0.3; + +@interface InstallerProgress : NSObject + +@property (nonatomic, readonly) SURemoteMessagePort *remotePort; +@property (nonatomic) SUStatusController *statusController; + +@end + +@implementation InstallerProgress + +@synthesize remotePort = _remotePort; +@synthesize statusController = _statusController; + +- (instancetype)initWithHost:(SUHost *)host +{ + self = [super init]; + if (self != nil) { + NSString *bundleIdentifier = host.bundle.bundleIdentifier; + if (bundleIdentifier == nil) { + SULog(@"Error: Bundle Identifier for host is nil"); + exit(0); + } + + _remotePort = [[SURemoteMessagePort alloc] initWithServiceName:SUAutoUpdateServiceNameForBundleIdentifier(bundleIdentifier)]; + _statusController = [[SUStatusController alloc] initWithHost:host]; + } + return self; +} + +// Close status window immediately, but delay termination for a little bit to better increase the chance +// the updated application when relaunched will be the frontmost application +// This is related to OS X activation issues when terminating a frontmost application happens right before +// launching another app +- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender +{ + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(SUTerminationTimeDelay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [sender replyToApplicationShouldTerminate:YES]; + }); + + [self.statusController close]; + self.statusController = nil; + + return NSTerminateLater; +} + +- (void)applicationDidFinishLaunching:(NSNotification *)__unused notification +{ + __weak InstallerProgress *weakSelf = self; + [self.remotePort connectWithLookupCompletion:^(BOOL success) { + if (!success) { + [NSApp terminate:nil]; + } else { + [weakSelf.remotePort setInvalidationHandler:^{ + [NSApp terminate:nil]; + }]; + + dispatch_async(dispatch_get_main_queue(), ^{ + [weakSelf showInstallerProgress]; + }); + } + }]; +} + +- (void)showInstallerProgress +{ + [self.statusController setButtonTitle:SULocalizedString(@"Cancel Update", @"") target:nil action:nil isDefault:NO]; + [self.statusController beginActionWithTitle:SULocalizedString(@"Installing update...", @"") maxProgressValue:0 statusText:@""]; + [self.statusController showWindow:self]; +} + +@end + +int main(int __unused argc, const char __unused *argv[]) +{ + @autoreleasepool + { + NSArray *args = [[NSProcessInfo processInfo] arguments]; + if (args.count != 2) { + return EXIT_FAILURE; + } + + NSString *hostBundlePath = args[1]; + + NSBundle *bundle = [NSBundle bundleWithPath:hostBundlePath]; + if (bundle == nil) { + SULog(@"Error: bundle at %@ is nil", hostBundlePath); + return EXIT_FAILURE; + } + + SUHost *host = [[SUHost alloc] initWithBundle:bundle]; + InstallerProgress *delegate = [[InstallerProgress alloc] initWithHost:host]; + + NSApplication *application = [NSApplication sharedApplication]; + [application setDelegate:delegate]; + + [application run]; + } + + return EXIT_SUCCESS; +} diff --git a/Sparkle/SUInstallerDriver.m b/Sparkle/SUInstallerDriver.m index 86a72bb7..524a712c 100644 --- a/Sparkle/SUInstallerDriver.m +++ b/Sparkle/SUInstallerDriver.m @@ -212,7 +212,13 @@ decryptionPassword = [self.updaterDelegate decryptionPasswordForUpdater:self.updater]; } - SUInstallationInputData *installationData = [[SUInstallationInputData alloc] initWithRelaunchPath:pathToRelaunch hostBundlePath:self.host.bundlePath updateDirectoryPath:self.temporaryDirectory downloadPath:self.downloadPath dsaSignature:dsaSignature decryptionPassword:decryptionPassword]; + NSError *progressToolError = nil; + NSString *progressToolPath = [self copyApplicationResourceToCacheDirectory:@""SPARKLE_INSTALLER_PROGRESS_TOOL_NAME error:&progressToolError]; + if (progressToolPath == nil) { + SULog(@"Error: Failed to copy or find installer progress tool: %@", progressToolError); + } + + SUInstallationInputData *installationData = [[SUInstallationInputData alloc] initWithRelaunchPath:pathToRelaunch progressToolPath:progressToolPath hostBundlePath:self.host.bundlePath updateDirectoryPath:self.temporaryDirectory downloadPath:self.downloadPath dsaSignature:dsaSignature decryptionPassword:decryptionPassword]; NSData *archivedData = SUArchiveRootObjectSecurely(installationData); @@ -311,7 +317,7 @@ // Creates intermediate directories up until targetPath if they don't already exist, // and removes the directory at targetPath if one already exists there -- (BOOL)preparePathForRelaunchTool:(NSString *)targetPath error:(NSError * __autoreleasing *)error +- (BOOL)preparePath:(NSString *)targetPath error:(NSError * __autoreleasing *)error { NSFileManager *fileManager = [[NSFileManager alloc] init]; if ([fileManager fileExistsAtPath:targetPath]) { @@ -334,60 +340,66 @@ return YES; } -- (void)launchAutoUpdateWithCompletion:(void (^)(NSError *_Nullable))completionHandler +- (NSString *)copyApplicationResourceToCacheDirectory:(NSString *)resource error:(NSError * __autoreleasing *)error { - NSBundle *sparkleBundle = self.sparkleBundle; - - NSString *relaunchPath = nil; - - // Copy the relauncher into a temporary directory so we can get to it after the new version's installed. - // Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems. - NSString *const relaunchToolName = @"" SPARKLE_RELAUNCH_TOOL_NAME; - NSString *const relaunchPathToCopy = [sparkleBundle pathForResource:relaunchToolName ofType:@"app"]; - if (relaunchPathToCopy != nil) { - NSString *targetPath = [self.cachePath stringByAppendingPathComponent:[relaunchPathToCopy lastPathComponent]]; - - SUFileManager *fileManager = [SUFileManager fileManagerAllowingAuthorization:NO]; - NSError *error = nil; - - NSURL *relaunchURLToCopy = [NSURL fileURLWithPath:relaunchPathToCopy]; - NSURL *targetURL = [NSURL fileURLWithPath:targetPath]; - - // We only need to run our copy of the app by spawning a task - // Since we are copying the app to a directory that is write-accessible, we don't need to muck with owner/group IDs - if ([self preparePathForRelaunchTool:targetPath error:&error] && [fileManager copyItemAtURL:relaunchURLToCopy toURL:targetURL error:&error]) { - relaunchPath = targetPath; - } else { - NSError *prepareError = + // Copy the resource into the caches directory so we can get to it after the new version's installed. + // Only the paranoid survive: if there's already a stray copy of resource there, we would have problems. + NSString *cachePath = nil; + NSString *const pathToCopy = [self.sparkleBundle pathForResource:resource ofType:@"app"]; + if (pathToCopy == nil) { + if (error != NULL) { + *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:@{ - NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil), - NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"Couldn't copy relauncher (%@) to temporary path (%@)! %@", relaunchPathToCopy, targetPath, (error ? [error localizedDescription] : @"")] + NSLocalizedDescriptionKey: [NSString stringWithFormat:SULocalizedString(@"An error occurred while relaunching %1$@, but the new version will be available next time you run %1$@.", nil), [self.host name]], + NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"Couldn't find the relauncher (expected to find it at %@)", pathToCopy] } ]; - - completionHandler(prepareError); - return; + } + } else { + NSString *targetPath = [self.cachePath stringByAppendingPathComponent:[pathToCopy lastPathComponent]]; + + SUFileManager *fileManager = [SUFileManager fileManagerAllowingAuthorization:NO]; + + NSURL *urlToCopy = [NSURL fileURLWithPath:pathToCopy]; + NSURL *targetURL = [NSURL fileURLWithPath:targetPath]; + + NSError *prepareOrCopyError = nil; + + // We only need to run our copy of the app by spawning a task + // Since we are copying the app to a directory that is write-accessible, we don't need to muck with owner/group IDs + if ([self preparePath:targetPath error:&prepareOrCopyError] && [fileManager copyItemAtURL:urlToCopy toURL:targetURL error:&prepareOrCopyError]) { + cachePath = targetPath; + } else { + if (error != NULL) { + *error = + [NSError + errorWithDomain:SUSparkleErrorDomain + code:SURelaunchError + userInfo:@{ + NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil), + NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"Couldn't copy relauncher (%@) to temporary path (%@)! %@", pathToCopy, targetPath, (prepareOrCopyError ? [prepareOrCopyError localizedDescription] : @"")] + } + ]; + } } } - NSString *relaunchToolPath = [[NSBundle bundleWithPath:relaunchPath] bundlePath]; - if (!relaunchToolPath || ![[NSFileManager defaultManager] fileExistsAtPath:relaunchPath]) { - // Note that we explicitly use the host app's name here, since updating plugin for Mail relaunches Mail, not just the plugin. - NSError *error = - [NSError - errorWithDomain:SUSparkleErrorDomain - code:SURelaunchError - userInfo:@{ - NSLocalizedDescriptionKey: [NSString stringWithFormat:SULocalizedString(@"An error occurred while relaunching %1$@, but the new version will be available next time you run %1$@.", nil), [self.host name]], - NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"Couldn't find the relauncher (expected to find it at %@)", relaunchPath] - } - ]; - - // We intentionally don't abandon the update here so that the host won't initiate another. - completionHandler(error); + return cachePath; +} + +- (void)launchAutoUpdateWithCompletion:(void (^)(NSError *_Nullable))completionHandler +{ + NSBundle *sparkleBundle = self.sparkleBundle; + + // Copy the relauncher into a temporary directory so we can get to it after the new version's installed. + // Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems. + NSError *relaunchError = nil; + NSString *relaunchToolPath = [self copyApplicationResourceToCacheDirectory:@""SPARKLE_RELAUNCH_TOOL_NAME error:&relaunchError]; + if (relaunchToolPath == nil) { + completionHandler(relaunchError); return; }