Convert remaining ivars to properties to avoid direct ivar access.

This commit is contained in:
Jake Petroules committed 2014-07-02 18:55:54 -04:00
1 parent aac2a91833
commit 0e14c9ca6a
13 files changed
+411 -330

No files matched your search

+45 -32
View File
@@ -20,6 +20,19 @@ static const NSTimeInterval SUParentQuitCheckInterval = .5;
@interface TerminationListener : NSObject <SUInstallerDelegate>
@property (assign) const char *hostpath;
@property (assign) const char *executablepath;
@property (assign) pid_t parentprocessid;
@property (assign) const char *folderpath;
@property (copy) NSString *selfPath;
@property (copy) NSString *installationPath;
@property (strong) NSTimer *watchdogTimer;
@property (strong) NSTimer *longInstallationTimer;
@property (strong) SUHost *host;
@property (assign) BOOL shouldRelaunch;
@property (assign) BOOL shouldShowUI;
- (void) parentHasQuit;
- (void) relaunch;
@@ -31,19 +44,19 @@ static const NSTimeInterval SUParentQuitCheckInterval = .5;
@end
@implementation TerminationListener
{
const char *hostpath;
const char *executablepath;
pid_t parentprocessid;
const char *folderpath;
NSString *selfPath;
NSString *installationPath;
NSTimer *watchdogTimer;
NSTimer *longInstallationTimer;
SUHost *host;
BOOL shouldRelaunch;
BOOL shouldShowUI;
}
@synthesize hostpath;
@synthesize executablepath;
@synthesize parentprocessid;
@synthesize folderpath;
@synthesize selfPath;
@synthesize installationPath;
@synthesize watchdogTimer;
@synthesize longInstallationTimer;
@synthesize host;
@synthesize shouldRelaunch;
@synthesize shouldShowUI;
- (instancetype) initWithHostPath:(const char *)inhostpath executablePath:(const char *)execpath parentProcessId:(pid_t)ppid folderPath:(const char*)infolderpath shouldRelaunch:(BOOL)relaunch shouldShowUI:(BOOL)showUI selfPath:(NSString*)inSelfPath
{
@@ -78,12 +91,12 @@ static const NSTimeInterval SUParentQuitCheckInterval = .5;
-(void) parentHasQuit
{
[watchdogTimer invalidate];
longInstallationTimer = [NSTimer scheduledTimerWithTimeInterval:SUInstallationTimeLimit
[self.watchdogTimer invalidate];
self.longInstallationTimer = [NSTimer scheduledTimerWithTimeInterval:SUInstallationTimeLimit
target: self selector: @selector(showAppIconInDock:)
userInfo:nil repeats:NO];
if( folderpath )
if( self.folderpath )
[self install];
else
[self relaunch];
@@ -91,7 +104,7 @@ static const NSTimeInterval SUParentQuitCheckInterval = .5;
- (void)watchdog:(NSTimer *) __unused aTimer
{
if (![NSRunningApplication runningApplicationWithProcessIdentifier:parentprocessid]) {
if (![NSRunningApplication runningApplicationWithProcessIdentifier:self.parentprocessid]) {
[self parentHasQuit];
}
}
@@ -105,23 +118,23 @@ static const NSTimeInterval SUParentQuitCheckInterval = .5;
- (void) relaunch __attribute__((noreturn))
{
if (shouldRelaunch)
if (self.shouldRelaunch)
{
NSString *appPath = nil;
if( !folderpath || strcmp(executablepath, hostpath) != 0 )
appPath = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:executablepath length:strlen(executablepath)];
if( !self.folderpath || strcmp(self.executablepath, self.hostpath) != 0 )
appPath = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:self.executablepath length:strlen(self.executablepath)];
else
appPath = installationPath;
appPath = self.installationPath;
[[NSWorkspace sharedWorkspace] openFile: appPath];
}
if (folderpath)
if (self.folderpath)
{
NSError *theError = nil;
if( ![SUPlainInstaller _removeFileAtPath: [SUInstaller updateFolder] error: &theError] )
SULog( @"Couldn't remove update folder: %@.", theError );
}
[[NSFileManager defaultManager] removeItemAtPath: selfPath error: NULL];
[[NSFileManager defaultManager] removeItemAtPath: self.selfPath error: NULL];
exit(EXIT_SUCCESS);
}
@@ -129,21 +142,21 @@ static const NSTimeInterval SUParentQuitCheckInterval = .5;
- (void) install
{
NSBundle *theBundle = [NSBundle bundleWithPath: [[NSFileManager defaultManager] stringWithFileSystemRepresentation: hostpath length:strlen(hostpath)]];
host = [[SUHost alloc] initWithBundle: theBundle];
installationPath = [[host installationPath] copy];
NSBundle *theBundle = [NSBundle bundleWithPath: [[NSFileManager defaultManager] stringWithFileSystemRepresentation: self.hostpath length:strlen(self.hostpath)]];
self.host = [[SUHost alloc] initWithBundle: theBundle];
self.installationPath = [[self.host installationPath] copy];
if (shouldShowUI) {
SUStatusController* statusCtl = [[SUStatusController alloc] initWithHost: host]; // We quit anyway after we've installed, so leak this for now.
if (self.shouldShowUI) {
SUStatusController* statusCtl = [[SUStatusController alloc] initWithHost: self.host]; // We quit anyway after we've installed, so leak this for now.
[statusCtl setButtonTitle: SULocalizedString(@"Cancel Update",@"") target: nil action: Nil isDefault: NO];
[statusCtl beginActionWithTitle: SULocalizedString(@"Installing update...",@"")
maxProgressValue: 0 statusText: @""];
[statusCtl showWindow: self];
}
[SUInstaller installFromUpdateFolder:[[NSFileManager defaultManager] stringWithFileSystemRepresentation:folderpath length:strlen(folderpath)]
overHost:host
installationPath:installationPath
[SUInstaller installFromUpdateFolder:[[NSFileManager defaultManager] stringWithFileSystemRepresentation:self.folderpath length:strlen(self.folderpath)]
overHost:self.host
installationPath:self.installationPath
delegate:self
versionComparator:[SUStandardVersionComparator defaultComparator]];
}
@@ -155,7 +168,7 @@ static const NSTimeInterval SUParentQuitCheckInterval = .5;
- (void)installerForHost:(SUHost *) __unused host failedWithError:(NSError *)error __attribute__((noreturn))
{
if (shouldShowUI)
if (self.shouldShowUI)
NSRunAlertPanel( @"", @"%@", @"OK", @"", @"", [error localizedDescription] );
exit(EXIT_FAILURE);
}
+31 -21
View File
@@ -17,34 +17,44 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
@interface SUUpdateDriver ()
- (void)setInterruptible:(BOOL)interruptible;
@property (getter=isInterruptible) BOOL interruptible;
@end
@interface SUAutomaticUpdateDriver ()
@property (assign) BOOL postponingInstallation;
@property (assign) BOOL showErrors;
@property (assign) BOOL willUpdateOnTermination;
@property (strong) SUAutomaticUpdateAlert *alert;
@property (strong) NSTimer *showUpdateAlertTimer;
@end
@implementation SUAutomaticUpdateDriver
{
BOOL postponingInstallation, showErrors;
BOOL willUpdateOnTermination;
SUAutomaticUpdateAlert *alert;
NSTimer *showUpdateAlertTimer;
}
@synthesize postponingInstallation;
@synthesize showErrors;
@synthesize willUpdateOnTermination;
@synthesize alert;
@synthesize showUpdateAlertTimer;
- (void)showUpdateAlert
{
self.interruptible = NO;
alert = [[SUAutomaticUpdateAlert alloc] initWithAppcastItem:self.updateItem host:self.host delegate:self];
self.alert = [[SUAutomaticUpdateAlert alloc] initWithAppcastItem:self.updateItem host:self.host delegate:self];
// If the app is a menubar app or the like, we need to focus it first and alter the
// update prompt to behave like a normal window. Otherwise if the window were hidden
// there may be no way for the application to be activated to make it visible again.
if ([self.host isBackgroundApplication])
{
[[alert window] setHidesOnDeactivate:NO];
[[self.alert window] setHidesOnDeactivate:NO];
[NSApp activateIgnoringOtherApps:YES];
}
if ([NSApp isActive])
[[alert window] makeKeyAndOrderFront:self];
[[self.alert window] makeKeyAndOrderFront:self];
else
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:NSApplicationDidBecomeActiveNotification object:NSApp];
}
@@ -57,7 +67,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
NSProcessInfo *processInfo = [NSProcessInfo processInfo];
[processInfo disableSuddenTermination];
willUpdateOnTermination = YES;
self.willUpdateOnTermination = YES;
id<SUUpdaterDelegate> updaterDelegate = [self.updater delegate];
if ([updaterDelegate respondsToSelector:@selector(updater:willInstallUpdateOnQuit:immediateInstallationInvocation:)])
@@ -80,7 +90,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
}
else
{
showUpdateAlertTimer = [NSTimer scheduledTimerWithTimeInterval:SUAutomaticUpdatePromptImpatienceTimer target:self selector:@selector(showUpdateAlert) userInfo:nil repeats:NO];
self.showUpdateAlertTimer = [NSTimer scheduledTimerWithTimeInterval:SUAutomaticUpdatePromptImpatienceTimer target:self selector:@selector(showUpdateAlert) userInfo:nil repeats:NO];
// At this point the driver is idle, allow it to be interrupted for user-initiated update checks.
self.interruptible = YES;
@@ -89,13 +99,13 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
- (void)stopUpdatingOnTermination
{
if (willUpdateOnTermination)
if (self.willUpdateOnTermination)
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillTerminateNotification object:nil];
NSProcessInfo *processInfo = [NSProcessInfo processInfo];
[processInfo enableSuddenTermination];
willUpdateOnTermination = NO;
self.willUpdateOnTermination = NO;
id<SUUpdaterDelegate> updaterDelegate = [self.updater delegate];
if ([updaterDelegate respondsToSelector:@selector(updater:didCancelInstallUpdateOnQuit:)])
@@ -105,8 +115,8 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
- (void)invalidateShowUpdateAlertTimer
{
[showUpdateAlertTimer invalidate];
showUpdateAlertTimer = nil;
[self.showUpdateAlertTimer invalidate];
self.showUpdateAlertTimer = nil;
}
- (void)dealloc
@@ -124,7 +134,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
- (void)applicationDidBecomeActive:(NSNotification *) __unused aNotification
{
[[alert window] makeKeyAndOrderFront:self];
[[self.alert window] makeKeyAndOrderFront:self];
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"NSApplicationDidBecomeActiveNotification" object:NSApp];
}
@@ -138,7 +148,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
break;
case SUInstallLaterChoice:
postponingInstallation = YES;
self.postponingInstallation = YES;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil];
// We're already waiting on quit, just indicate that we're idle.
self.interruptible = YES;
@@ -151,7 +161,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
}
}
- (BOOL)shouldInstallSynchronously { return postponingInstallation; }
- (BOOL)shouldInstallSynchronously { return self.postponingInstallation; }
- (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI
{
@@ -159,7 +169,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
[self stopUpdatingOnTermination];
}
showErrors = YES;
self.showErrors = YES;
[super installWithToolAndRelaunch:relaunch displayingUserInterface:showUI];
}
@@ -170,7 +180,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
- (void)abortUpdateWithError:(NSError *)error
{
if (showErrors)
if (self.showErrors)
[super abortUpdateWithError:error];
else
[self abortUpdate];
+52 -41
View File
@@ -30,17 +30,28 @@
#error FINISH_INSTALL_TOOL_NAME not defined
#endif
@interface SUBasicUpdateDriver ()
@property (weak) SUAppcastItem *updateItem;
@property (strong) NSURLDownload *download;
@property (copy) NSString *downloadPath;
@property (strong) SUAppcastItem *nonDeltaUpdateItem;
@property (copy) NSString *tempDir;
@property (copy) NSString *relaunchPath;
@end
@implementation SUBasicUpdateDriver
{
SUAppcastItem *nonDeltaUpdateItem;
NSString *tempDir;
NSString *relaunchPath;
}
@synthesize updateItem;
@synthesize download;
@synthesize downloadPath;
@synthesize nonDeltaUpdateItem;
@synthesize tempDir;
@synthesize relaunchPath;
- (void)checkForUpdatesAtURL:(NSURL *)URL host:(SUHost *)aHost
{
[super checkForUpdatesAtURL:URL host:aHost];
@@ -137,16 +148,16 @@
if (binaryDeltaSupported()) {
SUAppcastItem *deltaUpdateItem = [item deltaUpdates][[self.host version]];
if (deltaUpdateItem && [self hostSupportsItem:deltaUpdateItem]) {
nonDeltaUpdateItem = item;
self.nonDeltaUpdateItem = item;
item = deltaUpdateItem;
}
}
}
updateItem = item;
if (updateItem == nil) { [self didNotFindUpdate]; return; }
self.updateItem = item;
if (self.updateItem == nil) { [self didNotFindUpdate]; return; }
if ([self itemContainsValidUpdate:updateItem])
if ([self itemContainsValidUpdate:self.updateItem])
[self didFindValidUpdate];
else
[self didNotFindUpdate];
@@ -160,8 +171,8 @@
- (void)didFindValidUpdate
{
if ([[self.updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)])
[[self.updater delegate] updater:self.updater didFindValidUpdate:updateItem];
NSDictionary *userInfo = (updateItem != nil) ? @{SUUpdaterAppcastItemNotificationKey : updateItem} : nil;
[[self.updater delegate] updater:self.updater didFindValidUpdate:self.updateItem];
NSDictionary *userInfo = (self.updateItem != nil) ? @{SUUpdaterAppcastItemNotificationKey : self.updateItem} : nil;
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFindValidUpdateNotification object:self.updater userInfo:userInfo];
[self downloadUpdate];
}
@@ -180,34 +191,34 @@
- (void)downloadUpdate
{
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[updateItem fileURL]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[self.updateItem fileURL]];
[request setValue:[self.updater userAgentString] forHTTPHeaderField:@"User-Agent"];
download = [[NSURLDownload alloc] initWithRequest:request delegate:self];
self.download = [[NSURLDownload alloc] initWithRequest:request delegate:self];
}
- (void)download:(NSURLDownload *) __unused d decideDestinationWithSuggestedFilename:(NSString *)name
{
NSString *downloadFileName = [NSString stringWithFormat:@"%@ %@", [self.host name], [updateItem versionString]];
NSString *downloadFileName = [NSString stringWithFormat:@"%@ %@", [self.host name], [self.updateItem versionString]];
tempDir = [[self.host appSupportPath] stringByAppendingPathComponent:downloadFileName];
self.tempDir = [[self.host appSupportPath] stringByAppendingPathComponent:downloadFileName];
int cnt=1;
while ([[NSFileManager defaultManager] fileExistsAtPath:tempDir] && cnt <= 999)
while ([[NSFileManager defaultManager] fileExistsAtPath:self.tempDir] && cnt <= 999)
{
tempDir = [[self.host appSupportPath] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ %d", downloadFileName, cnt++]];
self.tempDir = [[self.host appSupportPath] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ %d", downloadFileName, cnt++]];
}
// Create the temporary directory if necessary.
BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:tempDir withIntermediateDirectories:YES attributes:nil error:NULL];
BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:self.tempDir withIntermediateDirectories:YES attributes:nil error:NULL];
if (!success)
{
// Okay, something's really broken with this user's file structure.
[download cancel];
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUTemporaryDirectoryError userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Can't make a temporary directory for the update download at %@.",tempDir]}]];
[self.download cancel];
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUTemporaryDirectoryError userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Can't make a temporary directory for the update download at %@.",self.tempDir]}]];
}
downloadPath = [tempDir stringByAppendingPathComponent:name];
[download setDestination:downloadPath allowOverwrite:YES];
self.downloadPath = [self.tempDir stringByAppendingPathComponent:name];
[self.download setDestination:self.downloadPath allowOverwrite:YES];
}
- (BOOL)validateUpdateDownloadedToPath:(NSString *)downloadedPath extractedToPath:(NSString *)extractedPath DSASignature:(NSString *)DSASignature publicDSAKey:(NSString *)publicDSAKey
@@ -245,10 +256,10 @@
- (void)extractUpdate
{
SUUnarchiver *unarchiver = [SUUnarchiver unarchiverForPath:downloadPath updatingHost:self.host];
SUUnarchiver *unarchiver = [SUUnarchiver unarchiverForPath:self.downloadPath updatingHost:self.host];
if (!unarchiver)
{
SULog(@"Sparkle Error: No valid unarchiver for %@!", downloadPath);
SULog(@"Sparkle Error: No valid unarchiver for %@!", self.downloadPath);
[self unarchiverDidFail:nil];
return;
}
@@ -259,8 +270,8 @@
- (void)failedToApplyDeltaUpdate
{
// When a delta update fails to apply we fall back on updating via a full install.
updateItem = nonDeltaUpdateItem;
nonDeltaUpdateItem = nil;
self.updateItem = self.nonDeltaUpdateItem;
self.nonDeltaUpdateItem = nil;
[self downloadUpdate];
}
@@ -272,7 +283,7 @@
- (void)unarchiverDidFail:(SUUnarchiver *)__unused ua
{
if ([updateItem isDeltaUpdate]) {
if ([self.updateItem isDeltaUpdate]) {
[self failedToApplyDeltaUpdate];
return;
}
@@ -290,7 +301,7 @@
- (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI
{
if (![self validateUpdateDownloadedToPath:downloadPath extractedToPath:tempDir DSASignature:[updateItem DSASignature] publicDSAKey:[self.host publicDSAKey]])
if (![self validateUpdateDownloadedToPath:self.downloadPath extractedToPath:self.tempDir DSASignature:[self.updateItem DSASignature] publicDSAKey:[self.host publicDSAKey]])
{
NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil),
@@ -316,14 +327,14 @@
[invocation setArgument:&relaunch atIndex:2];
[invocation setTarget:self];
postponedOnce = YES;
if ([updaterDelegate updater:self.updater shouldPostponeRelaunchForUpdate:updateItem untilInvoking:invocation]) {
if ([updaterDelegate updater:self.updater shouldPostponeRelaunchForUpdate:self.updateItem untilInvoking:invocation]) {
return;
}
}
if ([updaterDelegate respondsToSelector:@selector(updater:willInstallUpdate:)]) {
[updaterDelegate updater:self.updater willInstallUpdate:updateItem];
[updaterDelegate updater:self.updater willInstallUpdate:self.updateItem];
}
NSString *const finishInstallToolName = FINISH_INSTALL_TOOL_NAME_STRING;
@@ -339,7 +350,7 @@
[[NSFileManager defaultManager] createDirectoryAtPath: [targetPath stringByDeletingLastPathComponent] withIntermediateDirectories: YES attributes: @{} error: &error];
if( [SUPlainInstaller copyPathWithAuthentication: relaunchPathToCopy overPath: targetPath temporaryName: nil error: &error] )
relaunchPath = targetPath;
self.relaunchPath = targetPath;
else
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:@{NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil), NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"Couldn't copy relauncher (%@) to temporary path (%@)! %@", relaunchPathToCopy, targetPath, (error ? [error localizedDescription] : @"")]}]];
}
@@ -348,10 +359,10 @@
if ([updaterDelegate respondsToSelector:@selector(updaterWillRelaunchApplication:)])
[updaterDelegate updaterWillRelaunchApplication:self.updater];
if(!relaunchPath || ![[NSFileManager defaultManager] fileExistsAtPath:relaunchPath])
if(!self.relaunchPath || ![[NSFileManager defaultManager] fileExistsAtPath:self.relaunchPath])
{
// Note that we explicitly use the host app's name here, since updating plugin for Mail relaunches Mail, not just the plugin.
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:SULocalizedString(@"An error occurred while relaunching %1$@, but the new version will be available next time you run %1$@.", nil), [self.host name]], NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"Couldn't find the relauncher (expected to find it at %@)", relaunchPath]}]];
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:SULocalizedString(@"An error occurred while relaunching %1$@, but the new version will be available next time you run %1$@.", nil), [self.host name]], NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"Couldn't find the relauncher (expected to find it at %@)", self.relaunchPath]}]];
// We intentionally don't abandon the update here so that the host won't initiate another.
return;
}
@@ -360,11 +371,11 @@
if ([updaterDelegate respondsToSelector:@selector(pathToRelaunchForUpdater:)]) {
pathToRelaunch = [updaterDelegate pathToRelaunchForUpdater:self.updater];
}
NSString *relaunchToolPath = [[relaunchPath stringByAppendingPathComponent: @"/Contents/MacOS"] stringByAppendingPathComponent: finishInstallToolName];
NSString *relaunchToolPath = [[self.relaunchPath stringByAppendingPathComponent: @"/Contents/MacOS"] stringByAppendingPathComponent: finishInstallToolName];
[NSTask launchedTaskWithLaunchPath: relaunchToolPath arguments:@[[self.host bundlePath],
pathToRelaunch,
[NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]],
tempDir,
self.tempDir,
relaunch ? @"1" : @"0",
showUI ? @"1" : @"0"]];
@@ -373,13 +384,13 @@
- (void)cleanUpDownload
{
if (tempDir != nil) // tempDir contains downloadPath, so we implicitly delete both here.
if (self.tempDir != nil) // tempDir contains downloadPath, so we implicitly delete both here.
{
BOOL success = NO;
NSError * error = nil;
success = [[NSFileManager defaultManager] removeItemAtPath: tempDir error: &error]; // Clean up the copied relauncher
success = [[NSFileManager defaultManager] removeItemAtPath:self.tempDir error: &error]; // Clean up the copied relauncher
if( !success )
[[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:[tempDir stringByDeletingLastPathComponent] destination:@"" files:@[[tempDir lastPathComponent]] tag:NULL];
[[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:[self.tempDir stringByDeletingLastPathComponent] destination:@"" files:@[[self.tempDir lastPathComponent]] tag:NULL];
}
}
@@ -387,7 +398,7 @@
{
if (aHost != self.host) { return; }
NSError * dontThrow = nil;
[[NSFileManager defaultManager] removeItemAtPath: relaunchPath error: &dontThrow]; // Clean up the copied relauncher
[[NSFileManager defaultManager] removeItemAtPath:self.relaunchPath error: &dontThrow]; // Clean up the copied relauncher
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while installing the update. Please try again later.", nil), NSLocalizedFailureReasonErrorKey: [error localizedDescription]}]];
}
@@ -406,8 +417,8 @@
if ([error localizedFailureReason]) {
SULog(@"Sparkle Error (continued): %@", [error localizedFailureReason]);
}
if (download) {
[download cancel];
if (self.download) {
[self.download cancel];
}
[self abortUpdate];
}
+1 -1
View File
@@ -51,7 +51,7 @@ extern int bsdiff(int argc, const char **argv);
- (void)main
{
NSString *temporaryFile = temporaryFilename(@"BinaryDelta");
const char *argv[] = {"/usr/bin/bsdiff", [_fromPath fileSystemRepresentation], [_toPath fileSystemRepresentation], [temporaryFile fileSystemRepresentation]};
const char *argv[] = {"/usr/bin/bsdiff", [self._fromPath fileSystemRepresentation], [self._toPath fileSystemRepresentation], [temporaryFile fileSystemRepresentation]};
int result = bsdiff(4, argv);
if (!result)
self.resultPath = temporaryFile;
+21 -19
View File
@@ -24,16 +24,18 @@ typedef struct {
#endif
@interface SUHost ()
@property (strong, readwrite) NSBundle *bundle;
@property (copy) NSString *defaultsDomain;
@property (assign) BOOL usesStandardUserDefaults;
@end
@implementation SUHost
{
NSString *defaultsDomain;
BOOL usesStandardUserDefaults;
}
@synthesize bundle;
@synthesize defaultsDomain;
@synthesize usesStandardUserDefaults;
- (instancetype)initWithBundle:(NSBundle *)aBundle
{
@@ -45,13 +47,13 @@ typedef struct {
SULog(@"Sparkle Error: the bundle being updated at %@ has no CFBundleIdentifier! This will cause preference read/write to not work properly.", self.bundle);
}
defaultsDomain = [self.bundle objectForInfoDictionaryKey:SUDefaultsDomainKey];
if (!defaultsDomain) {
defaultsDomain = [self.bundle bundleIdentifier];
self.defaultsDomain = [self.bundle objectForInfoDictionaryKey:SUDefaultsDomainKey];
if (!self.defaultsDomain) {
self.defaultsDomain = [self.bundle bundleIdentifier];
}
// If we're using the main bundle's defaults we'll use the standard user defaults mechanism, otherwise we have to get CF-y.
usesStandardUserDefaults = [defaultsDomain isEqualToString:[[NSBundle mainBundle] bundleIdentifier]];
usesStandardUserDefaults = [self.defaultsDomain isEqualToString:[[NSBundle mainBundle] bundleIdentifier]];
}
return self;
}
@@ -186,42 +188,42 @@ typedef struct {
- (id)objectForUserDefaultsKey:(NSString *)defaultName
{
if (!defaultName || !defaultsDomain) {
if (!defaultName || !self.defaultsDomain) {
return nil;
}
// Under Tiger, CFPreferencesCopyAppValue doesn't get values from NSRegistrationDomain, so anything
// passed into -[NSUserDefaults registerDefaults:] is ignored. The following line falls
// back to using NSUserDefaults, but only if the host bundle is the main bundle.
if (usesStandardUserDefaults) {
if (self.usesStandardUserDefaults) {
return [[NSUserDefaults standardUserDefaults] objectForKey:defaultName];
}
CFPropertyListRef obj = CFPreferencesCopyAppValue((__bridge CFStringRef)defaultName, (__bridge CFStringRef)defaultsDomain);
CFPropertyListRef obj = CFPreferencesCopyAppValue((__bridge CFStringRef)defaultName, (__bridge CFStringRef)self.defaultsDomain);
return CFBridgingRelease(obj);
}
- (void)setObject:(id)value forUserDefaultsKey:(NSString *)defaultName
{
if (usesStandardUserDefaults)
if (self.usesStandardUserDefaults)
{
[[NSUserDefaults standardUserDefaults] setObject:value forKey:defaultName];
}
else
{
CFPreferencesSetValue((__bridge CFStringRef)defaultName, (__bridge CFPropertyListRef)(value), (__bridge CFStringRef)defaultsDomain, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
CFPreferencesSynchronize((__bridge CFStringRef)defaultsDomain, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
CFPreferencesSetValue((__bridge CFStringRef)defaultName, (__bridge CFPropertyListRef)(value), (__bridge CFStringRef)self.defaultsDomain, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
CFPreferencesSynchronize((__bridge CFStringRef)self.defaultsDomain, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
}
}
- (BOOL)boolForUserDefaultsKey:(NSString *)defaultName
{
if (usesStandardUserDefaults) {
if (self.usesStandardUserDefaults) {
return [[NSUserDefaults standardUserDefaults] boolForKey:defaultName];
}
BOOL value;
CFPropertyListRef plr = CFPreferencesCopyAppValue((__bridge CFStringRef)defaultName, (__bridge CFStringRef)defaultsDomain);
CFPropertyListRef plr = CFPreferencesCopyAppValue((__bridge CFStringRef)defaultName, (__bridge CFStringRef)self.defaultsDomain);
if (plr == NULL) {
value = NO;
}
@@ -235,14 +237,14 @@ typedef struct {
- (void)setBool:(BOOL)value forUserDefaultsKey:(NSString *)defaultName
{
if (usesStandardUserDefaults)
if (self.usesStandardUserDefaults)
{
[[NSUserDefaults standardUserDefaults] setBool:value forKey:defaultName];
}
else
{
CFPreferencesSetValue((__bridge CFStringRef)defaultName, (__bridge CFBooleanRef)@(value), (__bridge CFStringRef)defaultsDomain, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
CFPreferencesSynchronize((__bridge CFStringRef)defaultsDomain, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
CFPreferencesSetValue((__bridge CFStringRef)defaultName, (__bridge CFBooleanRef)@(value), (__bridge CFStringRef)self.defaultsDomain, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
CFPreferencesSynchronize((__bridge CFStringRef)self.defaultsDomain, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
}
}
+10 -5
View File
@@ -13,14 +13,19 @@
#import "SUAppcastItem.h"
#import "SUVersionComparisonProtocol.h"
@interface SUScheduledUpdateDriver ()
@property (assign) BOOL showErrors;
@end
@implementation SUScheduledUpdateDriver
{
BOOL showErrors;
}
@synthesize showErrors;
- (void)didFindValidUpdate
{
showErrors = YES; // We only start showing errors after we present the UI for the first time.
self.showErrors = YES; // We only start showing errors after we present the UI for the first time.
[super didFindValidUpdate];
}
@@ -38,7 +43,7 @@
- (void)abortUpdateWithError:(NSError *)error
{
if (showErrors)
if (self.showErrors)
[super abortUpdateWithError:error];
else
[self abortUpdate];
+44 -38
View File
@@ -14,22 +14,28 @@
#import "SUStatusController.h"
#import "SUConstants.h"
@interface SUUIBasedUpdateDriver ()
@property (strong) SUStatusController *statusController;
@property (strong) SUUpdateAlert *updateAlert;
@end
@implementation SUUIBasedUpdateDriver
{
SUStatusController *statusController;
SUUpdateAlert *updateAlert;
}
@synthesize statusController;
@synthesize updateAlert;
- (void)didFindValidUpdate
{
updateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:self.updateItem host:self.host];
[updateAlert setDelegate:self];
self.updateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:self.updateItem host:self.host];
[self.updateAlert setDelegate:self];
id<SUVersionDisplay> versDisp = nil;
if ([[self.updater delegate] respondsToSelector:@selector(versionDisplayerForUpdater:)]) {
versDisp = [[self.updater delegate] versionDisplayerForUpdater:self.updater];
}
[updateAlert setVersionDisplayer: versDisp];
[self.updateAlert setVersionDisplayer: versDisp];
if ([[self.updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)]) {
[[self.updater delegate] updater:self.updater didFindValidUpdate:self.updateItem];
@@ -40,13 +46,13 @@
// there may be no way for the application to be activated to make it visible again.
if ([self.host isBackgroundApplication])
{
[[updateAlert window] setHidesOnDeactivate:NO];
[[self.updateAlert window] setHidesOnDeactivate:NO];
[NSApp activateIgnoringOtherApps:YES];
}
// Only show the update alert if the app is active; otherwise, we'll wait until it is.
if ([NSApp isActive])
[[updateAlert window] makeKeyAndOrderFront:self];
[[self.updateAlert window] makeKeyAndOrderFront:self];
else
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:NSApplicationDidBecomeActiveNotification object:NSApp];
}
@@ -68,21 +74,21 @@
- (void)applicationDidBecomeActive:(NSNotification *) __unused aNotification
{
[[updateAlert window] makeKeyAndOrderFront:self];
[[self.updateAlert window] makeKeyAndOrderFront:self];
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"NSApplicationDidBecomeActiveNotification" object:NSApp];
}
- (void)updateAlert:(SUUpdateAlert *) __unused alert finishedWithChoice:(SUUpdateAlertChoice)choice
{
updateAlert = nil;
self.updateAlert = nil;
[self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey];
switch (choice)
{
case SUInstallUpdateChoice:
statusController = [[SUStatusController alloc] initWithHost:self.host];
[statusController beginActionWithTitle:SULocalizedString(@"Downloading update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil];
[statusController setButtonTitle:SULocalizedString(@"Cancel", nil) target:self action:@selector(cancelDownload:) isDefault:NO];
[statusController showWindow:self];
self.statusController = [[SUStatusController alloc] initWithHost:self.host];
[self.statusController beginActionWithTitle:SULocalizedString(@"Downloading update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil];
[self.statusController setButtonTitle:SULocalizedString(@"Cancel", nil) target:self action:@selector(cancelDownload:) isDefault:NO];
[self.statusController showWindow:self];
[self downloadUpdate];
break;
@@ -104,7 +110,7 @@
- (void)download:(NSURLDownload *) __unused download didReceiveResponse:(NSURLResponse *)response
{
[statusController setMaxProgressValue:[response expectedContentLength]];
[self.statusController setMaxProgressValue:[response expectedContentLength]];
}
- (NSString *)humanReadableSizeFromDouble:(double)value
@@ -126,11 +132,11 @@
- (void)download:(NSURLDownload *) __unused download didReceiveDataOfLength:(NSUInteger)length
{
[statusController setProgressValue:[statusController progressValue] + (double)length];
if ([statusController maxProgressValue] > 0.0)
[statusController setStatusText:[NSString stringWithFormat:SULocalizedString(@"%@ of %@", nil), [self humanReadableSizeFromDouble:[statusController progressValue]], [self humanReadableSizeFromDouble:[statusController maxProgressValue]]]];
[self.statusController setProgressValue:[self.statusController progressValue] + (double)length];
if ([self.statusController maxProgressValue] > 0.0)
[self.statusController setStatusText:[NSString stringWithFormat:SULocalizedString(@"%@ of %@", nil), [self humanReadableSizeFromDouble:[self.statusController progressValue]], [self humanReadableSizeFromDouble:[self.statusController maxProgressValue]]]];
else
[statusController setStatusText:[NSString stringWithFormat:SULocalizedString(@"%@ downloaded", nil), [self humanReadableSizeFromDouble:[statusController progressValue]]]];
[self.statusController setStatusText:[NSString stringWithFormat:SULocalizedString(@"%@ downloaded", nil), [self humanReadableSizeFromDouble:[self.statusController progressValue]]]];
}
- (IBAction)cancelDownload:(id) __unused sender
@@ -143,30 +149,30 @@
- (void)extractUpdate
{
// Now we have to extract the downloaded archive.
[statusController beginActionWithTitle:SULocalizedString(@"Extracting update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil];
[statusController setButtonEnabled:NO];
[self.statusController beginActionWithTitle:SULocalizedString(@"Extracting update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil];
[self.statusController setButtonEnabled:NO];
[super extractUpdate];
}
- (void)unarchiver:(SUUnarchiver *) __unused ua extractedLength:(unsigned long)length
{
// We do this here instead of in extractUpdate so that we only have a determinate progress bar for archives with progress.
if ([statusController maxProgressValue] == 0.0)
if ([self.statusController maxProgressValue] == 0.0)
{
NSDictionary * attributes;
attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:self.downloadPath error:nil];
[statusController setMaxProgressValue:[attributes[NSFileSize] doubleValue]];
[self.statusController setMaxProgressValue:[attributes[NSFileSize] doubleValue]];
}
[statusController setProgressValue:[statusController progressValue] + (double)length];
[self.statusController setProgressValue:[self.statusController progressValue] + (double)length];
}
- (void)unarchiverDidFinish:(SUUnarchiver *) __unused ua
{
[statusController beginActionWithTitle:SULocalizedString(@"Ready to Install", nil) maxProgressValue:1.0 statusText:nil];
[statusController setProgressValue:1.0]; // Fill the bar.
[statusController setButtonEnabled:YES];
[statusController setButtonTitle:SULocalizedString(@"Install and Relaunch", nil) target:self action:@selector(installAndRestart:) isDefault:YES];
[[statusController window] makeKeyAndOrderFront: self];
[self.statusController beginActionWithTitle:SULocalizedString(@"Ready to Install", nil) maxProgressValue:1.0 statusText:nil];
[self.statusController setProgressValue:1.0]; // Fill the bar.
[self.statusController setButtonEnabled:YES];
[self.statusController setButtonTitle:SULocalizedString(@"Install and Relaunch", nil) target:self action:@selector(installAndRestart:) isDefault:YES];
[[self.statusController window] makeKeyAndOrderFront: self];
[NSApp requestUserAttention:NSInformationalRequest];
}
@@ -177,8 +183,8 @@
- (void)installWithToolAndRelaunch:(BOOL)relaunch
{
[statusController beginActionWithTitle:SULocalizedString(@"Installing update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil];
[statusController setButtonEnabled:NO];
[self.statusController beginActionWithTitle:SULocalizedString(@"Installing update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil];
[self.statusController setButtonEnabled:NO];
[super installWithToolAndRelaunch:relaunch];
@@ -187,10 +193,10 @@
// tabs open), the status window still stays on the screen and obscures
// other windows; with this fix, it doesn't
if (statusController)
if (self.statusController)
{
[statusController close];
statusController = nil;
[self.statusController close];
self.statusController = nil;
}
}
@@ -203,10 +209,10 @@
- (void)abortUpdate
{
if (statusController)
if (self.statusController)
{
[statusController close];
statusController = nil;
[self.statusController close];
self.statusController = nil;
}
[super abortUpdate];
}
+87 -72
View File
@@ -24,24 +24,39 @@
@end
@interface SUUpdateAlert ()
@property (strong) SUAppcastItem *updateItem;
@property (strong) SUHost *host;
@property (strong) NSProgressIndicator *releaseNotesSpinner;
@property (assign) BOOL webViewFinishedLoading;
@property (weak) IBOutlet WebView *releaseNotesView;
@property (weak) IBOutlet NSTextField *descriptionField;
@property (weak) IBOutlet NSButton *installButton; // UK 2007-08-31.
@property (weak) IBOutlet NSButton *skipButton;
@property (weak) IBOutlet NSButton *laterButton;
@end
@implementation SUUpdateAlert
{
SUAppcastItem *updateItem;
SUHost *host;
IBOutlet WebView *releaseNotesView;
IBOutlet NSTextField *description;
IBOutlet NSButton *installButton; // UK 2007-08-31.
IBOutlet NSButton *skipButton;
IBOutlet NSButton *laterButton;
NSProgressIndicator *releaseNotesSpinner;
BOOL webViewFinishedLoading;
}
@synthesize delegate;
@synthesize versionDisplayer;
@synthesize updateItem;
@synthesize host;
@synthesize releaseNotesSpinner;
@synthesize webViewFinishedLoading;
@synthesize releaseNotesView;
@synthesize descriptionField;
@synthesize installButton;
@synthesize skipButton;
@synthesize laterButton;
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost
{
self = [super initWithHost:host windowNibName:@"SUUpdateAlert"];
@@ -59,15 +74,15 @@
return self;
}
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], [host bundlePath]]; }
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], [self.host bundlePath]]; }
- (void)endWithSelection:(SUUpdateAlertChoice)choice
{
[releaseNotesView stopLoading:self];
[releaseNotesView setFrameLoadDelegate:nil];
[releaseNotesView setPolicyDelegate:nil];
[releaseNotesView removeFromSuperview]; // Otherwise it gets sent Esc presses (why?!) and gets very confused.
[self.releaseNotesView stopLoading:self];
[self.releaseNotesView setFrameLoadDelegate:nil];
[self.releaseNotesView setPolicyDelegate:nil];
[self.releaseNotesView removeFromSuperview]; // Otherwise it gets sent Esc presses (why?!) and gets very confused.
[self close];
if ([self.delegate respondsToSelector:@selector(updateAlert:finishedWithChoice:)])
[self.delegate updateAlert:self finishedWithChoice:choice];
@@ -96,8 +111,8 @@
- (void)displayReleaseNotes
{
// Set the default font
[releaseNotesView setPreferencesIdentifier:[SPARKLE_BUNDLE bundleIdentifier]];
WebPreferences *prefs = [releaseNotesView preferences];
[self.releaseNotesView setPreferencesIdentifier:[SPARKLE_BUNDLE bundleIdentifier]];
WebPreferences *prefs = [self.releaseNotesView preferences];
NSString *familyName = [[NSFont systemFontOfSize:8] familyName];
if ([familyName hasPrefix:@"."]) { // 10.9 returns ".Lucida Grande UI", which isn't a valid name for the WebView
familyName = @"Lucida Grande";
@@ -105,44 +120,44 @@
[prefs setStandardFontFamily:familyName];
[prefs setDefaultFontSize:(int)[NSFont systemFontSizeForControlSize:NSSmallControlSize]];
[prefs setPlugInsEnabled:NO];
[releaseNotesView setFrameLoadDelegate:self];
[releaseNotesView setPolicyDelegate:self];
[self.releaseNotesView setFrameLoadDelegate:self];
[self.releaseNotesView setPolicyDelegate:self];
// Stick a nice big spinner in the middle of the web view until the page is loaded.
NSRect frame = [[releaseNotesView superview] frame];
releaseNotesSpinner = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(NSMidX(frame)-16, NSMidY(frame)-16, 32, 32)];
[releaseNotesSpinner setStyle:NSProgressIndicatorSpinningStyle];
[releaseNotesSpinner startAnimation:self];
webViewFinishedLoading = NO;
[[releaseNotesView superview] addSubview:releaseNotesSpinner];
NSRect frame = [[self.releaseNotesView superview] frame];
self.releaseNotesSpinner = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(NSMidX(frame)-16, NSMidY(frame)-16, 32, 32)];
[self.releaseNotesSpinner setStyle:NSProgressIndicatorSpinningStyle];
[self.releaseNotesSpinner startAnimation:self];
self.webViewFinishedLoading = NO;
[[self.releaseNotesView superview] addSubview:self.releaseNotesSpinner];
// If there's a release notes URL, load it; otherwise, just stick the contents of the description into the web view.
if ([updateItem releaseNotesURL])
if ([self.updateItem releaseNotesURL])
{
if ([[updateItem releaseNotesURL] isFileURL])
if ([[self.updateItem releaseNotesURL] isFileURL])
{
[[releaseNotesView mainFrame] loadHTMLString:@"Release notes with file:// URLs are not supported for security reasons&mdash;Javascript would be able to read files on your file system." baseURL:nil];
[[self.releaseNotesView mainFrame] loadHTMLString:@"Release notes with file:// URLs are not supported for security reasons&mdash;Javascript would be able to read files on your file system." baseURL:nil];
}
else
{
[[releaseNotesView mainFrame] loadRequest:[NSURLRequest requestWithURL:[updateItem releaseNotesURL] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30]];
[[self.releaseNotesView mainFrame] loadRequest:[NSURLRequest requestWithURL:[self.updateItem releaseNotesURL] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30]];
}
}
else
{
[[releaseNotesView mainFrame] loadHTMLString:[updateItem itemDescription] baseURL:nil];
[[self.releaseNotesView mainFrame] loadHTMLString:[self.updateItem itemDescription] baseURL:nil];
}
}
- (BOOL)showsReleaseNotes
{
NSNumber *shouldShowReleaseNotes = [host objectForInfoDictionaryKey:SUShowReleaseNotesKey];
NSNumber *shouldShowReleaseNotes = [self.host objectForInfoDictionaryKey:SUShowReleaseNotesKey];
if (shouldShowReleaseNotes == nil)
{
// UK 2007-09-18: Don't show release notes if RSS item contains no description and no release notes URL:
return( ([updateItem itemDescription] != nil
&& [[[updateItem itemDescription] stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]] length] > 0)
|| [updateItem releaseNotesURL] != nil );
return( ([self.updateItem itemDescription] != nil
&& [[[self.updateItem itemDescription] stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]] length] > 0)
|| [self.updateItem releaseNotesURL] != nil );
}
else
return [shouldShowReleaseNotes boolValue];
@@ -151,8 +166,8 @@
- (BOOL)allowsAutomaticUpdates
{
BOOL allowAutoUpdates = YES; // Defaults to YES.
if( [host objectForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey] )
allowAutoUpdates = [host boolForInfoDictionaryKey: SUAllowsAutomaticUpdatesKey];
if( [self.host objectForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey] )
allowAutoUpdates = [self.host boolForInfoDictionaryKey: SUAllowsAutomaticUpdatesKey];
// UK 2007-08-31: Give delegate a chance to modify this choice:
if (self.delegate && [self.delegate respondsToSelector: @selector(updateAlert:shouldAllowAutoUpdate:)] )
@@ -163,9 +178,9 @@
- (void)awakeFromNib
{
NSString* sizeStr = [host objectForInfoDictionaryKey:SUFixedHTMLDisplaySizeKey];
NSString* sizeStr = [self.host objectForInfoDictionaryKey:SUFixedHTMLDisplaySizeKey];
if ([host isBackgroundApplication]) {
if ([self.host isBackgroundApplication]) {
[[self window] setLevel:NSFloatingWindowLevel]; // This means the window will float over all other apps, if our app is switched out ?! UK 2007-09-04
}
[[self window] setFrameAutosaveName: sizeStr ? @"" : @"SUUpdateAlertFrame"];
@@ -176,7 +191,7 @@
if (!showReleaseNotes) // UK 2007-09-18
{
// Resize the window to be appropriate for not having a huge release notes view.
frame.size.height -= [releaseNotesView frame].size.height + 40; // Extra 40 is for the release notes label and margin.
frame.size.height -= [self.releaseNotesView frame].size.height + 40; // Extra 40 is for the release notes label and margin.
if ([self allowsAutomaticUpdates]) {
frame.size.height += 10; // Make room for the check box.
@@ -191,45 +206,45 @@
}
else if (![self allowsAutomaticUpdates])
{
NSRect boxFrame = [[[releaseNotesView superview] superview] frame];
NSRect boxFrame = [[[self.releaseNotesView superview] superview] frame];
boxFrame.origin.y -= 20;
boxFrame.size.height += 20;
[[[releaseNotesView superview] superview] setFrame:boxFrame];
[[[self.releaseNotesView superview] superview] setFrame:boxFrame];
}
if( [updateItem fileURL] == nil ) // UK 2007-08-31 (whole if clause)
if( [self.updateItem fileURL] == nil ) // UK 2007-08-31 (whole if clause)
{
[installButton setTitle: SULocalizedString( @"Learn More...", @"Alternate title for 'Install Update' button when there's no download in RSS feed." )];
[installButton setAction: @selector(openInfoURL:)];
[self.installButton setTitle: SULocalizedString( @"Learn More...", @"Alternate title for 'Install Update' button when there's no download in RSS feed." )];
[self.installButton setAction: @selector(openInfoURL:)];
}
// Make sure button widths are OK:
#define DISTANCE_BETWEEN_BUTTONS 3
#define DISTANCE_BETWEEN_BUTTON_GROUPS 12
CGFloat minimumWindowWidth = [[self window] frame].size.width -NSMaxX([installButton frame]) +NSMinX([skipButton frame]); // Distance between contents and left/right edge.
NSDictionary* attrs = @{NSFontAttributeName: [installButton font]};
NSSize titleSize = [[installButton title] sizeWithAttributes: attrs];
CGFloat minimumWindowWidth = [[self window] frame].size.width -NSMaxX([self.self.installButton frame]) +NSMinX([self.skipButton frame]); // Distance between contents and left/right edge.
NSDictionary* attrs = @{NSFontAttributeName: [self.installButton font]};
NSSize titleSize = [[self.installButton title] sizeWithAttributes: attrs];
titleSize.width += (16 + 8) * 2; // 16 px for the end caps plus 8 px padding at each end or it'll look as ugly as calling -sizeToFit.
NSRect installBtnBox = [installButton frame];
NSRect installBtnBox = [self.installButton frame];
installBtnBox.origin.x += installBtnBox.size.width -titleSize.width;
installBtnBox.size.width = titleSize.width;
[installButton setFrame: installBtnBox];
[self.installButton setFrame: installBtnBox];
minimumWindowWidth += titleSize.width;
titleSize = [[laterButton title] sizeWithAttributes: attrs];
titleSize = [[self.laterButton title] sizeWithAttributes: attrs];
titleSize.width += (16 + 8) * 2; // 16 px for the end caps plus 8 px padding at each end or it'll look as ugly as calling -sizeToFit.
NSRect laterBtnBox = [installButton frame];
NSRect laterBtnBox = [self.installButton frame];
laterBtnBox.origin.x = installBtnBox.origin.x -DISTANCE_BETWEEN_BUTTONS -titleSize.width;
laterBtnBox.size.width = titleSize.width;
[laterButton setFrame: laterBtnBox];
[self.laterButton setFrame: laterBtnBox];
minimumWindowWidth += DISTANCE_BETWEEN_BUTTONS +titleSize.width;
titleSize = [[skipButton title] sizeWithAttributes: attrs];
titleSize = [[self.skipButton title] sizeWithAttributes: attrs];
titleSize.width += (16 + 8) * 2; // 16 px for the end caps plus 8 px padding at each end or it'll look as ugly as calling -sizeToFit.
NSRect skipBtnBox = [skipButton frame];
NSRect skipBtnBox = [self.skipButton frame];
skipBtnBox.size.width = titleSize.width;
[skipButton setFrame: skipBtnBox];
[self.skipButton setFrame: skipBtnBox];
minimumWindowWidth += DISTANCE_BETWEEN_BUTTON_GROUPS +titleSize.width;
if( showReleaseNotes ) // UK 2007-09-18 (whole block)
@@ -241,10 +256,10 @@
// NSBox* boxView = (NSBox*)[[releaseNotesView superview] superview];
//[boxView setBorderType: NSNoBorder];
[releaseNotesView setDrawsBackground: NO];
[self.releaseNotesView setDrawsBackground: NO];
sizeDiff.width = desiredSize.width -[releaseNotesView frame].size.width;
sizeDiff.height = desiredSize.height -[releaseNotesView frame].size.height;
sizeDiff.width = desiredSize.width -[self.releaseNotesView frame].size.width;
sizeDiff.height = desiredSize.height -[self.releaseNotesView frame].size.height;
frame.size.width += sizeDiff.width;
frame.size.height += sizeDiff.height;
@@ -267,13 +282,13 @@
[self displayReleaseNotes];
}
[[[releaseNotesView superview] superview] setHidden: !showReleaseNotes]; // UK 2007-09-18
[[[self.releaseNotesView superview] superview] setHidden: !showReleaseNotes]; // UK 2007-09-18
}
-(BOOL)showsReleaseNotesText
{
return( [host objectForInfoDictionaryKey:SUFixedHTMLDisplaySizeKey] == nil );
return( [self.host objectForInfoDictionaryKey:SUFixedHTMLDisplaySizeKey] == nil );
}
@@ -285,42 +300,42 @@
- (NSImage *)applicationIcon
{
return [host icon];
return [self.host icon];
}
- (NSString *)titleText
{
return [NSString stringWithFormat:SULocalizedString(@"A new version of %@ is available!", nil), [host name]];
return [NSString stringWithFormat:SULocalizedString(@"A new version of %@ is available!", nil), [self.host name]];
}
- (NSString *)descriptionText
{
NSString *updateItemVersion = [updateItem displayVersionString];
NSString *hostVersion = [host displayVersion];
NSString *updateItemVersion = [self.updateItem displayVersionString];
NSString *hostVersion = [self.host displayVersion];
// Display more info if the version strings are the same; useful for betas.
if (!self.versionDisplayer && [updateItemVersion isEqualToString:hostVersion] )
{
updateItemVersion = [updateItemVersion stringByAppendingFormat:@" (%@)", [updateItem versionString]];
hostVersion = [hostVersion stringByAppendingFormat:@" (%@)", [host version]];
updateItemVersion = [updateItemVersion stringByAppendingFormat:@" (%@)", [self.updateItem versionString]];
hostVersion = [hostVersion stringByAppendingFormat:@" (%@)", [self.host version]];
}
else {
[self.versionDisplayer formatVersion: &updateItemVersion andVersion: &hostVersion];
}
return [NSString stringWithFormat:SULocalizedString(@"%@ %@ is now available--you have %@. Would you like to download it now?", nil), [host name], updateItemVersion, hostVersion];
return [NSString stringWithFormat:SULocalizedString(@"%@ %@ is now available--you have %@. Would you like to download it now?", nil), [self.host name], updateItemVersion, hostVersion];
}
- (void)webView:(WebView *)sender didFinishLoadForFrame:frame
{
if ([frame parentFrame] == nil) {
webViewFinishedLoading = YES;
[releaseNotesSpinner setHidden:YES];
self.webViewFinishedLoading = YES;
[self.releaseNotesSpinner setHidden:YES];
[sender display]; // necessary to prevent weird scroll bar artifacting
}
}
- (void)webView:(WebView *) __unused sender decidePolicyForNavigationAction:(NSDictionary *) __unused actionInformation request:(NSURLRequest *)request frame:(WebFrame *) __unused frame decisionListener:(id <WebPolicyDecisionListener>)listener
{
if (webViewFinishedLoading) {
if (self.webViewFinishedLoading) {
[[NSWorkspace sharedWorkspace] openURL:[request URL]];
[listener ignore];
+12 -11
View File
@@ -11,20 +11,26 @@
NSString * const SUUpdateDriverFinishedNotification = @"SUUpdateDriverFinished";
@interface SUUpdateDriver ()
@property (weak) SUUpdater *updater;
@property (copy) NSURL *appcastURL;
@property (getter=isInterruptible) BOOL interruptible;
@end
@implementation SUUpdateDriver
{
NSURL *appcastURL;
}
@synthesize updater;
@synthesize host;
@synthesize interruptible = isInterruptible;
@synthesize interruptible;
@synthesize finished;
@synthesize appcastURL;
- (instancetype) initWithUpdater:(SUUpdater *)anUpdater
{
if ((self = [super init])) {
updater = anUpdater;
self.updater = anUpdater;
}
return self;
}
@@ -33,7 +39,7 @@ NSString * const SUUpdateDriverFinishedNotification = @"SUUpdateDriverFinished";
- (void)checkForUpdatesAtURL:(NSURL *)URL host:(SUHost *)h
{
appcastURL = [URL copy];
self.appcastURL = URL;
self.host = h;
}
@@ -43,9 +49,4 @@ NSString * const SUUpdateDriverFinishedNotification = @"SUUpdateDriverFinished";
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdateDriverFinishedNotification object:self];
}
- (void)setInterruptible:(BOOL)interruptible
{
isInterruptible = interruptible;
}
@end
+43 -33
View File
@@ -12,25 +12,35 @@
#import "SUConstants.h"
@interface SUUpdatePermissionPrompt ()
@property BOOL isShowingMoreInfo, shouldSendProfile;
@property (assign) BOOL isShowingMoreInfo;
@property (assign) BOOL shouldSendProfile;
@property (strong) SUHost *host;
@property (strong) NSArray *systemProfileInformationArray;
@property (weak) id <SUUpdatePermissionPromptDelegate> delegate;
@property (weak) IBOutlet NSTextField *descriptionTextField;
@property (weak) IBOutlet NSView *moreInfoView;
@property (weak) IBOutlet NSButton *moreInfoButton;
@property (weak) IBOutlet NSTableView *profileTableView;
@end
@implementation SUUpdatePermissionPrompt
{
SUHost *host;
NSArray *systemProfileInformationArray;
id<SUUpdatePermissionPromptDelegate> delegate;
IBOutlet NSTextField *descriptionTextField;
IBOutlet NSView *moreInfoView;
IBOutlet NSButton *moreInfoButton;
IBOutlet NSTableView *profileTableView;
}
@synthesize isShowingMoreInfo = _isShowingMoreInfo, shouldSendProfile = _shouldSendProfile;
@synthesize isShowingMoreInfo = _isShowingMoreInfo;
@synthesize shouldSendProfile = _shouldSendProfile;
@synthesize host;
@synthesize systemProfileInformationArray;
@synthesize delegate;
@synthesize descriptionTextField;
@synthesize moreInfoView;
@synthesize moreInfoButton;
@synthesize profileTableView;
- (BOOL)shouldAskAboutProfile
{
return [[host objectForInfoDictionaryKey:SUEnableSystemProfilingKey] boolValue];
return [[self.host objectForInfoDictionaryKey:SUEnableSystemProfilingKey] boolValue];
}
- (instancetype)initWithHost:(SUHost *)aHost systemProfile:(NSArray *)profile delegate:(id<SUUpdatePermissionPromptDelegate>)d
@@ -59,18 +69,18 @@
[NSApp runModalForWindow:[prompt window]];
}
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], [host bundlePath]]; }
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], [self.host bundlePath]]; }
- (void)awakeFromNib
{
if (![self shouldAskAboutProfile])
{
NSRect frame = [[self window] frame];
frame.size.height -= [moreInfoButton frame].size.height;
frame.size.height -= [self.moreInfoButton frame].size.height;
[[self window] setFrame:frame display:YES];
} else {
// Set the table view's delegate so we can disable row selection.
[profileTableView setDelegate:(id)self];
[self.profileTableView setDelegate:(id)self];
}
}
@@ -79,27 +89,27 @@
- (NSImage *)icon
{
return [host icon];
return [self.host icon];
}
- (NSString *)promptDescription
{
return [NSString stringWithFormat:SULocalizedString(@"Should %1$@ automatically check for updates? You can always check for updates manually from the %1$@ menu.", nil), [host name]];
return [NSString stringWithFormat:SULocalizedString(@"Should %1$@ automatically check for updates? You can always check for updates manually from the %1$@ menu.", nil), [self.host name]];
}
- (IBAction)toggleMoreInfo:(id) __unused sender
{
self.isShowingMoreInfo = !_isShowingMoreInfo;
self.isShowingMoreInfo = !self.isShowingMoreInfo;
NSView *contentView = [[self window] contentView];
NSRect contentViewFrame = [contentView frame];
NSRect windowFrame = [[self window] frame];
NSRect profileMoreInfoViewFrame = [moreInfoView frame];
NSRect profileMoreInfoButtonFrame = [moreInfoButton frame];
NSRect descriptionFrame = [descriptionTextField frame];
NSRect profileMoreInfoViewFrame = [self.moreInfoView frame];
NSRect profileMoreInfoButtonFrame = [self.moreInfoButton frame];
NSRect descriptionFrame = [self.descriptionTextField frame];
if (_isShowingMoreInfo)
if (self.isShowingMoreInfo)
{
// Add the subview
contentViewFrame.size.height += profileMoreInfoViewFrame.size.height;
@@ -110,15 +120,15 @@
windowFrame.size.height += profileMoreInfoViewFrame.size.height;
windowFrame.origin.y -= profileMoreInfoViewFrame.size.height;
[moreInfoView setFrame:profileMoreInfoViewFrame];
[moreInfoView setHidden:YES];
[contentView addSubview:moreInfoView
[self.moreInfoView setFrame:profileMoreInfoViewFrame];
[self.moreInfoView setHidden:YES];
[contentView addSubview:self.moreInfoView
positioned:NSWindowBelow
relativeTo:moreInfoButton];
relativeTo:self.moreInfoButton];
} else {
// Remove the subview
[moreInfoView setHidden:NO];
[moreInfoView removeFromSuperview];
[self.moreInfoView setHidden:NO];
[self.moreInfoView removeFromSuperview];
contentViewFrame.size.height -= profileMoreInfoViewFrame.size.height;
windowFrame.size.height -= profileMoreInfoViewFrame.size.height;
@@ -127,16 +137,16 @@
[[self window] setFrame:windowFrame display:YES animate:YES];
[contentView setFrame:contentViewFrame];
[contentView setNeedsDisplay:YES];
[moreInfoView setHidden:(!_isShowingMoreInfo)];
[self.moreInfoView setHidden:!self.isShowingMoreInfo];
}
- (IBAction)finishPrompt:(id)sender
{
if (![delegate respondsToSelector:@selector(updatePermissionPromptFinishedWithResult:)]) {
[NSException raise:@"SUInvalidDelegate" format:@"SUUpdatePermissionPrompt's delegate (%@) doesn't respond to updatePermissionPromptFinishedWithResult:!", delegate];
if (![self.delegate respondsToSelector:@selector(updatePermissionPromptFinishedWithResult:)]) {
[NSException raise:@"SUInvalidDelegate" format:@"SUUpdatePermissionPrompt's delegate (%@) doesn't respond to updatePermissionPromptFinishedWithResult:!", self.delegate];
}
[host setBool:_shouldSendProfile forUserDefaultsKey:SUSendProfileInfoKey];
[delegate updatePermissionPromptFinishedWithResult:([sender tag] == 1 ? SUAutomaticallyCheck : SUDoNotAutomaticallyCheck)];
[self.host setBool:self.shouldSendProfile forUserDefaultsKey:SUSendProfileInfoKey];
[self.delegate updatePermissionPromptFinishedWithResult:([sender tag] == 1 ? SUAutomaticallyCheck : SUDoNotAutomaticallyCheck)];
[[self window] close];
[NSApp stopModal];
}
+43 -41
View File
@@ -41,18 +41,20 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
-(void) notifyWillShowModalAlert;
-(void) notifyDidShowModalAlert;
@property (strong) SUUpdateDriver *driver;
@property (strong) SUHost *host;
@end
@implementation SUUpdater
{
SUUpdateDriver *driver;
SUHost *host;
}
@synthesize delegate;
@synthesize checkTimer;
@synthesize userAgentString = customUserAgentString;
@synthesize driver;
@synthesize host;
#pragma mark Initialization
static NSMutableDictionary *sharedUpdaters = nil;
@@ -125,7 +127,7 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault
return [self initForBundle:[NSBundle mainBundle]];
}
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@, %@>", [self class], [host bundlePath], [host installationPath]]; }
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@, %@>", [self class], [self.host bundlePath], [self.host installationPath]]; }
-(void) notifyWillShowModalAlert
@@ -147,7 +149,7 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault
BOOL shouldPrompt = NO;
// If the user has been asked about automatic checks, don't bother prompting
if ([host objectForUserDefaultsKey:SUEnableAutomaticChecksKey])
if ([self.host objectForUserDefaultsKey:SUEnableAutomaticChecksKey])
{
shouldPrompt = NO;
}
@@ -157,17 +159,17 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault
shouldPrompt = [self.delegate updaterShouldPromptForPermissionToCheckForUpdates:self];
}
// Has he been asked already? And don't ask if the host has a default value set in its Info.plist.
else if ([host objectForKey:SUEnableAutomaticChecksKey] == nil)
else if ([self.host objectForKey:SUEnableAutomaticChecksKey] == nil)
{
if ([host objectForUserDefaultsKey:SUEnableAutomaticChecksKeyOld]) {
[self setAutomaticallyChecksForUpdates:[host boolForUserDefaultsKey:SUEnableAutomaticChecksKeyOld]];
if ([self.host objectForUserDefaultsKey:SUEnableAutomaticChecksKeyOld]) {
[self setAutomaticallyChecksForUpdates:[self.host boolForUserDefaultsKey:SUEnableAutomaticChecksKeyOld]];
}
// Now, we don't want to ask the user for permission to do a weird thing on the first launch.
// We wait until the second launch, unless explicitly overridden via SUPromptUserOnFirstLaunchKey.
else if (![host objectForKey:SUPromptUserOnFirstLaunchKey])
else if (![self.host objectForKey:SUPromptUserOnFirstLaunchKey])
{
if ([host boolForUserDefaultsKey:SUHasLaunchedBeforeKey] == NO)
[host setBool:YES forUserDefaultsKey:SUHasLaunchedBeforeKey];
if ([self.host boolForUserDefaultsKey:SUHasLaunchedBeforeKey] == NO)
[self.host setBool:YES forUserDefaultsKey:SUHasLaunchedBeforeKey];
else
shouldPrompt = YES;
}
@@ -177,12 +179,12 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault
if (shouldPrompt)
{
NSArray *profileInfo = [host systemProfile];
NSArray *profileInfo = [self.host systemProfile];
// Always say we're sending the system profile here so that the delegate displays the parameters it would send.
if ([self.delegate respondsToSelector:@selector(feedParametersForUpdater:sendingSystemProfile:)]) {
profileInfo = [profileInfo arrayByAddingObjectsFromArray:[self.delegate feedParametersForUpdater:self sendingSystemProfile:YES]];
}
[SUUpdatePermissionPrompt promptWithHost:host systemProfile:profileInfo delegate:self];
[SUUpdatePermissionPrompt promptWithHost:self.host systemProfile:profileInfo delegate:self];
// We start the update checks and register as observer for changes after the prompt finishes
}
else
@@ -201,16 +203,16 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault
- (void)updateDriverDidFinish:(NSNotification *)note
{
if ([note object] == driver && [driver finished])
if ([note object] == self.driver && [self.driver finished])
{
driver = nil;
self.driver = nil;
[self scheduleNextUpdateCheck];
}
}
- (NSDate *)lastUpdateCheckDate
{
return [host objectForUserDefaultsKey:SULastCheckTimeKey];
return [self.host objectForUserDefaultsKey:SULastCheckTimeKey];
}
- (void)scheduleNextUpdateCheck
@@ -317,8 +319,8 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault
- (IBAction)checkForUpdates:(id) __unused sender
{
if (driver && [driver isInterruptible]) {
[driver abortUpdate];
if (self.driver && [self.driver isInterruptible]) {
[self.driver abortUpdate];
}
[self checkForUpdatesWithDriver:[[SUUserInitiatedUpdateDriver alloc] initWithUpdater:self]];
@@ -338,7 +340,7 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault
SULog( @"===== %@ =====", [[NSFileManager defaultManager] displayNameAtPath: [[NSBundle mainBundle] bundlePath]] );
[self willChangeValueForKey:@"lastUpdateCheckDate"];
[host setObject:[NSDate date] forUserDefaultsKey:SULastCheckTimeKey];
[self.host setObject:[NSDate date] forUserDefaultsKey:SULastCheckTimeKey];
[self didChangeValueForKey:@"lastUpdateCheckDate"];
if( [self.delegate respondsToSelector: @selector(updaterMayCheckForUpdates:)] && ![self.delegate updaterMayCheckForUpdates: self] )
@@ -347,10 +349,10 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault
return;
}
driver = d;
self.driver = d;
// If we're not given a driver at all, just schedule the next update check and bail.
if (!driver)
if (!self.driver)
{
[self scheduleNextUpdateCheck];
return;
@@ -358,9 +360,9 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault
NSURL* theFeedURL = [self parameterizedFeedURL];
if( theFeedURL ) // Use a NIL URL to cancel quietly.
[driver checkForUpdatesAtURL: theFeedURL host:host];
[self.driver checkForUpdatesAtURL: theFeedURL host:self.host];
else
[driver abortUpdate];
[self.driver abortUpdate];
}
- (void)registerAsObserver
@@ -407,7 +409,7 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault
- (void)setAutomaticallyChecksForUpdates:(BOOL)automaticallyCheckForUpdates
{
[host setBool:automaticallyCheckForUpdates forUserDefaultsKey:SUEnableAutomaticChecksKey];
[self.host setBool:automaticallyCheckForUpdates forUserDefaultsKey:SUEnableAutomaticChecksKey];
// Hack to support backwards compatibility with older Sparkle versions, which supported
// disabling updates by setting the check interval to 0.
if (automaticallyCheckForUpdates && (NSInteger)[self updateCheckInterval] == 0) {
@@ -424,23 +426,23 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault
if ((NSInteger)[self updateCheckInterval] == 0) {
return NO;
}
return [host boolForKey:SUEnableAutomaticChecksKey];
return [self.host boolForKey:SUEnableAutomaticChecksKey];
}
- (void)setAutomaticallyDownloadsUpdates:(BOOL)automaticallyUpdates
{
[host setBool:automaticallyUpdates forUserDefaultsKey:SUAutomaticallyUpdateKey];
[self.host setBool:automaticallyUpdates forUserDefaultsKey:SUAutomaticallyUpdateKey];
}
- (BOOL)automaticallyDownloadsUpdates
{
// If the SUAllowsAutomaticUpdatesKey exists and is set to NO, return NO.
if ([host objectForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey] && [host boolForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey] == NO) {
if ([self.host objectForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey] && [self.host boolForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey] == NO) {
return NO;
}
// Otherwise, automatically downloading updates is allowed. Does the user want it?
return [host boolForUserDefaultsKey:SUAutomaticallyUpdateKey];
return [self.host boolForUserDefaultsKey:SUAutomaticallyUpdateKey];
}
- (void)setFeedURL:(NSURL *)feedURL
@@ -448,7 +450,7 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault
if (![NSThread isMainThread])
[NSException raise:@"SUThreadException" format:@"This method must be called on the main thread"];
[host setObject:[feedURL absoluteString] forUserDefaultsKey:SUFeedURLKey];
[self.host setObject:[feedURL absoluteString] forUserDefaultsKey:SUFeedURLKey];
}
- (NSURL *)feedURL
@@ -457,7 +459,7 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault
[NSException raise:@"SUThreadException" format:@"This method must be called on the main thread"];
// A value in the user defaults overrides one in the Info.plist (so preferences panels can be created wherein users choose between beta / release feeds).
NSString *appcastString = [host objectForKey:SUFeedURLKey];
NSString *appcastString = [self.host objectForKey:SUFeedURLKey];
if( [self.delegate respondsToSelector: @selector(feedURLStringForUpdater:)] )
appcastString = [self.delegate feedURLStringForUpdater: self];
if (!appcastString) // Can't find an appcast string!
@@ -477,19 +479,19 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault
}
NSString *version = [SPARKLE_BUNDLE objectForInfoDictionaryKey:@"CFBundleVersion"];
NSString *userAgent = [NSString stringWithFormat:@"%@/%@ Sparkle/%@", [host name], [host displayVersion], version ? version : @"?"];
NSString *userAgent = [NSString stringWithFormat:@"%@/%@ Sparkle/%@", [self.host name], [self.host displayVersion], version ? version : @"?"];
NSData *cleanedAgent = [userAgent dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
return [[NSString alloc] initWithData:cleanedAgent encoding:NSASCIIStringEncoding];
}
- (void)setSendsSystemProfile:(BOOL)sendsSystemProfile
{
[host setBool:sendsSystemProfile forUserDefaultsKey:SUSendProfileInfoKey];
[self.host setBool:sendsSystemProfile forUserDefaultsKey:SUSendProfileInfoKey];
}
- (BOOL)sendsSystemProfile
{
return [host boolForKey:SUSendProfileInfoKey];
return [self.host boolForKey:SUSendProfileInfoKey];
}
- (NSURL *)parameterizedFeedURL
@@ -500,7 +502,7 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault
BOOL sendingSystemProfile = [self sendsSystemProfile];
// Let's only send the system profiling information once per week at most, so we normalize daily-checkers vs. biweekly-checkers and the such.
NSDate *lastSubmitDate = [host objectForUserDefaultsKey:SULastProfileSubmitDateKey];
NSDate *lastSubmitDate = [self.host objectForUserDefaultsKey:SULastProfileSubmitDateKey];
if (!lastSubmitDate) {
lastSubmitDate = [NSDate distantPast];
}
@@ -513,8 +515,8 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault
}
if (sendingSystemProfile)
{
parameters = [parameters arrayByAddingObjectsFromArray:[host systemProfile]];
[host setObject:[NSDate date] forUserDefaultsKey:SULastProfileSubmitDateKey];
parameters = [parameters arrayByAddingObjectsFromArray:[self.host systemProfile]];
[self.host setObject:[NSDate date] forUserDefaultsKey:SULastProfileSubmitDateKey];
}
if ([parameters count] == 0) { return baseFeedURL; }
@@ -536,7 +538,7 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault
- (void)setUpdateCheckInterval:(NSTimeInterval)updateCheckInterval
{
[host setObject:@(updateCheckInterval) forUserDefaultsKey:SUScheduledCheckIntervalKey];
[self.host setObject:@(updateCheckInterval) forUserDefaultsKey:SUScheduledCheckIntervalKey];
if ((NSInteger)updateCheckInterval == 0) { // For compatibility with 1.1's settings.
[self setAutomaticallyChecksForUpdates:NO];
}
@@ -549,7 +551,7 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault
- (NSTimeInterval)updateCheckInterval
{
// Find the stored check interval. User defaults override Info.plist.
NSNumber *intervalValue = [host objectForKey:SUScheduledCheckIntervalKey];
NSNumber *intervalValue = [self.host objectForKey:SUScheduledCheckIntervalKey];
if (intervalValue)
return [intervalValue doubleValue];
else
@@ -572,9 +574,9 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault
- (BOOL)updateInProgress
{
return driver && ([driver finished] == NO);
return self.driver && ([self.driver finished] == NO);
}
- (NSBundle *)hostBundle { return [host bundle]; }
- (NSBundle *)hostBundle { return [self.host bundle]; }
@end
+21 -15
View File
@@ -11,34 +11,40 @@
#import "SUStatusController.h"
#import "SUHost.h"
@interface SUUserInitiatedUpdateDriver ()
@property (strong) SUStatusController *checkingController;
@property (assign, getter=isCanceled) BOOL canceled;
@end
@implementation SUUserInitiatedUpdateDriver
{
SUStatusController *checkingController;
BOOL isCanceled;
}
@synthesize checkingController;
@synthesize canceled;
- (void)closeCheckingWindow
{
if (checkingController)
if (self.checkingController)
{
[[checkingController window] close];
checkingController = nil;
[[self.checkingController window] close];
self.checkingController = nil;
}
}
- (void)cancelCheckForUpdates:(id) __unused sender
{
[self closeCheckingWindow];
isCanceled = YES;
self.canceled = YES;
}
- (void)checkForUpdatesAtURL:(NSURL *)URL host:(SUHost *)aHost
{
checkingController = [[SUStatusController alloc] initWithHost:aHost];
[[checkingController window] center]; // Force the checking controller to load its window.
[checkingController beginActionWithTitle:SULocalizedString(@"Checking for updates...", nil) maxProgressValue:0.0 statusText:nil];
[checkingController setButtonTitle:SULocalizedString(@"Cancel", nil) target:self action:@selector(cancelCheckForUpdates:) isDefault:NO];
[checkingController showWindow:self];
self.checkingController = [[SUStatusController alloc] initWithHost:aHost];
[[self.checkingController window] center]; // Force the checking controller to load its window.
[self.checkingController beginActionWithTitle:SULocalizedString(@"Checking for updates...", nil) maxProgressValue:0.0 statusText:nil];
[self.checkingController setButtonTitle:SULocalizedString(@"Cancel", nil) target:self action:@selector(cancelCheckForUpdates:) isDefault:NO];
[self.checkingController showWindow:self];
[super checkForUpdatesAtURL:URL host:aHost];
// For background applications, obtain focus.
@@ -51,7 +57,7 @@
- (void)appcastDidFinishLoading:(SUAppcast *)ac
{
if (isCanceled)
if (self.isCanceled)
{
[self abortUpdate];
return;
@@ -74,7 +80,7 @@
- (void)appcast:(SUAppcast *)ac failedToLoadWithError:(NSError *)error
{
if (isCanceled)
if (self.isCanceled)
{
[self abortUpdate];
return;
+1 -1
View File
@@ -10,7 +10,7 @@
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="SUUpdateAlert">
<connections>
<outlet property="description" destination="101" id="105"/>
<outlet property="descriptionField" destination="101" id="9oA-2S-eXN"/>
<outlet property="installButton" destination="76" id="176"/>
<outlet property="laterButton" destination="22" id="177"/>
<outlet property="releaseNotesView" destination="18" id="32"/>