diff --git a/Sparkle/Autoupdate/AppInstaller.m b/Sparkle/Autoupdate/AppInstaller.m index 5fd1d799..1f788afa 100644 --- a/Sparkle/Autoupdate/AppInstaller.m +++ b/Sparkle/Autoupdate/AppInstaller.m @@ -440,14 +440,9 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7; return; } - if (self.shouldShowUI) { - // Predict if an admin prompt is needed - // If it is, we should activate our app so that the auth prompt will be active - // (Note it's more efficient/simpler to predict rather than trying, seeing if we fail, notifying, and re-trying) - NSString *installationPath = [SUInstaller installationPathForHost:self.host]; - if (![[NSFileManager defaultManager] isWritableFileAtPath:installationPath]) { - [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; - } + if (self.shouldShowUI && [self.installer mayNeedToRequestAuthorization]) { + // We should activate our app so that the auth prompt will be active + [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; } NSError *secondStageError = nil; diff --git a/Sparkle/Autoupdate/SUInstallerProtocol.h b/Sparkle/Autoupdate/SUInstallerProtocol.h index 357a2069..b56c19be 100644 --- a/Sparkle/Autoupdate/SUInstallerProtocol.h +++ b/Sparkle/Autoupdate/SUInstallerProtocol.h @@ -36,6 +36,10 @@ // Should be thread safe - (BOOL)canInstallSilently; +// Indicates whether or not this installer may need authorization when performing the second stage of the installation +// Should be thread safe +- (BOOL)mayNeedToRequestAuthorization; + // Cleans up work done from any of the previous stages. This should be invoked after stage 3 succeeds, // or after any one of the stages fails. // Should be able to be called from non-main thread diff --git a/Sparkle/SUGuidedPackageInstaller.m b/Sparkle/SUGuidedPackageInstaller.m index 514a6c2d..4c8d1f41 100644 --- a/Sparkle/SUGuidedPackageInstaller.m +++ b/Sparkle/SUGuidedPackageInstaller.m @@ -93,7 +93,12 @@ - (BOOL)canInstallSilently { - return NO; // because of authorization + return ![self mayNeedToRequestAuthorization]; +} + +- (BOOL)mayNeedToRequestAuthorization +{ + return YES; } - (void)cleanup diff --git a/Sparkle/SUPackageInstaller.m b/Sparkle/SUPackageInstaller.m index adf964bb..7d5a12e3 100644 --- a/Sparkle/SUPackageInstaller.m +++ b/Sparkle/SUPackageInstaller.m @@ -82,6 +82,11 @@ static NSString *SUOpenUtilityPath = @"/usr/bin/open"; return NO; } +- (BOOL)mayNeedToRequestAuthorization +{ + return NO; +} + - (void)cleanup { } diff --git a/Sparkle/SUPlainInstaller.m b/Sparkle/SUPlainInstaller.m index 15a8be19..54a9e494 100644 --- a/Sparkle/SUPlainInstaller.m +++ b/Sparkle/SUPlainInstaller.m @@ -248,8 +248,16 @@ - (BOOL)canInstallSilently { -#warning is this test good enough or should we check parent directory too? - return [[NSFileManager defaultManager] isWritableFileAtPath:self.host.bundle.bundlePath]; + return ![self mayNeedToRequestAuthorization]; +} + +- (BOOL)mayNeedToRequestAuthorization +{ + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSString *bundlePath = self.host.bundle.bundlePath; + // It's very well possible to have the bundle be writable but not be able to write into the parent directory + // And if the bundle isn't writable, but we can write into the parent directory, we will still need to authorize to replace it + return ![fileManager isWritableFileAtPath:bundlePath] || ![fileManager isWritableFileAtPath:[bundlePath stringByDeletingLastPathComponent]]; } - (void)cleanup