From 8cb061968787dee78c9786a51f3f9b4c7068ad4e Mon Sep 17 00:00:00 2001 From: gorhill Date: Sun, 26 Oct 2014 15:54:50 -0400 Subject: [PATCH] fix to ensure PSL is available when binding tabs --- src/js/start.js | 33 +++++++++++++++++++-------------- src/js/storage.js | 17 +++++++++++++---- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/js/start.js b/src/js/start.js index e06e693..8734c69 100644 --- a/src/js/start.js +++ b/src/js/start.js @@ -116,18 +116,6 @@ chrome.webNavigation.onBeforeNavigate.addListener(onBeforeNavigateCallback); /******************************************************************************/ -// Initialize internal state with maybe already existing tabs - -chrome.tabs.query({ url: '' }, function(tabs) { - var i = tabs.length; - // console.debug('HTTP Switchboard > preparing to bind %d tabs', i); - while ( i-- ) { - µMatrix.bindTabToPageStats(tabs[i].id, tabs[i].url); - } -}); - -/******************************************************************************/ - // Browser data jobs (function() { @@ -175,7 +163,24 @@ chrome.tabs.query({ url: '' }, function(tabs) { // Load everything -µMatrix.load(); -µMatrix.webRequest.start(); +(function() { + var µm = µMatrix; + + // This needs to be done when the PSL is loaded + var bindTabs = function(tabs) { + var i = tabs.length; + // console.debug('start.js > binding %d tabs', i); + while ( i-- ) { + µm.bindTabToPageStats(tabs[i].id, tabs[i].url); + } + µm.webRequest.start(); + }; + + var queryTabs = function() { + chrome.tabs.query({ url: '' }, bindTabs); + }; + + µm.load(queryTabs); +})(); /******************************************************************************/ diff --git a/src/js/storage.js b/src/js/storage.js index e5940ce..a139836 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -362,13 +362,18 @@ // Load updatable assets -µMatrix.loadUpdatableAssets = function(forceUpdate) { +µMatrix.loadUpdatableAssets = function(forceUpdate, callback) { + if ( typeof callback !== 'function' ) { + callback = this.noopFunc; + } + this.assets.autoUpdate = forceUpdate === true; this.assets.autoUpdateDelay = this.updateAssetsEvery; if ( forceUpdate ) { this.updater.restart(); } - this.loadPublicSuffixList(); + + this.loadPublicSuffixList(callback); this.loadHostsFiles(); }; @@ -376,13 +381,17 @@ // Load all -µMatrix.load = function() { +µMatrix.load = function(callback) { + if ( typeof callback !== 'function' ) { + callback = this.noopFunc; + } + var µm = this; // User settings are in memory var onUserSettingsReady = function(settings) { // Never auto-update at boot time - µm.loadUpdatableAssets(false); + µm.loadUpdatableAssets(false, callback); // Setup auto-updater, earlier if auto-upate is enabled, later if not if ( settings.autoUpdate ) {