From 46a75cde97cc1d47b4a8a90e63055c2f5fb77028 Mon Sep 17 00:00:00 2001 From: Zorg Date: Thu, 25 Aug 2016 23:46:42 -0400 Subject: [PATCH] Terminate application in the progress agent instead of user driver This allows us to remove SPUUserDriverUIComponent and remove a bunch of logic in the user driver regarding termination. The user drivers generally don't need to know about the application bundle anymore, and strictly now only show UI events. This has another advantage of the agent being able to quit multiple instances of an application even if the application to update is sandboxed. We enforce the logic that an application can only be relaunched if it was running initially. --- Autoupdate/AppInstaller.m | 25 ++++---- Sparkle.xcodeproj/project.pbxproj | 16 ++--- .../InstallerProgressAppController.m | 58 ++++++++++++++++-- .../SPUInstallerAgentProtocol.h | 2 + Sparkle/SPUApplicationInfo.h | 4 -- Sparkle/SPUApplicationInfo.m | 32 ---------- Sparkle/SPUStandardUpdaterController.m | 2 +- Sparkle/SPUStandardUserDriver.h | 3 +- Sparkle/SPUStandardUserDriver.m | 59 +++---------------- Sparkle/SPUUserDriver.h | 32 ++++------ Sparkle/SPUUserDriverUIComponent.h | 26 -------- Sparkle/SPUUserDriverUIComponent.m | 48 --------------- Sparkle/SUAutomaticUpdateDriver.m | 7 --- Sparkle/SUCoreBasedUpdateDriver.h | 2 +- Sparkle/SUCoreBasedUpdateDriver.m | 6 +- Sparkle/SUInstallerDriver.h | 2 +- Sparkle/SUInstallerDriver.m | 2 +- Sparkle/SUUIBasedUpdateDriver.m | 4 +- Sparkle/SUUpdater.m | 8 +-- Sparkle/Sparkle.h | 1 - TestApplication/SUPopUpTitlebarUserDriver.h | 4 +- TestApplication/SUPopUpTitlebarUserDriver.m | 35 +++-------- .../SUUpdateSettingsWindowController.m | 4 +- sparkle-cli/SPUCommandLineDriver.m | 2 +- sparkle-cli/SPUCommandLineUserDriver.h | 2 +- sparkle-cli/SPUCommandLineUserDriver.m | 29 ++------- 26 files changed, 123 insertions(+), 292 deletions(-) delete mode 100644 Sparkle/SPUUserDriverUIComponent.h delete mode 100644 Sparkle/SPUUserDriverUIComponent.m diff --git a/Autoupdate/AppInstaller.m b/Autoupdate/AppInstaller.m index 6fd8aae2..4cbd6990 100644 --- a/Autoupdate/AppInstaller.m +++ b/Autoupdate/AppInstaller.m @@ -428,20 +428,17 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7; uint8_t showsUI = *((const uint8_t *)data.bytes + 1); dispatch_async(dispatch_get_main_queue(), ^{ - // Only applicable to stage 2 + // This flag has an impact on interactive type installations and showing UI progress during non-interactive installations self.shouldShowUI = (BOOL)showsUI; + // We only allow relaunching if the application has been alive + self.shouldRelaunch = (BOOL)relaunch && !self.terminationListener.terminated; - // Allow handling if we should relaunch at any time - self.shouldRelaunch = (BOOL)relaunch; - - dispatch_async(dispatch_get_main_queue(), ^{ - if (self.performedStage1Installation) { - // Resume the installation if we aren't done with stage 2 yet, and remind the client we are prepared to relaunch - dispatch_async(self.installerQueue, ^{ - [self performStage2InstallationIfNeeded]; - }); - } - }); + if (self.performedStage1Installation) { + // Resume the installation if we aren't done with stage 2 yet, and remind the client we are prepared to relaunch + dispatch_async(self.installerQueue, ^{ + [self performStage2InstallationIfNeeded]; + }); + } }); } else if (identifier == SPUUpdaterAlivePong) { self.receivedUpdaterPong = YES; @@ -515,6 +512,10 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7; NSData *sendData = [NSData dataWithBytes:&targetTerminated length:sizeof(targetTerminated)]; [self.communicator handleMessageWithIdentifier:SPUInstallationFinishedStage2 data:sendData]; + + if (!self.terminationListener.terminated) { + [self.agentConnection.agent sendTerminationSignal]; + } }); } else { SULog(@"Error: Failed to resume installer on stage 2 because installation cannot be installed silently"); diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 78ab92cc..96495591 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -108,7 +108,6 @@ 721BC2101D1CDE55002BC71E /* SPULocalCacheDirectory.m in Sources */ = {isa = PBXBuildFile; fileRef = 721BC20D1D1CDE55002BC71E /* SPULocalCacheDirectory.m */; }; 721C245A1CB75756005440CB /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 525A278F133D6AE900FD8D70 /* Cocoa.framework */; }; 721C245C1CB7576E005440CB /* SUStatusController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6196CFE409C71ADE000DC222 /* SUStatusController.m */; }; - 721C245D1CB757C4005440CB /* SPUApplicationInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 725602D41C83551C00DAA70E /* SPUApplicationInfo.m */; }; 721C245E1CB757DE005440CB /* SUConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A5F09CA6EB100B7442F /* SUConstants.m */; }; 721C24611CB75C5D005440CB /* SUHost.m in Sources */ = {isa = PBXBuildFile; fileRef = 61EF67550E25B58D00F754E0 /* SUHost.m */; }; 721C24621CB75C68005440CB /* SULog.m in Sources */ = {isa = PBXBuildFile; fileRef = 55C14F05136EF6DB00649790 /* SULog.m */; }; @@ -153,6 +152,8 @@ 724BB3B11D3484B2005D534A /* SPUSystemAuthorization.m in Sources */ = {isa = PBXBuildFile; fileRef = 724BB3AC1D347EDE005D534A /* SPUSystemAuthorization.m */; }; 724BB3B21D34862A005D534A /* SPUSystemAuthorization.m in Sources */ = {isa = PBXBuildFile; fileRef = 724BB3AC1D347EDE005D534A /* SPUSystemAuthorization.m */; }; 724BB3B71D35ABA8005D534A /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 61B5F8F609C4CEB300B25A18 /* Security.framework */; }; + 724F76F91D6EAD0D00ECD062 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 525A278F133D6AE900FD8D70 /* Cocoa.framework */; }; + 724F76FA1D6EB8ED00ECD062 /* SPUApplicationInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 725602D41C83551C00DAA70E /* SPUApplicationInfo.m */; }; 725264A91D5FBD9100CD6400 /* Sparkle.strings in Resources */ = {isa = PBXBuildFile; fileRef = 61AAE8220A321A7F00D8810D /* Sparkle.strings */; }; 725602D51C83551C00DAA70E /* SPUApplicationInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 725602D31C83551C00DAA70E /* SPUApplicationInfo.h */; }; 725602D61C83551C00DAA70E /* SPUApplicationInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 725602D41C83551C00DAA70E /* SPUApplicationInfo.m */; }; @@ -332,7 +333,6 @@ 72A5D5F01D692C4B0009E5AC /* Updater.app in CopyFiles */ = {isa = PBXBuildFile; fileRef = 721C24451CB753E6005440CB /* Updater.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 72A5D5F41D692CF50009E5AC /* SparkleCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 72A5D59C1D6927730009E5AC /* SparkleCore.framework */; }; 72A5D5F51D692CFE0009E5AC /* SparkleCore.framework in Copy Sparkle */ = {isa = PBXBuildFile; fileRef = 72A5D59C1D6927730009E5AC /* SparkleCore.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 72A5D5F71D692D900009E5AC /* SPUApplicationInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 725602D41C83551C00DAA70E /* SPUApplicationInfo.m */; }; 72A5D5F81D692F2B0009E5AC /* SUExport.h in Headers */ = {isa = PBXBuildFile; fileRef = 14652F8319A9759F00959E44 /* SUExport.h */; settings = {ATTRIBUTES = (Public, ); }; }; 72A5D5F91D692F4C0009E5AC /* SPUStatusCompletionResults.h in Headers */ = {isa = PBXBuildFile; fileRef = 726DF88D1C84277500188804 /* SPUStatusCompletionResults.h */; settings = {ATTRIBUTES = (Public, ); }; }; 72A5D5FB1D69312F0009E5AC /* SPUBundleIcon.m in Sources */ = {isa = PBXBuildFile; fileRef = 7214B8801D456A8500CB5CED /* SPUBundleIcon.m */; }; @@ -398,8 +398,6 @@ 72F9EC441D5E9ED8004AC8B6 /* SPUDownloadData.h in Headers */ = {isa = PBXBuildFile; fileRef = 72F9EC421D5E9ED8004AC8B6 /* SPUDownloadData.h */; settings = {ATTRIBUTES = (Public, ); }; }; 72F9EC451D5E9ED8004AC8B6 /* SPUDownloadData.m in Sources */ = {isa = PBXBuildFile; fileRef = 72F9EC431D5E9ED8004AC8B6 /* SPUDownloadData.m */; }; 72F9EC481D5EA904004AC8B6 /* SPUUpdaterDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 72F9EC471D5EA7D3004AC8B6 /* SPUUpdaterDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 72F9EC4B1D5F53A7004AC8B6 /* SPUUserDriverUIComponent.h in Headers */ = {isa = PBXBuildFile; fileRef = 72F9EC491D5F53A7004AC8B6 /* SPUUserDriverUIComponent.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 72F9EC4C1D5F53A7004AC8B6 /* SPUUserDriverUIComponent.m in Sources */ = {isa = PBXBuildFile; fileRef = 72F9EC4A1D5F53A7004AC8B6 /* SPUUserDriverUIComponent.m */; }; C23E885B1BE7B24F0050BB73 /* SparkleTestCodeSignApp.enc.dmg in Resources */ = {isa = PBXBuildFile; fileRef = C23E88591BE7AF890050BB73 /* SparkleTestCodeSignApp.enc.dmg */; }; F8761EB11ADC5068000C9034 /* SUCodeSigningVerifierTest.m in Sources */ = {isa = PBXBuildFile; fileRef = F8761EB01ADC5068000C9034 /* SUCodeSigningVerifierTest.m */; }; F8761EB31ADC50EB000C9034 /* SparkleTestCodeSignApp.zip in Resources */ = {isa = PBXBuildFile; fileRef = F8761EB21ADC50EB000C9034 /* SparkleTestCodeSignApp.zip */; }; @@ -1121,8 +1119,6 @@ 72F9EC421D5E9ED8004AC8B6 /* SPUDownloadData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUDownloadData.h; sourceTree = ""; }; 72F9EC431D5E9ED8004AC8B6 /* SPUDownloadData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPUDownloadData.m; sourceTree = ""; }; 72F9EC471D5EA7D3004AC8B6 /* SPUUpdaterDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SPUUpdaterDelegate.h; sourceTree = ""; }; - 72F9EC491D5F53A7004AC8B6 /* SPUUserDriverUIComponent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUUserDriverUIComponent.h; sourceTree = ""; }; - 72F9EC4A1D5F53A7004AC8B6 /* SPUUserDriverUIComponent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPUUserDriverUIComponent.m; sourceTree = ""; }; 8DC2EF5A0486A6940098B216 /* Sparkle-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Sparkle-Info.plist"; sourceTree = ""; }; 8DC2EF5B0486A6940098B216 /* Sparkle.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Sparkle.framework; sourceTree = BUILT_PRODUCTS_DIR; }; A5BF4F1B1BC7668B007A052A /* SUTestWebServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUTestWebServer.h; sourceTree = ""; }; @@ -1255,6 +1251,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 724F76F91D6EAD0D00ECD062 /* Cocoa.framework in Frameworks */, 72A5D5F41D692CF50009E5AC /* SparkleCore.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1757,8 +1754,6 @@ 725CB9561C7120410064365A /* SPUUserDriver.h */, 725F97791C8A896F00265BE4 /* SPUUserDriverCoreComponent.h */, 725F977A1C8A896F00265BE4 /* SPUUserDriverCoreComponent.m */, - 72F9EC491D5F53A7004AC8B6 /* SPUUserDriverUIComponent.h */, - 72F9EC4A1D5F53A7004AC8B6 /* SPUUserDriverUIComponent.m */, 726DF88D1C84277500188804 /* SPUStatusCompletionResults.h */, 7246E0A11C83B685003B4E75 /* SPUStandardUpdaterController.h */, 7246E0A21C83B685003B4E75 /* SPUStandardUpdaterController.m */, @@ -1960,7 +1955,6 @@ buildActionMask = 2147483647; files = ( 72DBA37D1D60CC34002594A8 /* SPUUpdatePermissionRequest.h in Headers */, - 72F9EC4B1D5F53A7004AC8B6 /* SPUUserDriverUIComponent.h in Headers */, 72F9EC441D5E9ED8004AC8B6 /* SPUDownloadData.h in Headers */, 725F977B1C8A896F00265BE4 /* SPUUserDriverCoreComponent.h in Headers */, 72F9EC481D5EA904004AC8B6 /* SPUUpdaterDelegate.h in Headers */, @@ -2840,6 +2834,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 724F76FA1D6EB8ED00ECD062 /* SPUApplicationInfo.m in Sources */, 72A5D6001D6932540009E5AC /* SPUApplicationIcon.m in Sources */, 7214B8831D456C2400CB5CED /* SPUBundleIcon.m in Sources */, 7267E5FA1D3DAC3600D1BF90 /* StatusInfo.m in Sources */, @@ -2852,7 +2847,6 @@ 72EB87EA1CB8798800C37F42 /* ShowInstallerProgress.m in Sources */, 721C24611CB75C5D005440CB /* SUHost.m in Sources */, 721C245E1CB757DE005440CB /* SUConstants.m in Sources */, - 721C245D1CB757C4005440CB /* SPUApplicationInfo.m in Sources */, 721C245C1CB7576E005440CB /* SUStatusController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -3027,7 +3021,6 @@ 72D954A51CBB415C006F28BD /* main.m in Sources */, 72D954A21CBB415C006F28BD /* SPUCommandLineDriver.m in Sources */, 72D954B81CBB467F006F28BD /* SPUCommandLineUserDriver.m in Sources */, - 72A5D5F71D692D900009E5AC /* SPUApplicationInfo.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -3043,7 +3036,6 @@ 721BC20F1D1CDE55002BC71E /* SPULocalCacheDirectory.m in Sources */, 7267E5B71D3D8AEE00D1BF90 /* SPUInstallationInfo.m in Sources */, 723B5DAA1CF7AB6A00365F95 /* SPUDownloader.m in Sources */, - 72F9EC4C1D5F53A7004AC8B6 /* SPUUserDriverUIComponent.m in Sources */, 72F94F5A1CC450DE002DEE68 /* SUInstallerLauncher.m in Sources */, 724BB3A91D33461B005D534A /* SUXPCInstallerStatus.m in Sources */, 72F9EC451D5E9ED8004AC8B6 /* SPUDownloadData.m in Sources */, diff --git a/Sparkle/InstallerProgress/InstallerProgressAppController.m b/Sparkle/InstallerProgress/InstallerProgressAppController.m index e30c72fb..9c194001 100644 --- a/Sparkle/InstallerProgress/InstallerProgressAppController.m +++ b/Sparkle/InstallerProgress/InstallerProgressAppController.m @@ -10,7 +10,6 @@ #import "InstallerProgressDelegate.h" #import "SPUMessageTypes.h" #import "SULog.h" -#import "SPUApplicationInfo.h" #import "SPUApplicationIcon.h" #import "SPUInstallerAgentProtocol.h" #import "SUInstallerAgentInitiationProtocol.h" @@ -34,6 +33,8 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3; @property (nonatomic) StatusInfo *statusInfo; @property (nonatomic) BOOL submittedLauncherJob; @property (nonatomic) BOOL willTerminate; +@property (nonatomic) BOOL applicationInitiallyAlive; +@property (nonatomic) NSBundle *applicationBundle; @end @@ -50,6 +51,8 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3; @synthesize statusInfo = _statusInfo; @synthesize submittedLauncherJob = _submittedLauncherJob; @synthesize willTerminate = _willTerminate; +@synthesize applicationInitiallyAlive = _applicationInitiallyAlive; +@synthesize applicationBundle = _applicationBundle; - (instancetype)initWithApplication:(NSApplication *)application arguments:(NSArray *)arguments delegate:(id)delegate { @@ -163,6 +166,32 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3; exit(status); } +- (NSArray *)runningApplicationsWithBundle:(NSBundle *)bundle +{ + // Resolve symlinks otherwise when we compare file paths, we may not realize two paths that are represented differently are the same + NSArray *bundlePathComponents = bundle.bundlePath.stringByResolvingSymlinksInPath.pathComponents; + NSString *bundleIdentifier = bundle.bundleIdentifier; + + NSMutableArray *matchedRunningApplications = [[NSMutableArray alloc] init]; + + if (bundleIdentifier != nil && bundlePathComponents != nil) { + NSArray *runningApplications = + (bundleIdentifier != nil) ? + [NSRunningApplication runningApplicationsWithBundleIdentifier:bundleIdentifier] : + [[NSWorkspace sharedWorkspace] runningApplications]; + + for (NSRunningApplication *runningApplication in runningApplications) { + // Comparing the URLs hasn't worked well for me in practice, so I'm comparing the file paths instead + NSString *candidatePath = runningApplication.bundleURL.URLByResolvingSymlinksInPath.path; + if (candidatePath != nil && [candidatePath.pathComponents isEqualToArray:bundlePathComponents]) { + [matchedRunningApplications addObject:runningApplication]; + } + } + } + + return [matchedRunningApplications copy]; +} + - (void)registerRelaunchBundlePath:(NSString *)relaunchBundlePath reply:(void (^)(NSNumber *))reply { dispatch_async(dispatch_get_main_queue(), ^{ @@ -173,12 +202,21 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3; [self cleanupAndExitWithStatus:EXIT_FAILURE]; } - NSRunningApplication *runningApplication = [SPUApplicationInfo runningApplicationWithBundle:relaunchBundle]; - NSNumber *processIdentifier = (runningApplication == nil || runningApplication.terminated) ? nil : @(runningApplication.processIdentifier); + NSArray *runningApplications = [self runningApplicationsWithBundle:relaunchBundle]; + + // We're just picking the first running application to send.. + // Ideally we'd send them all and have the installer monitor all of them but I don't want to deal with that complexity at the moment + // Although that would still have the issue if another instance of the application launched during that duration + // At the same time we don't want the installer to be over-reliant on us (the agent tool) in a way that could leave the installer as a zombie by accident + // Lastly we don't handle monitoring or terminating processes from logged in user's + NSRunningApplication *firstRunningApplication = runningApplications.firstObject; + NSNumber *processIdentifier = (firstRunningApplication == nil || firstRunningApplication.terminated) ? nil : @(firstRunningApplication.processIdentifier); reply(processIdentifier); self.repliedToRegistration = YES; + self.applicationBundle = relaunchBundle; + self.applicationInitiallyAlive = (processIdentifier != nil); } }); } @@ -192,12 +230,24 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3; }); } +- (void)sendTerminationSignal +{ + dispatch_async(dispatch_get_main_queue(), ^{ + if (!self.willTerminate && self.applicationBundle != nil && self.applicationInitiallyAlive) { + // Note we are sending an Apple quit event, which gives the application or user a chance to delay or cancel the request, which is what we desire + for (NSRunningApplication *runningApplication in [self runningApplicationsWithBundle:self.applicationBundle]) { + [runningApplication terminate]; + } + } + }); +} + // The pathToRelaunch passed to here is not necessarily the same as the one passed in -registerRelaunchBundlePath:reply: if the developer uses SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME // Note the installer won't tell us to launch an application unless it was already running before - (void)relaunchPath:(NSString *)pathToRelaunch { dispatch_async(dispatch_get_main_queue(), ^{ - if (!self.willTerminate) { + if (!self.willTerminate && self.applicationInitiallyAlive) { // We only launch applications, but I'm not sure how reliable -launchApplicationAtURL:options:config: is so we're not using it // Eg: http://www.openradar.me/10952677 diff --git a/Sparkle/InstallerProgress/SPUInstallerAgentProtocol.h b/Sparkle/InstallerProgress/SPUInstallerAgentProtocol.h index ca01437d..7bf8823d 100644 --- a/Sparkle/InstallerProgress/SPUInstallerAgentProtocol.h +++ b/Sparkle/InstallerProgress/SPUInstallerAgentProtocol.h @@ -16,6 +16,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)registerInstallationInfoData:(NSData *)installationInfoData; +- (void)sendTerminationSignal; + - (void)showProgress; - (void)stopProgress; diff --git a/Sparkle/SPUApplicationInfo.h b/Sparkle/SPUApplicationInfo.h index d0559766..e0a5bcfa 100644 --- a/Sparkle/SPUApplicationInfo.h +++ b/Sparkle/SPUApplicationInfo.h @@ -14,10 +14,6 @@ NS_ASSUME_NONNULL_BEGIN + (BOOL)isBackgroundApplication:(NSApplication *)application; -+ (NSArray *)runningApplicationsWithBundle:(NSBundle *)bundle; - -+ (NSRunningApplication * _Nullable)runningApplicationWithBundle:(NSBundle *)bundle; - @end NS_ASSUME_NONNULL_END diff --git a/Sparkle/SPUApplicationInfo.m b/Sparkle/SPUApplicationInfo.m index 931ac8ee..8bbc8cf7 100644 --- a/Sparkle/SPUApplicationInfo.m +++ b/Sparkle/SPUApplicationInfo.m @@ -7,7 +7,6 @@ // #import "SPUApplicationInfo.h" -#import "SPUBundleIcon.h" @implementation SPUApplicationInfo @@ -16,35 +15,4 @@ return (application.activationPolicy == NSApplicationActivationPolicyAccessory); } -+ (NSArray *)runningApplicationsWithBundle:(NSBundle *)bundle -{ - // Resolve symlinks otherwise when we compare file paths, we may not realize two paths that are represented differently are the same - NSArray *bundlePathComponents = bundle.bundlePath.stringByResolvingSymlinksInPath.pathComponents; - NSString *bundleIdentifier = bundle.bundleIdentifier; - - NSMutableArray *matchedRunningApplications = [[NSMutableArray alloc] init]; - - if (bundleIdentifier != nil && bundlePathComponents != nil) { - NSArray *runningApplications = - (bundleIdentifier != nil) ? - [NSRunningApplication runningApplicationsWithBundleIdentifier:bundleIdentifier] : - [[NSWorkspace sharedWorkspace] runningApplications]; - - for (NSRunningApplication *runningApplication in runningApplications) { - // Comparing the URLs hasn't worked well for me in practice, so I'm comparing the file paths instead - NSString *candidatePath = runningApplication.bundleURL.URLByResolvingSymlinksInPath.path; - if (candidatePath != nil && [candidatePath.pathComponents isEqualToArray:bundlePathComponents]) { - [matchedRunningApplications addObject:runningApplication]; - } - } - } - - return [matchedRunningApplications copy]; -} - -+ (NSRunningApplication *)runningApplicationWithBundle:(NSBundle *)bundle -{ - return [[self runningApplicationsWithBundle:bundle] firstObject]; -} - @end diff --git a/Sparkle/SPUStandardUpdaterController.m b/Sparkle/SPUStandardUpdaterController.m index 325f2a55..e217d21c 100644 --- a/Sparkle/SPUStandardUpdaterController.m +++ b/Sparkle/SPUStandardUpdaterController.m @@ -40,7 +40,7 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults self.initializedUpdater = YES; NSBundle *hostBundle = [NSBundle mainBundle]; - id userDriver = [[SPUStandardUserDriver alloc] initWithHostBundle:hostBundle applicationBundle:hostBundle delegate:self.userDriverDelegate]; + id userDriver = [[SPUStandardUserDriver alloc] initWithHostBundle:hostBundle delegate:self.userDriverDelegate]; self.updater = [[SPUUpdater alloc] initWithHostBundle:hostBundle applicationBundle:hostBundle userDriver:userDriver delegate:self.updaterDelegate]; self.userDriver = userDriver; diff --git a/Sparkle/SPUStandardUserDriver.h b/Sparkle/SPUStandardUserDriver.h index ac569715..e7e1330b 100644 --- a/Sparkle/SPUStandardUserDriver.h +++ b/Sparkle/SPUStandardUserDriver.h @@ -24,10 +24,9 @@ SU_EXPORT @interface SPUStandardUserDriver : NSObject )delegate; +- (instancetype)initWithHostBundle:(NSBundle *)hostBundle delegate:(nullable id)delegate; @end diff --git a/Sparkle/SPUStandardUserDriver.m b/Sparkle/SPUStandardUserDriver.m index 15bbdbb1..30c77304 100644 --- a/Sparkle/SPUStandardUserDriver.m +++ b/Sparkle/SPUStandardUserDriver.m @@ -8,7 +8,6 @@ #import "SPUStandardUserDriver.h" #import "SPUUserDriverCoreComponent.h" -#import "SPUUserDriverUIComponent.h" #import "SPUStandardUserDriverDelegate.h" #import "SUAppcastItem.h" #import "SUVersionDisplayProtocol.h" @@ -23,10 +22,8 @@ @interface SPUStandardUserDriver () @property (nonatomic, readonly) SUHost *host; -@property (nonatomic, readonly) NSBundle *applicationBundle; @property (nonatomic, readonly) SPUUserDriverCoreComponent *coreComponent; -@property (nonatomic, readonly) SPUUserDriverUIComponent *uiComponent; @property (nonatomic, weak, nullable, readonly) id delegate; @property (nonatomic) SUStatusController *checkingController; @@ -35,18 +32,10 @@ @end -@interface NSObject (Private) - -- (NSString * _Nullable)_pathToTerminateForStandardUserDriver; - -@end - @implementation SPUStandardUserDriver @synthesize host = _host; -@synthesize applicationBundle = _applicationBundle; @synthesize coreComponent = _coreComponent; -@synthesize uiComponent = _uiComponent; @synthesize delegate = _delegate; @synthesize checkingController = _checkingController; @synthesize activeUpdateAlert = _activeUpdateAlert; @@ -54,15 +43,13 @@ #pragma mark Birth -- (instancetype)initWithHostBundle:(NSBundle *)hostBundle applicationBundle:(NSBundle *)applicationBundle delegate:(nullable id)delegate +- (instancetype)initWithHostBundle:(NSBundle *)hostBundle delegate:(nullable id)delegate { self = [super init]; if (self != nil) { _host = [[SUHost alloc] initWithBundle:hostBundle]; - _applicationBundle = applicationBundle; _delegate = delegate; _coreComponent = [[SPUUserDriverCoreComponent alloc] init]; - _uiComponent = [[SPUUserDriverUIComponent alloc] init]; } return self; } @@ -404,46 +391,14 @@ #pragma mark Aborting Everything -- (BOOL)_terminateApplicationAndWillTerminateCurrentApplication -{ - // Give the delegate a deferred chance for providing an application path - // This is a private API and used by SUUpdater - NSString *applicationPath = nil; - if ([self.delegate respondsToSelector:@selector(_pathToTerminateForStandardUserDriver)]) { - applicationPath = [(NSObject *)self.delegate _pathToTerminateForStandardUserDriver]; - } - - NSBundle *applicationBundle; - if (applicationPath != nil) { - applicationBundle = [NSBundle bundleWithPath:applicationPath]; - assert(applicationBundle != nil); - } else { - applicationBundle = self.applicationBundle; - } - - return [self.uiComponent terminateApplicationForBundleAndWillTerminateCurrentApplication:applicationBundle]; -} - -- (void)terminateApplication +- (void)showSendingTerminationSignal { dispatch_async(dispatch_get_main_queue(), ^{ - if ([self _terminateApplicationAndWillTerminateCurrentApplication]) { - // if a user chooses to NOT relaunch the app (as is the case with WebKit - // when it asks you if you are sure you want to close the app with multiple - // tabs open), the status window still stays on the screen and obscures - // other windows; with this fix, it doesn't - [self.statusController close]; - self.statusController = nil; - } else { - [self _showInstallingUpdate]; - } - }); -} - -- (void)terminateApplicationSilently -{ - dispatch_async(dispatch_get_main_queue(), ^{ - [self _terminateApplicationAndWillTerminateCurrentApplication]; + // The "quit" event can always be canceled or delayed by the application we're updating + // So we can't easily predict how long the installation will take or if it won't happen right away + // We close our status window because we don't want it persisting for too long and have it obscure other windows + [self.statusController close]; + self.statusController = nil; }); } diff --git a/Sparkle/SPUUserDriver.h b/Sparkle/SPUUserDriver.h index 250bc4a0..fa640ce5 100644 --- a/Sparkle/SPUUserDriver.h +++ b/Sparkle/SPUUserDriver.h @@ -112,7 +112,9 @@ SU_EXPORT @protocol SPUUserDriver * * @param appcastItem The Appcast Item containing information that reflects the new update * - * @param reply A reply of SPUInstallAndRelaunchUpdateNow installs the update immediately and relaunches the new update. + * @param reply + * A reply of SPUInstallAndRelaunchUpdateNow installs the update immediately and relaunches the new update. + * Note: the application is not relaunched if it was not running before installing the update. * A reply of SPUInstallUpdateNow installs the update immediately but does not relaunch the new update. * A reply of SPUDismissUpdateInstallation dismisses the update installation. Note the update will attempt to finish installation * after the application terminates. @@ -233,7 +235,9 @@ SU_EXPORT @protocol SPUUserDriver * Let the user know that the update is ready and ask them whether they want to install or not. * Note if the target application is already terminated and an update can be performed silently, this method may not be invoked. * - * @param installUpdateHandler A reply of SPUInstallAndRelaunchUpdateNow installs the update immediately and relaunches the new update. + * @param installUpdateHandler + * A reply of SPUInstallAndRelaunchUpdateNow installs the update immediately and relaunches the new update. + * Note: the application is not relaunched if it was not running before installing the update. * A reply of SPUInstallUpdateNow installes the update immediately but does not relaunch the new update. * A reply of SPUDismissUpdateInstallation dismisses the update installation. Note the update may still be installed after * the application terminates, however there is not a strong guarantee that this will happen. @@ -252,29 +256,17 @@ SU_EXPORT @protocol SPUUserDriver - (void)showInstallingUpdate; /*! - * Terminate the application and show or dismiss installer progress. + * Show or dismiss progress while a termination signal is being sent to the application * - * Sparkle is asking us to send a request to terminate the application. + * Terminating and relaunching the application (if requested to be relaunched) may happen quickly, + * or it may take some time to perform the final installation, or the termination signal can be canceled or delayed by the application or user. * - * If this will terminate the current application, an implementor may decide to dismiss progress UI in case the termination request is delayed or canceled. - * Or if this will terminate a remote application, an implementor may decide to show the user that the update is currently installing. + * It is up to the implementor whether or not to decide to continue showing installation progress + * or dismissing UI that won't remain obscuring other parts of the user interface. * * This can be called from any thread */ -- (void)terminateApplication; - -/*! - * Terminate the application silently. - * - * Sparkle is asking us to send a request to terminate the application without showing any UI interaction. - * This may be invoked after Sparkle has downloaded an update in the background automatically, - * and the updater's delegate has decided to install & relaunch the application without disrupting the user (think of a backgrounded application). - * - * After the application is terminated, the update will be installed and the application will be relaunched. - * - * This can be called from any thread - */ -- (void)terminateApplicationSilently; +- (void)showSendingTerminationSignal; /*! * Show the user that the update installation finished diff --git a/Sparkle/SPUUserDriverUIComponent.h b/Sparkle/SPUUserDriverUIComponent.h deleted file mode 100644 index ee8e2d5d..00000000 --- a/Sparkle/SPUUserDriverUIComponent.h +++ /dev/null @@ -1,26 +0,0 @@ -// -// SPUUserDriverUIComponent.h -// Sparkle -// -// Created by Mayur Pawashe on 8/13/16. -// Copyright © 2016 Sparkle Project. All rights reserved. -// - -#import -#import "SUExport.h" - -NS_ASSUME_NONNULL_BEGIN - -SU_EXPORT @interface SPUUserDriverUIComponent : NSObject - -- (instancetype)init; - -- (BOOL)terminateApplicationForBundleAndWillTerminateCurrentApplication:(NSBundle *)bundle; - -- (void)terminateApplicationForBundle:(NSBundle *)bundle; - -- (BOOL)applicationIsAliveForBundle:(NSBundle *)bundle; - -@end - -NS_ASSUME_NONNULL_END diff --git a/Sparkle/SPUUserDriverUIComponent.m b/Sparkle/SPUUserDriverUIComponent.m deleted file mode 100644 index 79ace719..00000000 --- a/Sparkle/SPUUserDriverUIComponent.m +++ /dev/null @@ -1,48 +0,0 @@ -// -// SPUUserDriverUIComponent.m -// Sparkle -// -// Created by Mayur Pawashe on 8/13/16. -// Copyright © 2016 Sparkle Project. All rights reserved. -// - -#import "SPUUserDriverUIComponent.h" -#import "SPUApplicationInfo.h" - -@implementation SPUUserDriverUIComponent - -- (instancetype)init -{ - self = [super init]; - if (self != nil) { - } - return self; -} - -- (void)terminateApplicationForBundle:(NSBundle *)bundle -{ - [self terminateApplicationForBundleAndWillTerminateCurrentApplication:bundle]; -} - -- (BOOL)terminateApplicationForBundleAndWillTerminateCurrentApplication:(NSBundle *)bundle -{ - NSRunningApplication *currentRunningApplication = [NSRunningApplication currentApplication]; - BOOL willTerminateSelf = NO; - - NSArray *runningApplications = [SPUApplicationInfo runningApplicationsWithBundle:bundle]; - for (NSRunningApplication *runningApplication in runningApplications) { - if (!willTerminateSelf && [currentRunningApplication isEqual:runningApplication]) { - willTerminateSelf = YES; - } - [runningApplication terminate]; - } - - return willTerminateSelf; -} - -- (BOOL)applicationIsAliveForBundle:(NSBundle *)bundle -{ - return ([SPUApplicationInfo runningApplicationWithBundle:bundle] != nil); -} - -@end diff --git a/Sparkle/SUAutomaticUpdateDriver.m b/Sparkle/SUAutomaticUpdateDriver.m index 05304b1d..b4cea378 100644 --- a/Sparkle/SUAutomaticUpdateDriver.m +++ b/Sparkle/SUAutomaticUpdateDriver.m @@ -109,13 +109,6 @@ } } -// 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 -{ - [self.userDriver terminateApplicationSilently]; -} - - (void)basicDriverIsRequestingAbortUpdateWithError:(NSError *)error { [self abortUpdateWithError:error]; diff --git a/Sparkle/SUCoreBasedUpdateDriver.h b/Sparkle/SUCoreBasedUpdateDriver.h index 96a37c08..c586d480 100644 --- a/Sparkle/SUCoreBasedUpdateDriver.h +++ b/Sparkle/SUCoreBasedUpdateDriver.h @@ -41,7 +41,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)installerDidExtractUpdateWithProgress:(double)progress; -- (void)installerIsRequestingAppTermination; +- (void)installerIsSendingAppTerminationSignal; - (void)installerDidFinishInstallationWithAcknowledgement:(void(^)(void))acknowledgement; diff --git a/Sparkle/SUCoreBasedUpdateDriver.m b/Sparkle/SUCoreBasedUpdateDriver.m index a2a5ecb8..f55c18f7 100644 --- a/Sparkle/SUCoreBasedUpdateDriver.m +++ b/Sparkle/SUCoreBasedUpdateDriver.m @@ -305,11 +305,11 @@ } } -- (void)installerIsRequestingAppTermination +- (void)installerIsSendingAppTerminationSignal { // If they don't respond or do anything, we'll just install after the user terminates the app anyway - if ([self.delegate respondsToSelector:@selector(installerIsRequestingAppTermination)]) { - [self.delegate installerIsRequestingAppTermination]; + if ([self.delegate respondsToSelector:@selector(installerIsSendingAppTerminationSignal)]) { + [self.delegate installerIsSendingAppTerminationSignal]; } } diff --git a/Sparkle/SUInstallerDriver.h b/Sparkle/SUInstallerDriver.h index 88150261..cdb2e4a3 100644 --- a/Sparkle/SUInstallerDriver.h +++ b/Sparkle/SUInstallerDriver.h @@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)installerDidStartInstalling; - (void)installerDidExtractUpdateWithProgress:(double)progress; - (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately silently:(BOOL)willInstallSilently; -- (void)installerIsRequestingAppTermination; +- (void)installerIsSendingAppTerminationSignal; - (void)installerWillFinishInstallationAndRelaunch:(BOOL)relaunch; - (void)installerDidFinishInstallationWithAcknowledgement:(void(^)(void))acknowledgement; diff --git a/Sparkle/SUInstallerDriver.m b/Sparkle/SUInstallerDriver.m index 21c19f67..3f3a37f0 100644 --- a/Sparkle/SUInstallerDriver.m +++ b/Sparkle/SUInstallerDriver.m @@ -287,7 +287,7 @@ [self.delegate installerWillFinishInstallationAndRelaunch:self.willRelaunch]; if (!hasTargetTerminated) { - [self.delegate installerIsRequestingAppTermination]; + [self.delegate installerIsSendingAppTerminationSignal]; } } else if (identifier == SPUInstallationFinishedStage3) { self.currentStage = identifier; diff --git a/Sparkle/SUUIBasedUpdateDriver.m b/Sparkle/SUUIBasedUpdateDriver.m index 60ce14cb..6c63ca9b 100644 --- a/Sparkle/SUUIBasedUpdateDriver.m +++ b/Sparkle/SUUIBasedUpdateDriver.m @@ -214,9 +214,9 @@ } } -- (void)installerIsRequestingAppTermination +- (void)installerIsSendingAppTerminationSignal { - [self.userDriver terminateApplication]; + [self.userDriver showSendingTerminationSignal]; } - (void)installerDidFinishInstallationWithAcknowledgement:(void(^)(void))acknowledgement diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 2d67c016..96a1b8b3 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -77,7 +77,7 @@ static NSMutableDictionary *sharedUpdaters = nil; // This bundle may not necessarily be the correct application bundle // Unfortunately we won't know the correct application bundle until after the delegate is set // See -[SUUpdater _standardUserDriverRequestsPathToRelaunch] and -[SUUpdater _pathToRelaunchForUpdater:] implemented below which resolves this - _userDriver = [[SPUStandardUserDriver alloc] initWithHostBundle:bundle applicationBundle:bundle delegate:self]; + _userDriver = [[SPUStandardUserDriver alloc] initWithHostBundle:bundle delegate:self]; _updater = [[SPUUpdater alloc] initWithHostBundle:bundle applicationBundle:bundle userDriver:_userDriver delegate:self]; NSError *updaterError = nil; @@ -412,12 +412,6 @@ static NSMutableDictionary *sharedUpdaters = nil; return relaunchPath; } -// Private SPUStandardUserDriver API that allows us to defer providing an application path to terminate -- (NSString * _Nullable)_pathToTerminateForStandardUserDriver -{ - return [self _pathToRelaunchForUpdater:self.updater]; -} - - (NSString *)decryptionPasswordForUpdater:(SPUUpdater *)__unused updater { return self.decryptionPassword; diff --git a/Sparkle/Sparkle.h b/Sparkle/Sparkle.h index b5ecd8d1..7f249583 100644 --- a/Sparkle/Sparkle.h +++ b/Sparkle/Sparkle.h @@ -28,7 +28,6 @@ #import "SPUStandardUserDriver.h" #import "SPUStandardUserDriverDelegate.h" #import "SPUUserDriverCoreComponent.h" -#import "SPUUserDriverUIComponent.h" #import "SPUDownloadData.h" #import "SUUpdater.h" // deprecated diff --git a/TestApplication/SUPopUpTitlebarUserDriver.h b/TestApplication/SUPopUpTitlebarUserDriver.h index dbbdcb0f..9742b20c 100644 --- a/TestApplication/SUPopUpTitlebarUserDriver.h +++ b/TestApplication/SUPopUpTitlebarUserDriver.h @@ -9,10 +9,8 @@ #import #import -@protocol SPUStandardUserDriverProtocol; - @interface SUPopUpTitlebarUserDriver : NSObject -- (instancetype)initWithApplicationBundle:(NSBundle *)applicationBundle window:(NSWindow *)window; +- (instancetype)initWithWindow:(NSWindow *)window; @end diff --git a/TestApplication/SUPopUpTitlebarUserDriver.m b/TestApplication/SUPopUpTitlebarUserDriver.m index 301eeb7d..0b37d50b 100644 --- a/TestApplication/SUPopUpTitlebarUserDriver.m +++ b/TestApplication/SUPopUpTitlebarUserDriver.m @@ -11,11 +11,9 @@ @interface SUPopUpTitlebarUserDriver() -@property (nonatomic, readonly) NSBundle *applicationBundle; @property (nonatomic, readonly) NSWindow *window; @property (nonatomic, nullable) SUInstallUpdateViewController *installUpdateViewController; @property (nonatomic, readonly) SPUUserDriverCoreComponent *coreComponent; -@property (nonatomic, readonly) SPUUserDriverUIComponent *uiComponent; @property (nonatomic) NSTitlebarAccessoryViewController *accessoryViewController; @property (nonatomic) BOOL addedAccessory; @property (nonatomic) NSButton *updateButton; @@ -27,11 +25,9 @@ @implementation SUPopUpTitlebarUserDriver -@synthesize applicationBundle = _applicationBundle; @synthesize window = _window; @synthesize installUpdateViewController = _installUpdateViewController; @synthesize coreComponent = _coreComponent; -@synthesize uiComponent = _uiComponent; @synthesize accessoryViewController = _accessoryViewController; @synthesize addedAccessory = _addedAccessory; @synthesize updateButton = _updateButton; @@ -39,14 +35,12 @@ @synthesize expectedContentLength = _expectedContentLength; @synthesize contentLengthDownloaded = _contentLengthDownloaded; -- (instancetype)initWithApplicationBundle:(NSBundle *)applicationBundle window:(NSWindow *)window +- (instancetype)initWithWindow:(NSWindow *)window { self = [super init]; if (self != nil) { - _applicationBundle = applicationBundle; _window = window; _coreComponent = [[SPUUserDriverCoreComponent alloc] init]; - _uiComponent = [[SPUUserDriverUIComponent alloc] init]; } return self; } @@ -314,6 +308,14 @@ }); } +- (void)showSendingTerminationSignal +{ + dispatch_async(dispatch_get_main_queue(), ^{ + // In case our termination request fails or is delayed + [self removeUpdateButton]; + }); +} + - (void)showUpdateInstallationDidFinishWithAcknowledgement:(void (^)(void))acknowledgement { dispatch_async(dispatch_get_main_queue(), ^{ @@ -327,25 +329,6 @@ #pragma mark Aborting Everything -- (void)terminateApplication -{ - dispatch_async(dispatch_get_main_queue(), ^{ - if ([self.uiComponent terminateApplicationForBundleAndWillTerminateCurrentApplication:self.applicationBundle]) { - // In case our termination request fails or is delayed - [self removeUpdateButton]; - } else { - [self addUpdateButtonWithTitle:@"Installing…"]; - } - }); -} - -- (void)terminateApplicationSilently -{ - dispatch_async(dispatch_get_main_queue(), ^{ - [self.uiComponent terminateApplicationForBundle:self.applicationBundle]; - }); -} - - (void)_dismissUpdateInstallation { // Make sure everything we call here does not dispatch async to main queue diff --git a/TestApplication/SUUpdateSettingsWindowController.m b/TestApplication/SUUpdateSettingsWindowController.m index f3c0f4cd..86c3aa13 100644 --- a/TestApplication/SUUpdateSettingsWindowController.m +++ b/TestApplication/SUUpdateSettingsWindowController.m @@ -46,9 +46,9 @@ // If the user is holding down command, we use the popup title user driver instead id userDriver; if (self.customUserDriver) { - userDriver = [[SUPopUpTitlebarUserDriver alloc] initWithApplicationBundle:applicationBundle window:self.window]; + userDriver = [[SUPopUpTitlebarUserDriver alloc] initWithWindow:self.window]; } else { - userDriver = [[SPUStandardUserDriver alloc] initWithHostBundle:hostBundle applicationBundle:applicationBundle delegate:nil]; + userDriver = [[SPUStandardUserDriver alloc] initWithHostBundle:hostBundle delegate:nil]; } self.userDriver = userDriver; diff --git a/sparkle-cli/SPUCommandLineDriver.m b/sparkle-cli/SPUCommandLineDriver.m index 4cb69a50..2360765f 100644 --- a/sparkle-cli/SPUCommandLineDriver.m +++ b/sparkle-cli/SPUCommandLineDriver.m @@ -57,7 +57,7 @@ void _SULogDisableStandardErrorStream(void); _SULogDisableStandardErrorStream(); #endif - id userDriver = [[SPUCommandLineUserDriver alloc] initWithApplicationBundle:applicationBundle updatePermissionResponse:updatePermissionResponse deferInstallation:deferInstallation verbose:verbose]; + id userDriver = [[SPUCommandLineUserDriver alloc] initWithUpdatePermissionResponse:updatePermissionResponse deferInstallation:deferInstallation verbose:verbose]; _updater = [[SPUUpdater alloc] initWithHostBundle:updateBundle applicationBundle:applicationBundle userDriver:userDriver delegate:self]; } return self; diff --git a/sparkle-cli/SPUCommandLineUserDriver.h b/sparkle-cli/SPUCommandLineUserDriver.h index c18b7b40..586e3543 100644 --- a/sparkle-cli/SPUCommandLineUserDriver.h +++ b/sparkle-cli/SPUCommandLineUserDriver.h @@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN @interface SPUCommandLineUserDriver : NSObject -- (instancetype)initWithApplicationBundle:(NSBundle *)applicationBundle updatePermissionResponse:(nullable SPUUpdatePermissionResponse *)updatePermissionResponse deferInstallation:(BOOL)deferInstallation verbose:(BOOL)verbose; +- (instancetype)initWithUpdatePermissionResponse:(nullable SPUUpdatePermissionResponse *)updatePermissionResponse deferInstallation:(BOOL)deferInstallation verbose:(BOOL)verbose; @end diff --git a/sparkle-cli/SPUCommandLineUserDriver.m b/sparkle-cli/SPUCommandLineUserDriver.m index daa6fd4b..77a14ac1 100644 --- a/sparkle-cli/SPUCommandLineUserDriver.m +++ b/sparkle-cli/SPUCommandLineUserDriver.m @@ -11,15 +11,10 @@ #import #import "SPUUserDriverCoreComponent.h" -// Going to borrow this private class from Sparkle -// Note to compile properly, this class must not be exported (which is why we aren't importing SPUUserDriverUIComponent) -#import "SPUApplicationInfo.h" - #define SCHEDULED_UPDATE_TIMER_THRESHOLD 2.0 // seconds @interface SPUCommandLineUserDriver () -@property (nonatomic, readonly) NSBundle *applicationBundle; @property (nonatomic, nullable, readonly) SPUUpdatePermissionResponse *updatePermissionResponse; @property (nonatomic, readonly) BOOL deferInstallation; @property (nonatomic, readonly) BOOL verbose; @@ -31,7 +26,6 @@ @implementation SPUCommandLineUserDriver -@synthesize applicationBundle = _applicationBundle; @synthesize updatePermissionResponse = _updatePermissionResponse; @synthesize deferInstallation = _deferInstallation; @synthesize verbose = _verbose; @@ -39,11 +33,10 @@ @synthesize bytesDownloaded = _bytesDownloaded; @synthesize bytesToDownload = _bytesToDownload; -- (instancetype)initWithApplicationBundle:(NSBundle *)applicationBundle updatePermissionResponse:(nullable SPUUpdatePermissionResponse *)updatePermissionResponse deferInstallation:(BOOL)deferInstallation verbose:(BOOL)verbose +- (instancetype)initWithUpdatePermissionResponse:(nullable SPUUpdatePermissionResponse *)updatePermissionResponse deferInstallation:(BOOL)deferInstallation verbose:(BOOL)verbose { self = [super init]; if (self != nil) { - _applicationBundle = applicationBundle; _updatePermissionResponse = updatePermissionResponse; _deferInstallation = deferInstallation; _verbose = verbose; @@ -102,7 +95,8 @@ - (void)displayHTMLReleaseNotes:(NSData *)releaseNotes { - NSAttributedString *attributedString = [[NSAttributedString alloc] initWithHTML:releaseNotes documentAttributes:NULL]; + // Note: this is the only API we rely on here that references AppKit + NSAttributedString *attributedString = [[NSAttributedString alloc] initWithHTML:releaseNotes documentAttributes:nil]; [self displayReleaseNotes:attributedString.string.UTF8String]; } @@ -272,10 +266,8 @@ fprintf(stderr, "Deferring Installation.\n"); } [self.coreComponent installUpdateWithChoice:SPUDismissUpdateInstallation]; - } else if ([SPUApplicationInfo runningApplicationWithBundle:self.applicationBundle] != nil) { - [self.coreComponent installUpdateWithChoice:SPUInstallAndRelaunchUpdateNow]; } else { - [self.coreComponent installUpdateWithChoice:SPUInstallUpdateNow]; + [self.coreComponent installUpdateWithChoice:SPUInstallAndRelaunchUpdateNow]; } }); } @@ -312,18 +304,9 @@ }); } -- (void)terminateApplication +- (void)showSendingTerminationSignal { - dispatch_async(dispatch_get_main_queue(), ^{ - for (NSRunningApplication *application in [SPUApplicationInfo runningApplicationsWithBundle:self.applicationBundle]) { - [application terminate]; - } - }); -} - -- (void)terminateApplicationSilently -{ - [self terminateApplication]; + // We are already showing that the update is installing, so there is no need to do anything here } @end