Add time since version update in troubleshooting info

This commit is contained in:
Raymond Hill 2023-04-25 14:01:47 -04:00
parent 5e174c6cb5
commit 7e894f5e0e
No known key found for this signature in database
GPG key ID: 25E1490B761470C2
2 changed files with 31 additions and 26 deletions

View file

@ -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(),

View file

@ -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();
}
};
/******************************************************************************/