From ad14421b24bf2fd188ee31c1c8fee05d56b17d93 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 13 Aug 2016 11:55:50 -0400 Subject: [PATCH] Pass relaunch path to standard user driver from SUUpdater --- Sparkle/SPUStandardUserDriver.m | 23 ++++++++++++++++++++++- Sparkle/SUUpdater.m | 9 +++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Sparkle/SPUStandardUserDriver.m b/Sparkle/SPUStandardUserDriver.m index 20ec9002..d0e4997d 100644 --- a/Sparkle/SPUStandardUserDriver.m +++ b/Sparkle/SPUStandardUserDriver.m @@ -35,6 +35,12 @@ @end +@interface NSObject (Private) + +- (NSString * _Nullable)_pathToTerminateForStandardUserDriver; + +@end + @implementation SPUStandardUserDriver @synthesize host = _host; @@ -400,7 +406,22 @@ [self.statusController close]; self.statusController = nil; - [self.uiComponent terminateApplicationForBundle:self.applicationBundle]; + // 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; + } + + [self.uiComponent terminateApplicationForBundle:applicationBundle]; }); } diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 5a125915..3362a81a 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -74,6 +74,9 @@ static NSMutableDictionary *sharedUpdaters = nil; } [sharedUpdaters setObject:self forKey:[NSValue valueWithNonretainedObject:bundle]]; + // 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] below which resolves this _userDriver = [[SPUStandardUserDriver alloc] initWithHostBundle:bundle applicationBundle:bundle delegate:self]; _updater = [[SPUUpdater alloc] initWithHostBundle:bundle userDriver:_userDriver delegate:self]; @@ -408,6 +411,12 @@ 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;