[mv3] Split code path for wakeup versus launch status

Additionally, leave more regex rooms for non-strictblock rules.
This commit is contained in:
Raymond Hill 2025-04-20 12:17:57 -04:00
parent 2bd09e6f84
commit 782fff35ea
No known key found for this signature in database
GPG key ID: 25E1490B761470C2
2 changed files with 28 additions and 24 deletions

View file

@ -436,9 +436,7 @@ function onCommand(command, tab) {
/******************************************************************************/
async function start() {
await loadRulesetConfig();
async function launch() {
const currentVersion = getCurrentVersion();
const isNewVersion = currentVersion !== rulesetConfig.version;
@ -451,39 +449,28 @@ async function start() {
saveRulesetConfig();
}
const rulesetsUpdated = process.wakeupRun === false &&
await enableRulesets(rulesetConfig.enabledRulesets);
const rulesetsUpdated = await enableRulesets(rulesetConfig.enabledRulesets);
// We need to update the regex rules only when ruleset version changes.
if ( rulesetsUpdated === false ) {
if ( isNewVersion ) {
updateDynamicRules();
} else if ( process.wakeupRun === false ) {
} else {
updateSessionRules();
}
}
// Permissions may have been removed while the extension was disabled
const permissionsChanged = process.wakeupRun === false &&
await onPermissionsRemoved();
await syncWithBrowserPermissions();
// Unsure whether the browser remembers correctly registered css/scripts
// after we quit the browser. For now uBOL will check unconditionally at
// launch time whether content css/scripts are properly registered.
if ( process.wakeupRun === false || permissionsChanged ) {
registerInjectables();
const enabledRulesets = await dnr.getEnabledRulesets();
ubolLog(`Enabled rulesets: ${enabledRulesets}`);
dnr.getAvailableStaticRuleCount().then(count => {
ubolLog(`Available static rule count: ${count}`);
});
}
registerInjectables();
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/declarativeNetRequest
// Firefox API does not support `dnr.setExtensionActionOptions`
if ( process.wakeupRun === false && canShowBlockedCount ) {
if ( canShowBlockedCount ) {
dnr.setExtensionActionOptions({
displayActionCountAsBadgeText: rulesetConfig.showBlockedCount,
});
@ -502,12 +489,20 @@ async function start() {
}
}
toggleDeveloperMode(rulesetConfig.developerMode);
// Required to ensure the up to date property is available when needed
adminReadEx('disabledFeatures');
}
/******************************************************************************/
async function start() {
await loadRulesetConfig();
if ( process.wakeupRun === false ) {
adminReadEx('disabledFeatures');
await launch();
}
toggleDeveloperMode(rulesetConfig.developerMode);
}
/******************************************************************************/

View file

@ -408,7 +408,7 @@ async function updateSessionRules() {
const currentRules = await dnr.getSessionRules();
await updateStrictBlockRules(currentRules, addRulesUnfiltered, removeRuleIds);
if ( addRulesUnfiltered.length === 0 && removeRuleIds.length === 0 ) { return; }
const maxRegexCount = dnr.MAX_NUMBER_OF_REGEX_RULES * 0.95;
const maxRegexCount = dnr.MAX_NUMBER_OF_REGEX_RULES * 0.80;
let regexCount = dynamicRegexCount;
let ruleId = 1;
for ( const rule of addRulesUnfiltered ) {
@ -595,10 +595,19 @@ async function enableRulesets(ids) {
if ( disableRulesetIds.length !== 0 ) {
ubolLog(`Disable ruleset: ${disableRulesetIds}`);
}
await dnr.updateEnabledRulesets({ enableRulesetIds, disableRulesetIds });
await dnr.updateEnabledRulesets({ enableRulesetIds, disableRulesetIds }).catch(reason => {
ubolLog(reason);
});
await updateDynamicRules();
dnr.getEnabledRulesets().then(enabledRulesets => {
ubolLog(`Enabled rulesets: ${enabledRulesets}`);
return dnr.getAvailableStaticRuleCount();
}).then(count => {
ubolLog(`Available static rule count: ${count}`);
});
return true;
}