From 8eb61afe53b0a2522e4d4246ccfb8127376c04a8 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 13 Aug 2016 10:49:45 -0400 Subject: [PATCH] Use SPUUserDriverUIComponent for command line user driver --- Sparkle/SPUUserDriverUIComponent.h | 2 ++ Sparkle/SPUUserDriverUIComponent.m | 5 +++++ sparkle-cli/SPUCommandLineUserDriver.m | 17 +++++------------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Sparkle/SPUUserDriverUIComponent.h b/Sparkle/SPUUserDriverUIComponent.h index 800878fc..2bac8251 100644 --- a/Sparkle/SPUUserDriverUIComponent.h +++ b/Sparkle/SPUUserDriverUIComponent.h @@ -17,6 +17,8 @@ SU_EXPORT @interface SPUUserDriverUIComponent : NSObject - (void)terminateApplicationForBundle:(NSBundle *)bundle; +- (BOOL)applicationIsAliveForBundle:(NSBundle *)bundle; + @end NS_ASSUME_NONNULL_END diff --git a/Sparkle/SPUUserDriverUIComponent.m b/Sparkle/SPUUserDriverUIComponent.m index 22a95b9d..2836c5f5 100644 --- a/Sparkle/SPUUserDriverUIComponent.m +++ b/Sparkle/SPUUserDriverUIComponent.m @@ -27,4 +27,9 @@ } } +- (BOOL)applicationIsAliveForBundle:(NSBundle *)bundle +{ + return ([SPUApplicationInfo runningApplicationWithBundle:bundle] != nil); +} + @end diff --git a/sparkle-cli/SPUCommandLineUserDriver.m b/sparkle-cli/SPUCommandLineUserDriver.m index 9a1f48ce..94fbac12 100644 --- a/sparkle-cli/SPUCommandLineUserDriver.m +++ b/sparkle-cli/SPUCommandLineUserDriver.m @@ -8,8 +8,6 @@ #import "SPUCommandLineUserDriver.h" #import -#import "SPUApplicationInfo.h" -#import "SPUDownloadData.h" #define SCHEDULED_UPDATE_TIMER_THRESHOLD 2.0 // seconds @@ -20,6 +18,7 @@ @property (nonatomic, readonly) BOOL deferInstallation; @property (nonatomic, readonly) BOOL verbose; @property (nonatomic, readonly) SPUUserDriverCoreComponent *coreComponent; +@property (nonatomic, readonly) SPUUserDriverUIComponent *uiComponent; @property (nonatomic) NSUInteger bytesDownloaded; @property (nonatomic) NSUInteger bytesToDownload; @@ -32,6 +31,7 @@ @synthesize deferInstallation = _deferInstallation; @synthesize verbose = _verbose; @synthesize coreComponent = _coreComponent; +@synthesize uiComponent = _uiComponent; @synthesize bytesDownloaded = _bytesDownloaded; @synthesize bytesToDownload = _bytesToDownload; @@ -44,6 +44,7 @@ _deferInstallation = deferInstallation; _verbose = verbose; _coreComponent = [[SPUUserDriverCoreComponent alloc] init]; + _uiComponent = [[SPUUserDriverUIComponent alloc] init]; } return self; } @@ -268,7 +269,7 @@ fprintf(stderr, "Deferring Installation.\n"); } [self.coreComponent installUpdateWithChoice:SPUDismissUpdateInstallation]; - } else if ([SPUApplicationInfo runningApplicationWithBundle:self.applicationBundle] != nil) { + } else if ([self.uiComponent applicationIsAliveForBundle:self.applicationBundle]) { [self.coreComponent installUpdateWithChoice:SPUInstallAndRelaunchUpdateNow]; } else { [self.coreComponent installUpdateWithChoice:SPUInstallUpdateNow]; @@ -311,15 +312,7 @@ - (void)terminateApplication { dispatch_async(dispatch_get_main_queue(), ^{ - NSRunningApplication *runningApplication = [SPUApplicationInfo runningApplicationWithBundle:self.applicationBundle]; - if (runningApplication != nil) { - if (![runningApplication terminate]) { - if (![runningApplication forceTerminate]) { - fprintf(stderr, "Error: Failed to terminate running application. Please terminate it to update it."); - exit(EXIT_FAILURE); - } - } - } + [self.uiComponent terminateApplicationForBundle:self.applicationBundle]; }); }