[mv3] Fine tune various portions of code

This commit is contained in:
Raymond Hill 2023-06-06 13:42:22 -04:00
parent f282b43550
commit 1ad7410077
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
5 changed files with 28 additions and 29 deletions

View File

@ -59,6 +59,7 @@ iframe {
border: 0;
flex-grow: 1;
margin: 0;
min-height: 800px;
padding: 0;
}
#unsavedWarning {

View File

@ -65,11 +65,12 @@ const rulesetConfig = {
version: '',
enabledRulesets: [ 'default' ],
autoReload: 1,
firstRun: false,
};
const UBOL_ORIGIN = runtime.getURL('').replace(/\/$/, '');
let firstRun = false;
/******************************************************************************/
function getCurrentVersion() {
@ -82,26 +83,26 @@ async function loadRulesetConfig() {
rulesetConfig.version = data.version;
rulesetConfig.enabledRulesets = data.enabledRulesets;
rulesetConfig.autoReload = data.autoReload;
return;
return false;
}
data = await localRead('rulesetConfig');
if ( data ) {
rulesetConfig.version = data.version;
rulesetConfig.enabledRulesets = data.enabledRulesets;
rulesetConfig.autoReload = data.autoReload;
return;
return false;
}
data = await loadRulesetConfig.convertLegacyStorage();
if ( data ) {
rulesetConfig.version = data.version;
rulesetConfig.enabledRulesets = data.enabledRulesets;
rulesetConfig.autoReload = data.autoReload;
return;
return false;
}
rulesetConfig.enabledRulesets = await defaultRulesetsFromLanguage();
rulesetConfig.firstRun = true;
sessionWrite('rulesetConfig', rulesetConfig);
localWrite('rulesetConfig', rulesetConfig);
return true;
}
// TODO: To remove after next stable release is widespread (2023-06-04)
@ -221,9 +222,9 @@ function onMessage(request, sender, callback) {
enabledRulesets,
rulesetDetails: Array.from(rulesetDetails.values()),
autoReload: rulesetConfig.autoReload === 1,
firstRun: rulesetConfig.firstRun,
firstRun,
});
rulesetConfig.firstRun = false;
firstRun = false;
});
return true;
}
@ -297,7 +298,7 @@ function onMessage(request, sender, callback) {
/******************************************************************************/
async function start() {
await loadRulesetConfig();
firstRun = await loadRulesetConfig();
await enableRulesets(rulesetConfig.enabledRulesets);
// We need to update the regex rules only when ruleset version changes.
@ -330,10 +331,6 @@ async function start() {
if ( dnr.setExtensionActionOptions ) {
dnr.setExtensionActionOptions({ displayActionCountAsBadgeText: true });
}
}
(async ( ) => {
await start();
runtime.onMessage.addListener(onMessage);
@ -341,7 +338,9 @@ async function start() {
( ) => { onPermissionsRemoved(); }
);
if ( rulesetConfig.firstRun ) {
if ( firstRun ) {
runtime.openOptionsPage();
}
})();
}
start();

View File

@ -100,6 +100,9 @@ async function getActualFilteringModeDetails() {
};
}
}
if ( details ) {
sessionWrite('filteringModeDetails', details);
}
}
const out = {
none: new Set(details.none),

View File

@ -46,19 +46,17 @@ const CURRENT_CONFIG_BASE_RULE_ID = 9000000;
/******************************************************************************/
let rulesetDetailsPromise;
function getRulesetDetails() {
if ( rulesetDetailsPromise !== undefined ) {
return rulesetDetailsPromise;
if ( getRulesetDetails.rulesetDetailsPromise !== undefined ) {
return getRulesetDetails.rulesetDetailsPromise;
}
rulesetDetailsPromise = fetchJSON('/rulesets/ruleset-details').then(entries => {
const map = new Map(
getRulesetDetails.rulesetDetailsPromise = fetchJSON('/rulesets/ruleset-details').then(entries => {
const rulesMap = new Map(
entries.map(entry => [ entry.id, entry ])
);
return map;
return rulesMap;
});
return rulesetDetailsPromise;
return getRulesetDetails.rulesetDetailsPromise;
}
/******************************************************************************/
@ -68,12 +66,10 @@ function getDynamicRules() {
return getDynamicRules.dynamicRuleMapPromise;
}
getDynamicRules.dynamicRuleMapPromise = dnr.getDynamicRules().then(rules => {
const map = new Map(
rules.map(rule => [ rule.id, rule ])
);
ubolLog(`Dynamic rule count: ${map.size}`);
ubolLog(`Available dynamic rule count: ${dnr.MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES - map.size}`);
return map;
const rulesMap = new Map(rules.map(rule => [ rule.id, rule ]));
ubolLog(`Dynamic rule count: ${rulesMap.size}`);
ubolLog(`Available dynamic rule count: ${dnr.MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES - rulesMap.size}`);
return rulesMap;
});
return getDynamicRules.dynamicRuleMapPromise;
}

View File

@ -126,7 +126,7 @@ const hostnamesFromMatches = origins => {
const ubolLog = (...args) => {
// Do not pollute dev console in stable release.
if ( browser.runtime.id === 'ddkjiahejlhfcafbddmgiahcphecmpfh' ) { return; }
console.info(...args);
console.info('[uBOL]', ...args);
};
/******************************************************************************/