Skip to content

Commit

Permalink
Background updates would never get scheduled when the net's down.
Browse files Browse the repository at this point in the history
  • Loading branch information
andymatuschak committed Oct 10, 2011
1 parent 95398cd commit fc725cc
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions SUUpdater.m
Expand Up @@ -259,10 +259,8 @@ -(void) checkForUpdatesInBgReachabilityCheckWithDriver: (SUUpdateDriver*)inDrive
isNetworkReachable = NO;
}

if( isNetworkReachable )
{
[self performSelectorOnMainThread: @selector(checkForUpdatesWithDriver:) withObject: inDriver waitUntilDone: NO];
}
// If the network's not reachable, we pass a nil driver into checkForUpdatesWithDriver, which will then reschedule the next update so we try again later.
[self performSelectorOnMainThread: @selector(checkForUpdatesWithDriver:) withObject: isNetworkReachable ? inDriver : nil waitUntilDone: NO];

[pool release];
NS_HANDLER
Expand All @@ -274,12 +272,6 @@ -(void) checkForUpdatesInBgReachabilityCheckWithDriver: (SUUpdateDriver*)inDrive

- (void)checkForUpdatesInBackground
{
if( [delegate respondsToSelector: @selector(updaterMayCheckForUpdates:)] && ![delegate updaterMayCheckForUpdates: self] )
{
[self scheduleNextUpdateCheck];
return;
}

// 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:
Expand Down Expand Up @@ -316,7 +308,21 @@ - (void)checkForUpdatesWithDriver:(SUUpdateDriver *)d
[host setObject:[NSDate date] forUserDefaultsKey:SULastCheckTimeKey];
[self didChangeValueForKey:@"lastUpdateCheckDate"];

driver = [d retain];
if( [delegate respondsToSelector: @selector(updaterMayCheckForUpdates:)] && ![delegate updaterMayCheckForUpdates: self] )
{
[self scheduleNextUpdateCheck];
return;
}

driver = [d retain];

// If we're not given a driver at all, just schedule the next update check and bail.
if (!driver)
{
[self scheduleNextUpdateCheck];
return;
}

NSURL* theFeedURL = [self parameterizedFeedURL];
if( theFeedURL ) // Use a NIL URL to cancel quietly.
[driver checkForUpdatesAtURL: theFeedURL host:host];
Expand Down

0 comments on commit fc725cc

Please sign in to comment.