mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-11 17:41:03 +01:00
Ensure the "Filter lists" pane is in sync with update status
Related issue: - https://github.com/gorhill/uBlock/issues/2394 Additionally, I added a new advanced setting to control how long after launch an auto-update session should be started -- value is in seconds: autoUpdateDelayAfterLaunch 180
This commit is contained in:
parent
a0ac1b7ee8
commit
72d9758faa
5 changed files with 62 additions and 45 deletions
|
@ -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();
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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':
|
||||
|
|
|
@ -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 ) {
|
||||
|
|
Loading…
Reference in a new issue