From dc8c6958554156f23bc54c1be5e623b0eea97a20 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 25 Jun 2006 07:34:03 +0000 Subject: [PATCH] Fixes #11, Observe user pref to turn off automatic scraper updates --- .../content/scholar/xpcom/schema.js | 32 ++++++++++++------- .../content/scholar/xpcom/scholar.js | 9 ++++-- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/chrome/chromeFiles/content/scholar/xpcom/schema.js b/chrome/chromeFiles/content/scholar/xpcom/schema.js index 4aad89e5fa..83de7915cd 100644 --- a/chrome/chromeFiles/content/scholar/xpcom/schema.js +++ b/chrome/chromeFiles/content/scholar/xpcom/schema.js @@ -50,18 +50,26 @@ Scholar.Schema = new function(){ * since the last check **/ function updateScrapersRemote(force){ - // Determine the earliest local time that we'd query the repository again - var nextCheck = new Date(); - nextCheck.setTime((parseInt(_getDBVersion('lastcheck')) - + SCHOLAR_CONFIG['REPOSITORY_CHECK_INTERVAL']) * 1000); // JS uses ms - var now = new Date(); - - // If enough time hasn't passed and it's not being forced, don't update - if (!force && now < nextCheck){ - Scholar.debug('Not enough time since last update -- not checking repository', 4); - // Set the repository timer to the remaining time - _setRepositoryTimer(Math.round((nextCheck.getTime() - now.getTime()) / 1000)); - return false; + if (!force){ + // Check user preference for automatic updates + if (!Scholar.Prefs.get('automaticScraperUpdates')){ + Scholar.debug('Automatic scraper updating disabled -- not checking repository', 4); + return false; + } + + // Determine the earliest local time that we'd query the repository again + var nextCheck = new Date(); + nextCheck.setTime((parseInt(_getDBVersion('lastcheck')) + + SCHOLAR_CONFIG['REPOSITORY_CHECK_INTERVAL']) * 1000); // JS uses ms + var now = new Date(); + + // If enough time hasn't passed, don't update + if (now < nextCheck){ + Scholar.debug('Not enough time since last update -- not checking repository', 4); + // Set the repository timer to the remaining time + _setRepositoryTimer(Math.round((nextCheck.getTime() - now.getTime()) / 1000)); + return false; + } } // Get the last timestamp we got from the server diff --git a/chrome/chromeFiles/content/scholar/xpcom/scholar.js b/chrome/chromeFiles/content/scholar/xpcom/scholar.js index e7af2cac55..cc84708dfe 100644 --- a/chrome/chromeFiles/content/scholar/xpcom/scholar.js +++ b/chrome/chromeFiles/content/scholar/xpcom/scholar.js @@ -369,8 +369,13 @@ Scholar.Prefs = new function(){ // subject is the nsIPrefBranch we're observing (after appropriate QI) // data is the name of the pref that's been changed (relative to subject) switch (data){ - case "pref1": - // pref1 changed + case "automaticScraperUpdates": + if (this.get('automaticScraperUpdates')){ + Scholar.Schema.updateScrapersRemote(); + } + else { + Scholar.Schema.stopRepositoryTimer(); + } break; } }