diff --git a/Sparkle/SUAutomaticUpdateDriver.m b/Sparkle/SUAutomaticUpdateDriver.m index 9fed2c71..8b51d331 100644 --- a/Sparkle/SUAutomaticUpdateDriver.m +++ b/Sparkle/SUAutomaticUpdateDriver.m @@ -43,13 +43,13 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 - (void)showUpdateAlert { - id updaterDelegate = [self.updater delegate]; if ([updaterDelegate suppressSparkleUI]) { [self automaticUpdateAlertFinishedWithChoice:SUInstallLaterChoice]; return; } +// NSLog(@"[Sparkle showUpdateAlert]"); self.interruptible = NO; self.alert = [[SUAutomaticUpdateAlert alloc] initWithAppcastItem:self.updateItem host:self.host completionBlock:^(SUAutomaticInstallationChoice choice) { @@ -98,6 +98,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 // If this is marked as a critical update, we'll prompt the user to install it right away. if ([self.updateItem isCriticalUpdate]) { +// NSLog(@"[Sparkle update deemed critical]"); [self showUpdateAlert]; } else diff --git a/Sparkle/SUErrors.h b/Sparkle/SUErrors.h index 54b0e8ff..ffbc8566 100644 --- a/Sparkle/SUErrors.h +++ b/Sparkle/SUErrors.h @@ -27,6 +27,7 @@ typedef NS_ENUM(OSStatus, SUError) { // Download phase errors. SUTemporaryDirectoryError = 2000, SUDownloadError = 2001, + SUHostDirectoryNotWritable = 2002, // Extraction phase errors. SUUnarchivingError = 3000, diff --git a/Sparkle/SUUpdater.h b/Sparkle/SUUpdater.h index 14fb786f..d7c26a39 100644 --- a/Sparkle/SUUpdater.h +++ b/Sparkle/SUUpdater.h @@ -153,9 +153,13 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey; @protocol SUUpdaterDelegate @optional - +/*! + Suppress sparkle UI. This should prevent any Sparkle UI from popping up. + Updates should be handled by the host. + */ -(BOOL)suppressSparkleUI; + /*! Returns whether to allow Sparkle to pop up. diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 8a7b4bc8..104ec6e5 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -314,8 +314,30 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults // Background update checks should only happen if we have a network connection. // Wouldn't want to annoy users on dial-up by establishing a connection every // hour or so: - SUUpdateDriver *theUpdateDriver = [[([self automaticallyDownloadsUpdates] ? [SUAutomaticUpdateDriver class] : [SUScheduledUpdateDriver class])alloc] initWithUpdater:self]; + BOOL canAutomaticallyDownloadUpdates = [self automaticallyDownloadsUpdates]; + if (!canAutomaticallyDownloadUpdates) + { + // TB: App is in a non writable directory + if ([self.delegate respondsToSelector:@selector(updater:didAbortWithError:)]) { + NSError *error = + [NSError errorWithDomain:SUSparkleErrorDomain code:SUHostDirectoryNotWritable + userInfo:@{NSLocalizedDescriptionKey: SULocalizedString(@"Host directory is not writable", nil)}]; + [self.delegate updater:nil didAbortWithError:error]; + } + return; + } + + SUUpdateDriver *theUpdateDriver; + + if (canAutomaticallyDownloadUpdates || [self.delegate suppressSparkleUI]) + { + theUpdateDriver = [[SUAutomaticUpdateDriver alloc] initWithUpdater:self]; + } + else { + theUpdateDriver = [[SUScheduledUpdateDriver alloc] initWithUpdater:self]; + } +// NSLog(@"[Sparkle driver class: %@]", [theUpdateDriver class]); dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [self checkForUpdatesInBgReachabilityCheckWithDriver:theUpdateDriver]; }); @@ -343,6 +365,8 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults - (void)installUpdatesIfAvailable { +// NSLog(@"[Sparkle installUpdatesIfAvailable]"); + if (self.driver && [self.driver isInterruptible]) { [self.driver abortUpdate]; } @@ -456,11 +480,15 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults { // If the host doesn't allow automatic updates, don't ever let them happen if (!self.host.allowsAutomaticUpdates) { +// NSLog(@"Host denied automatic updates"); return NO; } - // Otherwise, automatically downloading updates is allowed. Does the user want it? - return [self.host boolForUserDefaultsKey:SUAutomaticallyUpdateKey]; + + BOOL automatic = [self.host boolForUserDefaultsKey:SUAutomaticallyUpdateKey]; +// NSLog(@"Automatic updates %@", automatic ? @"enabled" : @"disabled"); + + return automatic; } - (void)setFeedURL:(NSURL *)feedURL