From 680d66378deb3c2fed4e0ab44fb9da290572d1de Mon Sep 17 00:00:00 2001 From: Marcus Ososbase Date: Wed, 21 Feb 2018 15:29:55 -0500 Subject: [PATCH] Modified Sparkle to accomodate helper-parent update --- Sparkle/SUBasicUpdateDriver.m | 27 ++++++++++++++++++++++++++- Sparkle/SUUpdaterDelegate.h | 8 ++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index d0f0cc53..957aba1b 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -593,7 +593,32 @@ // Note: this is overridden by the automatic update driver to not terminate in some cases - (void)terminateApp { - [NSApp terminate:self]; + BOOL isMainBundle = [self.host.bundle isEqualTo:[NSBundle mainBundle]]; + + if (isMainBundle) { + [NSApp terminate:self]; + } + else { + NSString *bundleID = self.host.bundle.bundleIdentifier; + if (bundleID.length > 0) { + NSArray *apps = [NSRunningApplication runningApplicationsWithBundleIdentifier:bundleID]; + for (NSRunningApplication *app in apps) { + [app terminate]; + } + + // Notify the mainBundle host the target has been terminated + id updater = self.updater; + id updaterDelegate = [updater delegate]; + if ([updaterDelegate respondsToSelector:@selector(updater:didTerminateTarget:)]) { + [updaterDelegate updater:self.updater didTerminateTarget:bundleID]; + } + } + else + { + // Shouldn't happen + [NSApp terminate:self]; + } + } } - (void)cleanUpDownload diff --git a/Sparkle/SUUpdaterDelegate.h b/Sparkle/SUUpdaterDelegate.h index 1fc02673..af325aee 100644 --- a/Sparkle/SUUpdaterDelegate.h +++ b/Sparkle/SUUpdaterDelegate.h @@ -285,6 +285,14 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey; */ - (void)updater:(SUUpdater *)updater willInstallUpdateOnQuit:(SUAppcastItem *)item immediateInstallationBlock:(void (^)()) restartBlock; +/*! + Called when the update target is not from the host mainBundle. For example, a helper app updating its parent + + \param updater the SUUpdater instance. + \param targetBundleID the bundle ID of the terminated parent app + */ +- (void)updater:(SUUpdater *)updater didTerminateTarget: (NSString *)targetBundleID; + /*! Calls after an update that was scheduled to be silently installed on quit has been canceled.