Fix odds and ends from mega commit 9b292304d3

Related commit:
- https://github.com/gorhill/uMatrix/commit/9b292304d33a
pull/2/head
Raymond Hill 5 years ago
parent df4a403473
commit 2936d73911
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

@ -385,6 +385,7 @@ body.tabless .needtab {
justify-content: flex-end; justify-content: flex-end;
unicode-bidi: embed; unicode-bidi: embed;
width: 16em; width: 16em;
word-break: keep-all;
} }
.matrix .matGroup.g4 .matRow.ro > .matCell:first-child { .matrix .matGroup.g4 .matRow.ro > .matCell:first-child {
direction: inherit; direction: inherit;

@ -166,7 +166,7 @@ return {
} }
}, },
rawSettingsDefault: rawSettingsDefault, rawSettingsDefault,
rawSettings: (( ) => { rawSettings: (( ) => {
const out = Object.assign({}, rawSettingsDefault); const out = Object.assign({}, rawSettingsDefault);
const json = vAPI.localStorage.getItem('immediateRawSettings'); const json = vAPI.localStorage.getItem('immediateRawSettings');

@ -27,10 +27,22 @@
const µm = µMatrix; const µm = µMatrix;
await Promise.all([ await Promise.all([
µm.loadPublicSuffixList(), µm.loadRawSettings(),
µm.loadUserSettings(), µm.loadUserSettings(),
]); ]);
log.info(`PSL and user settings ready ${Date.now()-vAPI.T0} ms after launch`); log.info(`User settings ready ${Date.now()-vAPI.T0} ms after launch`);
const shouldWASM = µm.rawSettings.disableWebAssembly !== true;
if ( shouldWASM ) {
await Promise.all([
µm.HNTrieContainer.enableWASM(),
self.publicSuffixList.enableWASM(),
]);
log.info(`WASM modules ready ${Date.now()-vAPI.T0} ms after launch`);
}
await µm.loadPublicSuffixList(),
log.info(`PSL ready ${Date.now()-vAPI.T0} ms after launch`);
{ {
let trieDetails; let trieDetails;
@ -41,16 +53,17 @@
} catch(ex) { } catch(ex) {
} }
µm.ubiquitousBlacklist = new µm.HNTrieContainer(trieDetails); µm.ubiquitousBlacklist = new µm.HNTrieContainer(trieDetails);
µm.ubiquitousBlacklist.initWASM(); if ( shouldWASM ) {
µm.ubiquitousBlacklist.initWASM();
}
} }
log.info(`Ubiquitous block container ready ${Date.now()-vAPI.T0} ms after launch`); log.info(`Ubiquitous block rules container ready ${Date.now()-vAPI.T0} ms after launch`);
await Promise.all([ await Promise.all([
µm.loadRawSettings(),
µm.loadMatrix(), µm.loadMatrix(),
µm.loadHostsFiles(), µm.loadHostsFiles(),
]); ]);
log.info(`Ubiquitous block rules ready ${Date.now()-vAPI.T0} ms after launch`); log.info(`All rules ready ${Date.now()-vAPI.T0} ms after launch`);
{ {
const pageStore = const pageStore =

@ -158,7 +158,7 @@
this.rawSettings.suspendTabsUntilReady ? 'yes' : 'unset'; this.rawSettings.suspendTabsUntilReady ? 'yes' : 'unset';
} }
} }
this.fireDOMEvent('hiddenSettingsChanged'); this.fireDOMEvent('rawSettingsChanged');
}; };
// Note: Save only the settings which values differ from the default ones. // Note: Save only the settings which values differ from the default ones.
@ -175,11 +175,11 @@
bin.rawSettings[prop] = this.rawSettings[prop]; bin.rawSettings[prop] = this.rawSettings[prop];
} }
} }
vAPI.storage.set(bin);
this.saveImmediateHiddenSettings(); this.saveImmediateHiddenSettings();
return vAPI.storage.set(bin);
}; };
self.addEventListener('hiddenSettingsChanged', ( ) => { self.addEventListener('rawSettingsChanged', ( ) => {
const µm = µMatrix; const µm = µMatrix;
self.log.verbosity = µm.rawSettings.consoleLogLevel; self.log.verbosity = µm.rawSettings.consoleLogLevel;
vAPI.net.setOptions({ vAPI.net.setOptions({
@ -192,113 +192,56 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
}); });
}); });
// These settings must be available immediately on startup, without delay self.addEventListener('rawSettingsChanged', ( ) => {
// through the vAPI.localStorage. Add/remove settings as needed. const µm = µMatrix;
self.log.verbosity = µm.rawSettings.consoleLogLevel;
µMatrix.saveImmediateHiddenSettings = function() { vAPI.net.setOptions({
const props = [ cnameIgnoreList: µm.rawSettings.cnameIgnoreList,
'consoleLogLevel', cnameIgnore1stParty: µm.rawSettings.cnameIgnore1stParty,
'disableWebAssembly', cnameIgnoreExceptions: µm.rawSettings.cnameIgnoreExceptions,
'suspendTabsUntilReady', cnameIgnoreRootDocument: µm.rawSettings.cnameIgnoreRootDocument,
]; cnameMaxTTL: µm.rawSettings.cnameMaxTTL,
const toSave = {}; cnameReplayFullURL: µm.rawSettings.cnameReplayFullURL,
for ( const prop of props ) { });
if ( this.rawSettings[prop] !== this.rawSettingsDefault[prop] ) { });
toSave[prop] = this.rawSettings[prop];
}
}
if ( Object.keys(toSave).length !== 0 ) {
vAPI.localStorage.setItem(
'immediateHiddenSettings',
JSON.stringify(toSave)
);
} else {
vAPI.localStorage.removeItem('immediateHiddenSettings');
}
};
µMatrix.loadRawSettings = async function() {
const bin = await vAPI.storage.get('rawSettings');
if (
bin instanceof Object === false ||
bin.rawSettings instanceof Object === false
) {
return;
}
for ( const key of Object.keys(bin.rawSettings) ) {
if (
this.rawSettings.hasOwnProperty(key) === false ||
typeof bin.rawSettings[key] !== typeof this.rawSettings[key]
) {
continue;
}
this.rawSettings[key] = bin.rawSettings[key];
}
this.rawSettingsWriteTime = Date.now();
};
µMatrix.saveRawSettings = async function(rawSettings) {
const keys = Object.keys(rawSettings);
if ( keys.length === 0 ) { return; }
for ( const key of keys ) {
if (
this.rawSettingsDefault.hasOwnProperty(key) &&
typeof rawSettings[key] === typeof this.rawSettingsDefault[key]
) {
this.rawSettings[key] = rawSettings[key];
}
}
this.saveImmediateHiddenSettings();
this.rawSettingsWriteTime = Date.now();
await vAPI.storage.set({ rawSettings: this.rawSettings }); /******************************************************************************/
};
µMatrix.rawSettingsFromString = function(raw) { µMatrix.rawSettingsFromString = function(raw) {
const result = {}; const out = Object.assign({}, this.rawSettingsDefault);
const lineIter = new this.LineIterator(raw); const lineIter = new this.LineIterator(raw);
while ( lineIter.eot() === false ) { while ( lineIter.eot() === false ) {
const line = lineIter.next().trim(); const line = lineIter.next();
const matches = /^(\S+)(\s+(.+))?$/.exec(line); const matches = /^\s*(\S+)\s+(.+)$/.exec(line);
if ( matches === null ) { continue; } if ( matches === null || matches.length !== 3 ) { continue; }
const name = matches[1]; const name = matches[1];
if ( this.rawSettingsDefault.hasOwnProperty(name) === false ) { if ( out.hasOwnProperty(name) === false ) { continue; }
continue; const value = matches[2].trim();
} switch ( typeof out[name] ) {
let value = (matches[2] || '').trim();
switch ( typeof this.rawSettingsDefault[name] ) {
case 'boolean': case 'boolean':
if ( value === 'true' ) { if ( value === 'true' ) {
value = true; out[name] = true;
} else if ( value === 'false' ) { } else if ( value === 'false' ) {
value = false; out[name] = false;
} else {
value = this.rawSettingsDefault[name];
} }
break; break;
case 'string': case 'string':
if ( value === '' ) { out[name] = value;
value = this.rawSettingsDefault[name];
}
break; break;
case 'number': case 'number': {
value = parseInt(value, 10); const i = parseInt(value, 10);
if ( isNaN(value) ) { if ( isNaN(i) === false ) {
value = this.rawSettingsDefault[name]; out[name] = i;
} }
break; break;
}
default: default:
break; break;
} }
if ( this.rawSettings[name] !== value ) {
result[name] = value;
}
} }
this.saveRawSettings(result); this.rawSettings = out;
this.saveRawSettings();
this.fireDOMEvent('rawSettingsChanged');
}; };
µMatrix.stringFromRawSettings = function() { µMatrix.stringFromRawSettings = function() {
@ -309,16 +252,30 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
return out.join('\n'); return out.join('\n');
}; };
/******************************************************************************/
// These settings must be available immediately on startup, without delay // These settings must be available immediately on startup, without delay
// through the vAPI.localStorage. Add/remove settings as needed. // through the vAPI.localStorage. Add/remove settings as needed.
µMatrix.saveImmediateHiddenSettings = function() { µMatrix.saveImmediateHiddenSettings = function() {
vAPI.localStorage.setItem( const props = [
'immediateRawSettings', 'consoleLogLevel',
JSON.stringify({ 'suspendTabsUntilReady',
suspendTabsUntilReady: this.rawSettings.suspendTabsUntilReady, ];
}) const toSave = {};
); for ( const prop of props ) {
if ( this.rawSettings[prop] !== this.rawSettingsDefault[prop] ) {
toSave[prop] = this.rawSettings[prop];
}
}
if ( Object.keys(toSave).length !== 0 ) {
vAPI.localStorage.setItem(
'immediateHiddenSettings',
JSON.stringify(toSave)
);
} else {
vAPI.localStorage.removeItem('immediateHiddenSettings');
}
}; };
/******************************************************************************/ /******************************************************************************/
@ -816,6 +773,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
); );
µm.ubiquitousBlacklistRef = µm.ubiquitousBlacklistRef =
µm.ubiquitousBlacklist.createOne(bin.hostsFilesSelfie.trieref); µm.ubiquitousBlacklist.createOne(bin.hostsFilesSelfie.trieref);
return true;
}, },
cancel: function() { cancel: function() {
if ( timer !== undefined ) { if ( timer !== undefined ) {
@ -832,10 +790,6 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
// TODO: remove once all users are way past 1.4.0. // TODO: remove once all users are way past 1.4.0.
this.cacheStorage.remove('publicSuffixListSelfie'); this.cacheStorage.remove('publicSuffixListSelfie');
if ( this.rawSettings.disableWebAssembly === false ) {
publicSuffixList.enableWASM();
}
try { try {
const result = await this.assets.get(`compiled/${this.pslAssetKey}`); const result = await this.assets.get(`compiled/${this.pslAssetKey}`);
if ( publicSuffixList.fromSelfie(result.content, this.base64) ) { if ( publicSuffixList.fromSelfie(result.content, this.base64) ) {

@ -227,3 +227,15 @@
})(); })();
/******************************************************************************/ /******************************************************************************/
µMatrix.fireDOMEvent = function(name) {
if (
window instanceof Object &&
window.dispatchEvent instanceof Function &&
window.CustomEvent instanceof Function
) {
window.dispatchEvent(new CustomEvent(name));
}
};
/******************************************************************************/

@ -72,7 +72,7 @@
<li id="mtxSwitch_no-workers" class="dropdown-menu-entry exists"><!-- <svg><use xlink:href="#toggleButton" /></svg> --><svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 152 96"><g><ellipse cx="48" cy="48" rx="24" ry="24" /><ellipse cx="104" cy="48" rx="24" ry="24" /><rect width="56" height="48" x="48" y="24" /></g><g class="off"><ellipse cx="48" cy="48" rx="48" ry="48" /><ellipse style="fill:#fff;" cx="48" cy="48" rx="40" ry="40" /><ellipse class="dot" cx="48" cy="48" rx="12" ry="12" /></g><g class="on"><ellipse style="fill:#444;" cx="104" cy="48" rx="48" ry="48" /><ellipse class="dot" cx="104" cy="48" rx="12" ry="12" /></g></svg><span data-i18n="matrixSwitchNoWorker"></span>&emsp;<a class="fa-icon" href="https://developer.mozilla.org/docs/Web/API/Web_Workers_API" target="_blank">info-circle</a> <li id="mtxSwitch_no-workers" class="dropdown-menu-entry exists"><!-- <svg><use xlink:href="#toggleButton" /></svg> --><svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 152 96"><g><ellipse cx="48" cy="48" rx="24" ry="24" /><ellipse cx="104" cy="48" rx="24" ry="24" /><rect width="56" height="48" x="48" y="24" /></g><g class="off"><ellipse cx="48" cy="48" rx="48" ry="48" /><ellipse style="fill:#fff;" cx="48" cy="48" rx="40" ry="40" /><ellipse class="dot" cx="48" cy="48" rx="12" ry="12" /></g><g class="on"><ellipse style="fill:#444;" cx="104" cy="48" rx="48" ry="48" /><ellipse class="dot" cx="104" cy="48" rx="12" ry="12" /></g></svg><span data-i18n="matrixSwitchNoWorker"></span>&emsp;<a class="fa-icon" href="https://developer.mozilla.org/docs/Web/API/Web_Workers_API" target="_blank">info-circle</a>
<li id="mtxSwitch_referrer-spoof" class="dropdown-menu-entry"><!-- <svg><use xlink:href="#toggleButton" /></svg> --><svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 152 96"><g><ellipse cx="48" cy="48" rx="24" ry="24" /><ellipse cx="104" cy="48" rx="24" ry="24" /><rect width="56" height="48" x="48" y="24" /></g><g class="off"><ellipse cx="48" cy="48" rx="48" ry="48" /><ellipse style="fill:#fff;" cx="48" cy="48" rx="40" ry="40" /><ellipse class="dot" cx="48" cy="48" rx="12" ry="12" /></g><g class="on"><ellipse style="fill:#444;" cx="104" cy="48" rx="48" ry="48" /><ellipse class="dot" cx="104" cy="48" rx="12" ry="12" /></g></svg><span data-i18n="matrixSwitchReferrerSpoof"></span>&emsp;<a class="fa-icon" href="https://developer.mozilla.org/docs/Web/HTTP/Headers/Referer" target="_blank">info-circle</a> <li id="mtxSwitch_referrer-spoof" class="dropdown-menu-entry"><!-- <svg><use xlink:href="#toggleButton" /></svg> --><svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 152 96"><g><ellipse cx="48" cy="48" rx="24" ry="24" /><ellipse cx="104" cy="48" rx="24" ry="24" /><rect width="56" height="48" x="48" y="24" /></g><g class="off"><ellipse cx="48" cy="48" rx="48" ry="48" /><ellipse style="fill:#fff;" cx="48" cy="48" rx="40" ry="40" /><ellipse class="dot" cx="48" cy="48" rx="12" ry="12" /></g><g class="on"><ellipse style="fill:#444;" cx="104" cy="48" rx="48" ry="48" /><ellipse class="dot" cx="104" cy="48" rx="12" ry="12" /></g></svg><span data-i18n="matrixSwitchReferrerSpoof"></span>&emsp;<a class="fa-icon" href="https://developer.mozilla.org/docs/Web/HTTP/Headers/Referer" target="_blank">info-circle</a>
<li id="mtxSwitch_noscript-spoof" class="dropdown-menu-entry"><!-- <svg><use xlink:href="#toggleButton" /></svg> --><svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 152 96"><g><ellipse cx="48" cy="48" rx="24" ry="24" /><ellipse cx="104" cy="48" rx="24" ry="24" /><rect width="56" height="48" x="48" y="24" /></g><g class="off"><ellipse cx="48" cy="48" rx="48" ry="48" /><ellipse style="fill:#fff;" cx="48" cy="48" rx="40" ry="40" /><ellipse class="dot" cx="48" cy="48" rx="12" ry="12" /></g><g class="on"><ellipse style="fill:#444;" cx="104" cy="48" rx="48" ry="48" /><ellipse class="dot" cx="104" cy="48" rx="12" ry="12" /></g></svg><span data-i18n="matrixSwitchNoscriptSpoof"></span>&emsp;<a class="fa-icon" href="https://developer.mozilla.org/docs/Web/HTML/Element/noscript" target="_blank">info-circle</a> <li id="mtxSwitch_noscript-spoof" class="dropdown-menu-entry"><!-- <svg><use xlink:href="#toggleButton" /></svg> --><svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 152 96"><g><ellipse cx="48" cy="48" rx="24" ry="24" /><ellipse cx="104" cy="48" rx="24" ry="24" /><rect width="56" height="48" x="48" y="24" /></g><g class="off"><ellipse cx="48" cy="48" rx="48" ry="48" /><ellipse style="fill:#fff;" cx="48" cy="48" rx="40" ry="40" /><ellipse class="dot" cx="48" cy="48" rx="12" ry="12" /></g><g class="on"><ellipse style="fill:#444;" cx="104" cy="48" rx="48" ry="48" /><ellipse class="dot" cx="104" cy="48" rx="12" ry="12" /></g></svg><span data-i18n="matrixSwitchNoscriptSpoof"></span>&emsp;<a class="fa-icon" href="https://developer.mozilla.org/docs/Web/HTML/Element/noscript" target="_blank">info-circle</a>
<li id="mtxSwitch_cname-reveal" class="dropdown-menu-entry"><!-- <svg><use xlink:href="#toggleButton" /></svg> --><svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 152 96"><g><ellipse cx="48" cy="48" rx="24" ry="24" /><ellipse cx="104" cy="48" rx="24" ry="24" /><rect width="56" height="48" x="48" y="24" /></g><g class="off"><ellipse cx="48" cy="48" rx="48" ry="48" /><ellipse style="fill:#fff;" cx="48" cy="48" rx="40" ry="40" /><ellipse class="dot" cx="48" cy="48" rx="12" ry="12" /></g><g class="on"><ellipse style="fill:#444;" cx="104" cy="48" rx="48" ry="48" /><ellipse class="dot" cx="104" cy="48" rx="12" ry="12" /></g></svg><span data-i18n="matrixSwitchRevealCname"></span>&emsp;<a class="fa-icon" href="https://en.wikipedia.org/wiki/CNAME_record" target="_blank">info-circle</a> <li id="mtxSwitch_cname-reveal" class="dropdown-menu-entry"><!-- <svg><use xlink:href="#toggleButton" /></svg> --><svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 152 96"><g><ellipse cx="48" cy="48" rx="24" ry="24" /><ellipse cx="104" cy="48" rx="24" ry="24" /><rect width="56" height="48" x="48" y="24" /></g><g class="off"><ellipse cx="48" cy="48" rx="48" ry="48" /><ellipse style="fill:#fff;" cx="48" cy="48" rx="40" ry="40" /><ellipse class="dot" cx="48" cy="48" rx="12" ry="12" /></g><g class="on"><ellipse style="fill:#444;" cx="104" cy="48" rx="48" ry="48" /><ellipse class="dot" cx="104" cy="48" rx="12" ry="12" /></g></svg><span data-i18n="matrixSwitchRevealCname"></span>&emsp;<a class="fa-icon" href="https://wikipedia.org/wiki/CNAME_record" target="_blank">info-circle</a>
</ul> </ul>
</div> </div>
</div> </div>

Loading…
Cancel
Save