From 7e894f5e0e9e2423ff67445021e725cc54bc3c1f Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 25 Apr 2023 14:01:47 -0400 Subject: [PATCH] Add time since version update in troubleshooting info --- src/js/messaging.js | 41 +++++++++++++++++++++++++++-------------- src/js/start.js | 16 ++++------------ 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/js/messaging.js b/src/js/messaging.js index b11e607d6..c97d44f17 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -1418,6 +1418,22 @@ const getSupportData = async function() { filterset.push(line); } + const now = Date.now(); + + const formatDelayFromNow = time => { + if ( (time || 0) === 0 ) { return '?'; } + const delayInSec = (now - time) / 1000; + const days = (delayInSec / 86400) | 0; + const hours = (delayInSec % 86400) / 3600 | 0; + const minutes = (delayInSec % 3600) / 60 | 0; + const parts = []; + if ( days > 0 ) { parts.push(`${days}d`); } + if ( hours > 0 ) { parts.push(`${hours}h`); } + if ( minutes > 0 ) { parts.push(`${minutes}m`); } + if ( parts.length === 0 ) { parts.push('now'); } + return parts.join('.'); + }; + const lists = µb.availableFilterLists; let defaultListset = {}; let addedListset = {}; @@ -1435,16 +1451,7 @@ const getSupportData = async function() { if ( typeof list.writeTime !== 'number' || list.writeTime === 0 ) { listDetails.push('never'); } else { - const delta = (Date.now() - list.writeTime) / 1000 | 0; - const days = (delta / 86400) | 0; - const hours = (delta % 86400) / 3600 | 0; - const minutes = (delta % 3600) / 60 | 0; - const parts = []; - if ( days > 0 ) { parts.push(`${days}d`); } - if ( hours > 0 ) { parts.push(`${hours}h`); } - if ( minutes > 0 ) { parts.push(`${minutes}m`); } - if ( parts.length === 0 ) { parts.push('now'); } - listDetails.push(parts.join('.')); + listDetails.push(formatDelayFromNow(list.writeTime)); } } if ( list.isDefault || listKey === µb.userFiltersPath ) { @@ -1462,18 +1469,22 @@ const getSupportData = async function() { } if ( Object.keys(addedListset).length === 0 ) { addedListset = undefined; - } else if ( Object.keys(addedListset).length > 15 ) { + } else { const added = Object.keys(addedListset); - const truncated = added.slice(15); + const truncated = added.slice(12); for ( const key of truncated ) { delete addedListset[key]; } - addedListset[`[${truncated.length} lists not shown]`] = '[too many]'; + if ( truncated.length !== 0 ) { + addedListset[`[${truncated.length} lists not shown]`] = '[too many]'; + } } if ( Object.keys(removedListset).length === 0 ) { removedListset = undefined; } + const { versionUpdateTime = 0 } = await vAPI.storage.get('versionUpdateTime'); + let browserFamily = (( ) => { if ( vAPI.webextFlavor.soup.has('firefox') ) { return 'Firefox'; } if ( vAPI.webextFlavor.soup.has('chromium') ) { return 'Chromium'; } @@ -1484,7 +1495,9 @@ const getSupportData = async function() { } return { - [`${vAPI.app.name}`]: `${vAPI.app.version}`, + [`${vAPI.app.name} ${vAPI.app.version}`]: { + since: formatDelayFromNow(versionUpdateTime), + }, [`${browserFamily}`]: `${vAPI.webextFlavor.major}`, 'filterset (summary)': { network: staticNetFilteringEngine.getFilterCount(), diff --git a/src/js/start.js b/src/js/start.js index 166871e2a..d18f41d6f 100644 --- a/src/js/start.js +++ b/src/js/start.js @@ -148,7 +148,10 @@ const initializeTabs = async ( ) => { const onVersionReady = lastVersion => { if ( lastVersion === vAPI.app.version ) { return; } - vAPI.storage.set({ version: vAPI.app.version }); + vAPI.storage.set({ + version: vAPI.app.version, + versionUpdateTime: Date.now(), + }); const lastVersionInt = vAPI.app.intFromVersion(lastVersion); @@ -161,17 +164,6 @@ const onVersionReady = lastVersion => { // Since built-in resources may have changed since last version, we // force a reload of all resources. redirectEngine.invalidateResourcesSelfie(io); - - // https://github.com/LiCybora/NanoDefenderFirefox/issues/196 - // Toggle on the blocking of CSP reports by default for Firefox. - if ( - lastVersionInt <= 1031003011 && - vAPI.webextFlavor.soup.has('firefox') - ) { - sessionSwitches.toggle('no-csp-reports', '*', 1); - permanentSwitches.toggle('no-csp-reports', '*', 1); - µb.saveHostnameSwitches(); - } }; /******************************************************************************/