1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-25 03:43:25 +01:00

[mv3] Set Optimal as default if extension broad permission at install time

This is to prepare uBOL to be ready to set Optimal mode as default
if ever Chromium-based browsers support a way to pre-grant broad host
permissions in a policy.

Related issue:
https://github.com/uBlockOrigin/uBOL-home/discussions/232
https://github.com/uBlockOrigin/uBOL-home/discussions/135
This commit is contained in:
Raymond Hill 2024-10-17 12:32:28 -04:00
parent 89c353640e
commit 27f3612fdf
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 15 additions and 3 deletions

View File

@ -38,6 +38,8 @@ import {
} from './ruleset-manager.js';
import {
MODE_BASIC,
MODE_OPTIMAL,
getDefaultFilteringMode,
getFilteringMode,
getTrustedSites,
@ -136,7 +138,7 @@ async function onPermissionsRemoved() {
const modified = await syncWithBrowserPermissions();
if ( modified === false ) { return false; }
const afterMode = await getDefaultFilteringMode();
if ( beforeMode > 1 && afterMode <= 1 ) {
if ( beforeMode > MODE_BASIC && afterMode <= MODE_BASIC ) {
updateDynamicRules();
}
registerInjectables();
@ -420,9 +422,19 @@ async function start() {
);
if ( firstRun ) {
const enableOptimal = await hasOmnipotence();
if ( enableOptimal ) {
const afterLevel = await setDefaultFilteringMode(MODE_OPTIMAL);
if ( afterLevel === MODE_OPTIMAL ) {
updateDynamicRules();
registerInjectables();
}
}
const disableFirstRunPage = await adminRead('disableFirstRunPage');
if ( disableFirstRunPage !== true ) {
runtime.openOptionsPage();
} else {
firstRun = false;
}
}
}

View File

@ -316,7 +316,7 @@ dom.on('#showBlockedCount input[type="checkbox"]', 'change', ev => {
function renderTrustedSites() {
const textarea = qs$('#trustedSites');
const hostnames = cachedRulesetData.trustedSites;
const hostnames = cachedRulesetData.trustedSites || [];
textarea.value = hostnames.map(hn => punycode.toUnicode(hn)).join('\n');
if ( textarea.value !== '' ) {
textarea.value += '\n';
@ -325,7 +325,7 @@ function renderTrustedSites() {
function changeTrustedSites() {
const hostnames = getStagedTrustedSites();
const hash = hashFromIterable(cachedRulesetData.trustedSites);
const hash = hashFromIterable(cachedRulesetData.trustedSites || []);
if ( hashFromIterable(hostnames) === hash ) { return; }
sendMessage({
what: 'setTrustedSites',