Skip to content

Commit

Permalink
Support pane: mark lists as obsolete only when update button is clicked
Browse files Browse the repository at this point in the history
Lists older than 2 hours were unconditionally marked as obsolete when
opening the _Support_ pane. Those lists will now be marked as obsolete
only when the _Update now_ button in the _Support_ pane is pressed, i.e.
when launching an update cycle.

Related discussion:
uBlockOrigin/uBlock-discussions#781 (comment)
  • Loading branch information
gorhill committed Oct 16, 2023
1 parent b1530e2 commit bee64eb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/css/support.css
Expand Up @@ -54,12 +54,12 @@ body.filterIssue #moreButton {
display: none;
}

body.shouldUpdate:not(.updated) .e .createEntry {
body[data-should-update-lists]:not(.updated) .e .createEntry {
opacity: 0.25;
pointer-events: none;
}

body:not(.shouldUpdate) .shouldUpdate {
body:not([data-should-update-lists]) .shouldUpdate {
display: none;
}
body.updating {
Expand Down
9 changes: 4 additions & 5 deletions src/js/messaging.js
Expand Up @@ -602,11 +602,10 @@ const launchReporter = async function(request) {
const entries = await io.getUpdateAges({
filters: µb.selectedFilterLists.slice()
});
let shouldUpdateLists = false;
const shouldUpdateLists = [];
for ( const entry of entries ) {
if ( entry.age < (2 * 60 * 60 * 1000) ) { continue; }
io.purge(entry.assetKey);
shouldUpdateLists = true;
shouldUpdateLists.push(entry.assetKey);
}

// https://github.com/gorhill/uBlock/commit/6efd8eb#commitcomment-107523558
Expand Down Expand Up @@ -634,8 +633,8 @@ const launchReporter = async function(request) {
const supportURL = new URL(vAPI.getURL('support.html'));
supportURL.searchParams.set('pageURL', request.pageURL);
supportURL.searchParams.set('popupPanel', JSON.stringify(request.popupPanel));
if ( shouldUpdateLists ) {
supportURL.searchParams.set('shouldUpdate', 1);
if ( shouldUpdateLists.length ) {
supportURL.searchParams.set('shouldUpdateLists', JSON.stringify(shouldUpdateLists));
}
return supportURL.href;
};
Expand Down
13 changes: 9 additions & 4 deletions src/js/support.js
Expand Up @@ -210,8 +210,9 @@ const reportedPage = (( ) => {
dom.text(option, parsedURL.href);
select.append(option);
}
if ( url.searchParams.get('shouldUpdate') !== null ) {
dom.cl.add(dom.body, 'shouldUpdate');
const shouldUpdateLists = url.searchParams.get('shouldUpdateLists');
if ( shouldUpdateLists !== null ) {
dom.body.dataset.shouldUpdateLists = shouldUpdateLists;
}
dom.cl.add(dom.body, 'filterIssue');
return {
Expand Down Expand Up @@ -250,8 +251,12 @@ function reportSpecificFilterIssue() {
}

async function updateFilterLists() {
if ( dom.body.dataset.shouldUpdateLists === undefined ) { return false; }
dom.cl.add(dom.body, 'updating');
const assetKeys = JSON.parse(dom.body.dataset.shouldUpdateLists);
vAPI.messaging.send('dashboard', { what: 'purgeCaches', assetKeys });
vAPI.messaging.send('dashboard', { what: 'forceUpdateAssets' });
return true;
}

/******************************************************************************/
Expand Down Expand Up @@ -281,9 +286,9 @@ uBlockDashboard.patchCodeMirrorEditor(cmEditor);
});

if ( reportedPage !== null ) {
if ( dom.cl.has(dom.body, 'shouldUpdate') ) {
if ( dom.body.dataset.shouldUpdateLists ) {
dom.on('.supportEntry.shouldUpdate button', 'click', ev => {
updateFilterLists();
if ( updateFilterLists() === false ) { return; }
ev.preventDefault();
});
}
Expand Down

0 comments on commit bee64eb

Please sign in to comment.