diff --git a/src/js/3p-filters.js b/src/js/3p-filters.js index 94c35d35c..f34caaa65 100644 --- a/src/js/3p-filters.js +++ b/src/js/3p-filters.js @@ -299,6 +299,10 @@ const renderFilterLists = function(soft) { if ( !soft ) { filteringSettingsHash = hashFromCurrentFromSettings(); } + + // https://github.com/gorhill/uBlock/issues/2394 + document.body.classList.toggle('updating', listDetails.isUpdating); + renderWidgets(); }; diff --git a/src/js/assets.js b/src/js/assets.js index 286a43200..6d2596a5b 100644 --- a/src/js/assets.js +++ b/src/js/assets.js @@ -916,15 +916,16 @@ api.rmrf = function() { /******************************************************************************/ // Asset updater area. -var updaterStatus, +const updaterAssetDelayDefault = 120000; +const updaterUpdated = []; +const updaterFetched = new Set(); + +let updaterStatus, updaterTimer, - updaterAssetDelayDefault = 120000, updaterAssetDelay = updaterAssetDelayDefault, - updaterUpdated = [], - updaterFetched = new Set(), noRemoteResources; -var updateFirst = function() { +const updateFirst = function() { // https://github.com/gorhill/uBlock/commit/126110c9a0a0630cd556f5cb215422296a961029 // Firefox extension reviewers do not want uBO/webext to fetch its own // scriptlets/resources asset from the project's own repo (github.com). @@ -939,31 +940,33 @@ var updateFirst = function() { } updaterStatus = 'updating'; updaterFetched.clear(); - updaterUpdated = []; + updaterUpdated.length = 0; fireNotification('before-assets-updated'); updateNext(); }; -var updateNext = function() { - var assetDict, cacheDict; +const updateNext = function() { + let assetDict, cacheDict; // This will remove a cached asset when it's no longer in use. - var garbageCollectOne = function(assetKey) { - var cacheEntry = cacheDict[assetKey]; + const garbageCollectOne = function(assetKey) { + const cacheEntry = cacheDict[assetKey]; if ( cacheEntry && cacheEntry.readTime < assetCacheRegistryStartTime ) { assetCacheRemove(assetKey); } }; - var findOne = function() { - var now = Date.now(), - assetEntry, cacheEntry; - for ( var assetKey in assetDict ) { - assetEntry = assetDict[assetKey]; + const findOne = function() { + const now = Date.now(); + for ( const assetKey in assetDict ) { + const assetEntry = assetDict[assetKey]; if ( assetEntry.hasRemoteURL !== true ) { continue; } if ( updaterFetched.has(assetKey) ) { continue; } - cacheEntry = cacheDict[assetKey]; - if ( cacheEntry && (cacheEntry.writeTime + assetEntry.updateAfter * 86400000) > now ) { + const cacheEntry = cacheDict[assetKey]; + if ( + cacheEntry && + (cacheEntry.writeTime + assetEntry.updateAfter * 86400000) > now + ) { continue; } // Update of user scripts/resources forbidden? @@ -982,7 +985,7 @@ var updateNext = function() { } }; - var updatedOne = function(details) { + const updatedOne = function(details) { if ( details.content !== '' ) { updaterUpdated.push(details.assetKey); if ( details.assetKey === 'assets.json' ) { @@ -998,8 +1001,8 @@ var updateNext = function() { } }; - var updateOne = function() { - var assetKey = findOne(); + const updateOne = function() { + const assetKey = findOne(); if ( assetKey === undefined ) { return updateDone(); } @@ -1020,20 +1023,20 @@ var updateNext = function() { }); }; -var updateDone = function() { - var assetKeys = updaterUpdated.slice(0); +const updateDone = function() { + const assetKeys = updaterUpdated.slice(0); updaterFetched.clear(); - updaterUpdated = []; + updaterUpdated.length = 0; updaterStatus = undefined; updaterAssetDelay = updaterAssetDelayDefault; fireNotification('after-assets-updated', { assetKeys: assetKeys }); }; api.updateStart = function(details) { - var oldUpdateDelay = updaterAssetDelay, - newUpdateDelay = typeof details.delay === 'number' ? - details.delay : - updaterAssetDelayDefault; + const oldUpdateDelay = updaterAssetDelay; + const newUpdateDelay = typeof details.delay === 'number' ? + details.delay : + updaterAssetDelayDefault; updaterAssetDelay = Math.min(oldUpdateDelay, newUpdateDelay); if ( updaterStatus !== undefined ) { if ( newUpdateDelay < oldUpdateDelay ) { @@ -1055,6 +1058,11 @@ api.updateStop = function() { } }; +api.isUpdating = function() { + return updaterStatus === 'updating' && + updaterAssetDelay <= µBlock.hiddenSettings.manualUpdateAssetFetchPeriod; +}; + /******************************************************************************/ return api; diff --git a/src/js/background.js b/src/js/background.js index 16db9c72d..9d43f78eb 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -40,6 +40,7 @@ const µBlock = (function() { // jshint ignore:line assetFetchTimeout: 30, autoCommentFilterTemplate: '{{date}} {{origin}}', autoUpdateAssetFetchPeriod: 120, + autoUpdateDelayAfterLaunch: 180, autoUpdatePeriod: 7, cacheStorageAPI: 'unset', cacheStorageCompression: true, diff --git a/src/js/messaging.js b/src/js/messaging.js index 26ffe8973..512690ff5 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -862,24 +862,23 @@ const resetUserData = function() { // 3rd-party filters -var prepListEntries = function(entries) { - var µburi = µb.URI; - var entry, hn; - for ( var k in entries ) { +const prepListEntries = function(entries) { + const µburi = µb.URI; + for ( const k in entries ) { if ( entries.hasOwnProperty(k) === false ) { continue; } - entry = entries[k]; + const entry = entries[k]; if ( typeof entry.supportURL === 'string' && entry.supportURL !== '' ) { entry.supportName = µburi.hostnameFromURI(entry.supportURL); } else if ( typeof entry.homeURL === 'string' && entry.homeURL !== '' ) { - hn = µburi.hostnameFromURI(entry.homeURL); - entry.supportURL = 'http://' + hn + '/'; + const hn = µburi.hostnameFromURI(entry.homeURL); + entry.supportURL = `http://${hn}/`; entry.supportName = µburi.domainFromHostname(hn); } } }; -var getLists = function(callback) { - var r = { +const getLists = function(callback) { + const r = { autoUpdate: µb.userSettings.autoUpdate, available: null, cache: null, @@ -887,16 +886,17 @@ var getLists = function(callback) { current: µb.availableFilterLists, externalLists: µb.userSettings.externalLists, ignoreGenericCosmeticFilters: µb.userSettings.ignoreGenericCosmeticFilters, + isUpdating: µb.assets.isUpdating(), netFilterCount: µb.staticNetFilteringEngine.getFilterCount(), parseCosmeticFilters: µb.userSettings.parseAllABPHideFilters, userFiltersPath: µb.userFiltersPath }; - var onMetadataReady = function(entries) { + const onMetadataReady = function(entries) { r.cache = entries; prepListEntries(r.cache); callback(r); }; - var onLists = function(lists) { + const onLists = function(lists) { r.available = lists; prepListEntries(r.available); µb.assets.metadata(onMetadataReady); @@ -908,7 +908,7 @@ var getLists = function(callback) { // My rules -var getRules = function() { +const getRules = function() { return { permanentRules: µb.permanentFirewall.toArray().concat( @@ -923,7 +923,7 @@ var getRules = function() { }; }; -var modifyRuleset = function(details) { +const modifyRuleset = function(details) { let swRuleset, hnRuleset, urlRuleset; if ( details.permanent ) { swRuleset = µb.permanentSwitches; @@ -974,7 +974,7 @@ var modifyRuleset = function(details) { // Shortcuts pane -let getShortcuts = function(callback) { +const getShortcuts = function(callback) { if ( µb.canUseShortcuts === false ) { return callback([]); } @@ -995,7 +995,7 @@ let getShortcuts = function(callback) { }); }; -let setShortcut = function(details) { +const setShortcut = function(details) { if ( µb.canUpdateShortcuts === false ) { return; } if ( details.shortcut === undefined ) { vAPI.commands.reset(details.name); @@ -1009,7 +1009,7 @@ let setShortcut = function(details) { /******************************************************************************/ -var onMessage = function(request, sender, callback) { +const onMessage = function(request, sender, callback) { // Async switch ( request.what ) { case 'backupUserData': diff --git a/src/js/start.js b/src/js/start.js index f9abf5565..80828c10f 100644 --- a/src/js/start.js +++ b/src/js/start.js @@ -65,9 +65,13 @@ var onAllReady = function() { initializeTabs(); // https://github.com/chrisaljoudi/uBlock/issues/184 - // Check for updates not too far in the future. + // Check for updates not too far in the future. µb.assets.addObserver(µb.assetObserver.bind(µb)); - µb.scheduleAssetUpdater(µb.userSettings.autoUpdate ? 5 * 60 * 1000 : 0); + µb.scheduleAssetUpdater( + µb.userSettings.autoUpdate + ? µb.hiddenSettings.autoUpdateDelayAfterLaunch * 1000 + : 0 + ); // vAPI.cloud is optional. if ( µb.cloudStorageSupported ) {