mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-26 04:57:54 +00:00
Bug #402074: ".pkg installations should support asynchronous installation"
This commit is contained in:
1 parent
8f00c3c274
commit
0e99d4fa80
1 file changed
+45
-27
+45
-27
@@ -12,44 +12,62 @@
|
||||
#define NSAppKitVersionNumber10_4 824
|
||||
#endif
|
||||
|
||||
NSString *SUPackageInstallerCommandKey = @"SUPackageInstallerCommand";
|
||||
NSString *SUPackageInstallerArgumentsKey = @"SUPackageInstallerArguments";
|
||||
NSString *SUPackageInstallerHostKey = @"SUPackageInstallerHost";
|
||||
NSString *SUPackageInstallerDelegateKey = @"SUPackageInstallerDelegate";
|
||||
|
||||
@implementation SUPackageInstaller
|
||||
|
||||
+ (void)performInstallationWithPath:(NSString *)path host:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id <SUVersionComparison>)comparator;
|
||||
+ (void)_finishInstallationWithInfo:(NSDictionary *)info
|
||||
{
|
||||
NSError *error = nil;
|
||||
BOOL result = YES;
|
||||
[self _finishInstallationWithResult:YES host:[info objectForKey:SUPackageInstallerHostKey] error:nil delegate:[info objectForKey:SUPackageInstallerDelegateKey]];
|
||||
}
|
||||
|
||||
+ (void)_performInstallationWithInfo:(NSDictionary *)info
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
NSTask *installer = [NSTask launchedTaskWithLaunchPath:[info objectForKey:SUPackageInstallerCommandKey] arguments:[info objectForKey:SUPackageInstallerArgumentsKey]];
|
||||
[installer waitUntilExit];
|
||||
|
||||
// Known bug: if the installation fails or is canceled, Sparkle goes ahead and restarts, thinking everything is fine.
|
||||
[self performSelectorOnMainThread:@selector(_finishInstallationWithInfo:) withObject:info waitUntilDone:NO];
|
||||
|
||||
[pool drain];
|
||||
}
|
||||
|
||||
+ (void)performInstallationWithPath:(NSString *)path host:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id <SUVersionComparison>)comparator
|
||||
{
|
||||
NSString *command;
|
||||
NSArray *args;
|
||||
|
||||
if (floor(NSAppKitVersionNumber) == NSAppKitVersionNumber10_4) {
|
||||
// 10.4 uses Installer.app because the "open" command in 10.4 doesn't support -W and -n
|
||||
NSString *installerPath = [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:@"com.apple.installer"];
|
||||
result = [[NSFileManager defaultManager] fileExistsAtPath:installerPath];
|
||||
if (result)
|
||||
{
|
||||
NSTask *installer = [NSTask launchedTaskWithLaunchPath:installerPath arguments:[NSArray arrayWithObjects:path, nil]];
|
||||
[installer waitUntilExit];
|
||||
}
|
||||
command = [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:@"com.apple.installer"];
|
||||
args = [NSArray arrayWithObjects:path, nil];
|
||||
} else {
|
||||
// 10.5 and later. Run installer using the "open" command to ensure it is launched in front of current application.
|
||||
NSString* openCommand = @"/usr/bin/open";
|
||||
result = [[NSFileManager defaultManager] fileExistsAtPath:openCommand];
|
||||
if (result)
|
||||
{
|
||||
// The -W and -n options were added to the 'open' command in 10.5
|
||||
// -W = wait until the app has quit.
|
||||
// -n = Open another instance if already open.
|
||||
// -b = app bundle identifier
|
||||
NSArray *args = [NSArray arrayWithObjects:@"-W", @"-n", @"-b", @"com.apple.installer", path, nil];
|
||||
NSTask *openTask = [NSTask launchedTaskWithLaunchPath:openCommand arguments:args];
|
||||
[openTask waitUntilExit];
|
||||
}
|
||||
// The -W and -n options were added to the 'open' command in 10.5
|
||||
// -W = wait until the app has quit.
|
||||
// -n = Open another instance if already open.
|
||||
// -b = app bundle identifier
|
||||
command = @"/usr/bin/open";
|
||||
args = [NSArray arrayWithObjects:@"-W", @"-n", @"-b", @"com.apple.installer", path, nil];
|
||||
}
|
||||
|
||||
if (!result)
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:command])
|
||||
{
|
||||
error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingInstallerToolError userInfo:[NSDictionary dictionaryWithObject:@"Couldn't find Apple's installer tool!" forKey:NSLocalizedDescriptionKey]];
|
||||
NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingInstallerToolError userInfo:[NSDictionary dictionaryWithObject:@"Couldn't find Apple's installer tool!" forKey:NSLocalizedDescriptionKey]];
|
||||
[self _finishInstallationWithResult:NO host:host error:error delegate:delegate];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:command, SUPackageInstallerCommandKey, args, SUPackageInstallerArgumentsKey, host, SUPackageInstallerHostKey, delegate, SUPackageInstallerDelegateKey, nil];
|
||||
if (synchronously)
|
||||
[self _performInstallationWithInfo:info];
|
||||
else
|
||||
[NSThread detachNewThreadSelector:@selector(_performInstallationWithInfo:) toTarget:self withObject:info];
|
||||
}
|
||||
// Known bug: if the installation fails or is canceled, Sparkle goes ahead and restarts, thinking everything is fine.
|
||||
[self _finishInstallationWithResult:result host:host error:error delegate:delegate];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user