Pass path to relaunch to sparkle-cli

We also now listen on termination for the app that we are going to re-launch,
rather than the bundle we are updating.
This commit is contained in:
Zorg committed 2016-04-30 22:52:04 -04:00
1 parent d9952b8f22
commit 15483815ff
6 files changed
+52 -24

No files matched your search

+15 -6
View File
@@ -341,12 +341,21 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
SULog(@"Error: Failed to match host bundle identifiers %@ and %@", self.hostBundleIdentifier, bundleIdentifier);
[self cleanupAndExitWithStatus:EXIT_FAILURE];
} else {
self.host = host;
self.installationData = installationData;
self.terminationListener = [[TerminationListener alloc] initWithBundle:hostBundle];
[self extractAndInstallUpdate];
NSBundle *relaunchBundle = [NSBundle bundleWithPath:nonNullInstallationData.relaunchPath];
if (relaunchBundle == nil) {
SULog(@"Error: Failed to locate relaunch bundle path %@", nonNullInstallationData.relaunchPath);
[self cleanupAndExitWithStatus:EXIT_FAILURE];
} else {
self.host = host;
self.installationData = installationData;
// We use the relaunch path for the bundle to listen for termination instead of the host path
// For a plug-in this makes a big difference; we want to wait until the app hosting the plug-in terminates
// Otherwise for an app, the relaunch path and host path should be identical
self.terminationListener = [[TerminationListener alloc] initWithBundle:relaunchBundle];
[self extractAndInstallUpdate];
}
}
}
});
+1 -1
View File
@@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface AppDelegate : NSObject <NSApplicationDelegate>
- (nullable instancetype)initWithBundlePath:(const char *)bundlePath;
- (instancetype)initWithUpdateBundlePath:(const char *)updateBundlePath relaunchBundlePath:(const char *)relaunchBundlePath;
@end
+26 -7
View File
@@ -13,29 +13,43 @@
@interface AppDelegate () <SUUpdaterDelegate>
@property (nonatomic, readonly) SUUpdater *updater;
@property (nonatomic, readonly) NSString *relaunchBundlePath;
@end
@implementation AppDelegate
@synthesize updater = _updater;
@synthesize relaunchBundlePath = _relaunchBundlePath;
- (instancetype)initWithBundlePath:(const char *)bundlePath
- (instancetype)initWithUpdateBundlePath:(const char *)updateBundlePathString relaunchBundlePath:(const char *)relaunchBundlePathString
{
self = [super init];
if (self != nil) {
NSString *bundlePathString = [[NSString alloc] initWithUTF8String:bundlePath];
if (bundlePathString == nil) {
NSString *updateBundlePath = [[NSString alloc] initWithUTF8String:updateBundlePathString];
if (updateBundlePath == nil) {
return nil;
}
NSBundle *bundle = [NSBundle bundleWithPath:bundlePathString];
if (bundle == nil) {
NSString *relaunchBundlePath = [[NSString alloc] initWithUTF8String:relaunchBundlePathString];
if (relaunchBundlePath == nil) {
return nil;
}
id <SUUserDriver> userDriver = [[SUCommandLineUserDriver alloc] initWithBundle:bundle];
_updater = [[SUUpdater alloc] initWithHostBundle:bundle userDriver:userDriver delegate:self];
NSBundle *updateBundle = [NSBundle bundleWithPath:updateBundlePath];
if (updateBundle == nil) {
return nil;
}
NSBundle *relaunchBundle = [NSBundle bundleWithPath:relaunchBundlePath];
if (relaunchBundle == nil) {
return nil;
}
_relaunchBundlePath = relaunchBundlePath;
id <SUUserDriver> userDriver = [[SUCommandLineUserDriver alloc] initWithRelaunchBundle:relaunchBundle];
_updater = [[SUUpdater alloc] initWithHostBundle:updateBundle userDriver:userDriver delegate:self];
}
return self;
}
@@ -45,6 +59,11 @@
return YES;
}
- (NSString *)pathToRelaunchForUpdater:(SUUpdater *)__unused updater
{
return self.relaunchBundlePath;
}
- (void)applicationDidFinishLaunching:(NSNotification *)__unused aNotification
{
// Kick off a scheduled update check once we start the updater later
+1 -1
View File
@@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface SUCommandLineUserDriver : NSObject <SUUserDriver>
- (instancetype)initWithBundle:(NSBundle *)bundle;
- (instancetype)initWithRelaunchBundle:(NSBundle *)relaunchBundle;
@end
+6 -6
View File
@@ -11,7 +11,7 @@
@interface SUCommandLineUserDriver ()
@property (nonatomic, readonly) NSBundle *bundle;
@property (nonatomic, readonly) NSBundle *relaunchBundle;
@property (nonatomic, readonly) SUUserDriverCoreComponent *coreComponent;
@property (nonatomic) NSUInteger bytesDownloaded;
@property (nonatomic) NSUInteger bytesToDownload;
@@ -20,16 +20,16 @@
@implementation SUCommandLineUserDriver
@synthesize bundle = _bundle;
@synthesize relaunchBundle = _relaunchBundle;
@synthesize coreComponent = _coreComponent;
@synthesize bytesDownloaded = _bytesDownloaded;
@synthesize bytesToDownload = _bytesToDownload;
- (instancetype)initWithBundle:(NSBundle *)bundle
- (instancetype)initWithRelaunchBundle:(NSBundle *)relaunchBundle
{
self = [super init];
if (self != nil) {
_bundle = bundle;
_relaunchBundle = relaunchBundle;
_coreComponent = [[SUUserDriverCoreComponent alloc] initWithDelegate:nil];
}
return self;
@@ -201,11 +201,11 @@
- (NSRunningApplication *)targetRunningApplication
{
NSString *bundleIdentifier = self.bundle.bundleIdentifier;
NSString *bundleIdentifier = self.relaunchBundle.bundleIdentifier;
if (bundleIdentifier != nil) {
NSArray<NSRunningApplication *> *runningApplications = [NSRunningApplication runningApplicationsWithBundleIdentifier:bundleIdentifier];
// Make sure we *don't* use NSURLs for equality comparison; turns out to not work that great
NSString *bundlePath = self.bundle.bundleURL.path;
NSString *bundlePath = self.relaunchBundle.bundleURL.path;
if (bundlePath != nil) {
for (NSRunningApplication *runningApplication in runningApplications) {
NSString *candidatePath = runningApplication.bundleURL.path;
+3 -3
View File
@@ -13,12 +13,12 @@ int main(int argc, const char *argv[])
{
@autoreleasepool
{
if (argc != 2) {
printf("Usage: %s <path to bundle to update>\n", argv[0]);
if (argc != 3) {
printf("Usage: %s <update-bundle-path> <relaunch-app-path>\n", argv[0]);
return EXIT_FAILURE;
}
AppDelegate *delegate = [[AppDelegate alloc] initWithBundlePath:argv[1]];
AppDelegate *delegate = [[AppDelegate alloc] initWithUpdateBundlePath:argv[1] relaunchBundlePath:argv[2]];
if (delegate == nil) {
printf("Error: Failed to initialize sparkle. Is the bundle you specified valid?\n");
return EXIT_FAILURE;