mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-24 04:38:16 +00:00
Fix normalization relaunch path setting and improve relaunching code
SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME=1 now works properly again. In the progress agent, we don't use the path sent from the installer unless the normalized setting is enabled.
This commit is contained in:
1 parent
251feb7e07
commit
fb2aea0d86
9 files changed
+53
-30
No files matched your search
@@ -566,6 +566,10 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
return;
|
||||
}
|
||||
|
||||
// Used later for relaunching
|
||||
// Compute this now before we set this installer property to nil
|
||||
NSString *installationPath = [self.installer installationPath];
|
||||
|
||||
NSError *thirdStageError = nil;
|
||||
if (![self.installer performFinalInstallation:&thirdStageError]) {
|
||||
SULog(@"Failed to finalize installation with error: %@", thirdStageError);
|
||||
@@ -590,13 +594,11 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
|
||||
[self.communicator handleMessageWithIdentifier:SPUInstallationFinishedStage3 data:[NSData data]];
|
||||
|
||||
NSString *installationPath = [SUInstaller installationPathForHost:self.host];
|
||||
|
||||
if (self.shouldRelaunch) {
|
||||
NSString *pathToRelaunch = nil;
|
||||
// If the installation path differs from the host path, we give higher precedence for it than
|
||||
// if the desired relaunch path differs from the host path
|
||||
if (![installationPath.pathComponents isEqualToArray:self.host.bundlePath.pathComponents] || [self.relaunchPath.pathComponents isEqualToArray:self.host.bundlePath.pathComponents]) {
|
||||
// If the relaunch path is the same as the host bundle path, use the installation path from the installer which may be normalized
|
||||
// Otherwise use the requested relaunch path in all other cases
|
||||
if ([self.relaunchPath.pathComponents isEqualToArray:self.host.bundlePath.pathComponents]) {
|
||||
pathToRelaunch = installationPath;
|
||||
} else {
|
||||
pathToRelaunch = self.relaunchPath;
|
||||
|
||||
@@ -31,6 +31,9 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
// Should be able to be called from non-main thread
|
||||
- (void)cleanup;
|
||||
|
||||
// The destination and installation path of the bundle being updated
|
||||
- (NSString *)installationPath;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -21,6 +21,6 @@ A guided installation can be started by applications other than the application
|
||||
|
||||
@interface SUGuidedPackageInstaller : NSObject <SPUInstallerProtocol>
|
||||
|
||||
- (instancetype)initWithPackagePath:(NSString *)packagePath;
|
||||
- (instancetype)initWithPackagePath:(NSString *)packagePath installationPath:(NSString *)installationPath;
|
||||
|
||||
@end
|
||||
@@ -17,18 +17,21 @@
|
||||
@interface SUGuidedPackageInstaller ()
|
||||
|
||||
@property (nonatomic, readonly, copy) NSString *packagePath;
|
||||
@property (nonatomic, readonly, copy) NSString *installationPath;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUGuidedPackageInstaller
|
||||
|
||||
@synthesize packagePath = _packagePath;
|
||||
@synthesize installationPath = _installationPath;
|
||||
|
||||
- (instancetype)initWithPackagePath:(NSString *)packagePath
|
||||
- (instancetype)initWithPackagePath:(NSString *)packagePath installationPath:(NSString *)installationPath
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_packagePath = [packagePath copy];
|
||||
_installationPath = [installationPath copy];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
+ (NSString *)installSourcePathInUpdateFolder:(NSString *)inUpdateFolder forHost:(SUHost *)host isPackage:(BOOL *)isPackagePtr isGuided:(nullable BOOL *)isGuidedPtr;
|
||||
|
||||
+ (NSString *)installationPathForHost:(SUHost *)host;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+21
-13
@@ -136,7 +136,7 @@
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Found guided package installer but '%@=%@' was probably missing in the appcast item enclosure", SUAppcastAttributeInstallationType, SPUInstallationTypeGuidedPackage] }];
|
||||
}
|
||||
} else {
|
||||
installer = [[SUGuidedPackageInstaller alloc] initWithPackagePath:newDownloadPath];
|
||||
installer = [[SUGuidedPackageInstaller alloc] initWithPackagePath:newDownloadPath installationPath:host.bundlePath];
|
||||
}
|
||||
} else if (isPackage) {
|
||||
if (![expectedInstallationType isEqualToString:SPUInstallationTypeInteractivePackage]) {
|
||||
@@ -144,7 +144,7 @@
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Found package installer but '%@=%@' was probably missing in the appcast item enclosure", SUAppcastAttributeInstallationType, SPUInstallationTypeInteractivePackage] }];
|
||||
}
|
||||
} else {
|
||||
installer = [[SUPackageInstaller alloc] initWithPackagePath:newDownloadPath];
|
||||
installer = [[SUPackageInstaller alloc] initWithPackagePath:newDownloadPath installationPath:host.bundlePath];
|
||||
}
|
||||
} else {
|
||||
if (![expectedInstallationType isEqualToString:SPUInstallationTypeApplication]) {
|
||||
@@ -152,27 +152,35 @@
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Found regular application update but expected '%@=%@' from the appcast item enclosure instead", SUAppcastAttributeInstallationType, expectedInstallationType] }];
|
||||
}
|
||||
} else {
|
||||
installer = [[SUPlainInstaller alloc] initWithHost:host applicationPath:newDownloadPath installationPath:[[self class] installationPathForHost:host] versionComparator:comparator];
|
||||
NSString *normalizedInstallationPath = nil;
|
||||
if (SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME) {
|
||||
normalizedInstallationPath = [[self class] normalizedInstallationPathForHost:host];
|
||||
}
|
||||
|
||||
// If we have a normalized path, we'll install to "#{CFBundleName}.app", but only if that path doesn't already exist. If we're "Foo 4.2.app," and there's a "Foo.app" in this directory, we don't want to overwrite it! But if there's no "Foo.app," we'll take that name.
|
||||
// Otherwise if there's no normalized path (the more likely case), we'll just use the host bundle's path
|
||||
NSString *installationPath;
|
||||
if (normalizedInstallationPath != nil && ![[NSFileManager defaultManager] fileExistsAtPath:normalizedInstallationPath]) {
|
||||
installationPath = normalizedInstallationPath;
|
||||
} else {
|
||||
installationPath = host.bundlePath;
|
||||
}
|
||||
|
||||
installer = [[SUPlainInstaller alloc] initWithHost:host applicationPath:newDownloadPath installationPath:installationPath versionComparator:comparator];
|
||||
}
|
||||
}
|
||||
|
||||
return installer;
|
||||
}
|
||||
|
||||
+ (NSString *)installationPathForHost:(SUHost *)host
|
||||
+ (NSString *)normalizedInstallationPathForHost:(SUHost *)host
|
||||
{
|
||||
NSBundle *bundle = host.bundle;
|
||||
assert(bundle != nil);
|
||||
|
||||
if (SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME) {
|
||||
// We'll install to "#{CFBundleName}.app", but only if that path doesn't already exist. If we're "Foo 4.2.app," and there's a "Foo.app" in this directory, we don't want to overwrite it! But if there's no "Foo.app," we'll take that name.
|
||||
NSString *normalizedAppPath = [[[bundle bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@", [bundle objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleNameKey], [[bundle bundlePath] pathExtension]]];
|
||||
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:normalizedAppPath]) {
|
||||
return normalizedAppPath;
|
||||
}
|
||||
}
|
||||
return [bundle bundlePath];
|
||||
NSString *normalizedAppPath = [[[bundle bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@", [bundle objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleNameKey], [[bundle bundlePath] pathExtension]]];
|
||||
|
||||
return normalizedAppPath;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -14,6 +14,6 @@
|
||||
|
||||
@interface SUPackageInstaller : NSObject <SPUInstallerProtocol>
|
||||
|
||||
- (instancetype)initWithPackagePath:(NSString *)packagePath;
|
||||
- (instancetype)initWithPackagePath:(NSString *)packagePath installationPath:(NSString *)installationPath;
|
||||
|
||||
@end
|
||||
@@ -18,6 +18,7 @@
|
||||
@interface SUPackageInstaller ()
|
||||
|
||||
@property (nonatomic, readonly, copy) NSString *packagePath;
|
||||
@property (nonatomic, readonly, copy) NSString *installationPath;
|
||||
|
||||
@end
|
||||
|
||||
@@ -26,12 +27,14 @@
|
||||
static NSString *SUOpenUtilityPath = @"/usr/bin/open";
|
||||
|
||||
@synthesize packagePath = _packagePath;
|
||||
@synthesize installationPath = _installationPath;
|
||||
|
||||
- (instancetype)initWithPackagePath:(NSString *)packagePath
|
||||
- (instancetype)initWithPackagePath:(NSString *)packagePath installationPath:(NSString *)installationPath
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_packagePath = [packagePath copy];
|
||||
_installationPath = [installationPath copy];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
+12
-6
@@ -243,14 +243,18 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
});
|
||||
}
|
||||
|
||||
// The pathToRelaunch passed to here is not necessarily the same as the one passed in -registerApplicationBundlePath: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
|
||||
- (void)relaunchPath:(NSString *)requestedPathToRelaunch
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
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
|
||||
if (!self.willTerminate && self.applicationBundle != nil && self.applicationInitiallyAlive) {
|
||||
// If the normalized setting is not enabled, we shouldn't trust the relaunch path input that is being passed to us
|
||||
// because we already have the application path to relaunch, and we verified that it was running before
|
||||
NSString *pathToRelaunch;
|
||||
if (SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME) {
|
||||
pathToRelaunch = requestedPathToRelaunch;
|
||||
} else {
|
||||
pathToRelaunch = self.applicationBundle.bundlePath;
|
||||
}
|
||||
|
||||
// We should at least make sure we're opening a bundle however
|
||||
NSBundle *relaunchBundle = [NSBundle bundleWithPath:pathToRelaunch];
|
||||
@@ -259,6 +263,8 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE];
|
||||
}
|
||||
|
||||
// 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
|
||||
if (![[NSWorkspace sharedWorkspace] openFile:pathToRelaunch]) {
|
||||
SULog(@"Error: Failed to relaunch bundle at %@", pathToRelaunch);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user