Browse Source

code review: simplify PSL selfie generator

pull/2/head
Raymond Hill 7 years ago
parent
commit
b963ccb778
No known key found for this signature in database GPG Key ID: 25E1490B761470C2
  1. 2
      src/js/start.js
  2. 75
      src/js/storage.js

2
src/js/start.js

@ -98,7 +98,7 @@ var onPSLReady = function() {
/******************************************************************************/
processCallbackQueue(µm.onBeforeStartQueue, function() {
µm.loadPublicSuffixList(onPSLReady);
µm.publicSuffixList.load(onPSLReady);
});
/******************************************************************************/

75
src/js/storage.js

@ -733,68 +733,47 @@
/******************************************************************************/
µMatrix.loadPublicSuffixList = function(callback) {
let µm = this;
µMatrix.publicSuffixList = (function() {
let µm = µMatrix;
if ( typeof callback !== 'function' ) {
callback = this.noopFunc;
}
var applyPublicSuffixList = function(details) {
if ( !details.error ) {
var onPSLReady = function(details, callback) {
if (
!details.error &&
typeof details.content === 'string' &&
details.content.length !== 0
) {
publicSuffixList.parse(details.content, punycode.toASCII);
µm.publicSuffixListSelfie.create();
vAPI.cacheStorage.set({
publicSuffixListSelfie: publicSuffixList.toSelfie()
});
}
callback();
};
let onSelfieReady = function(status) {
if ( status === true ) {
let onSelfieReady = function(bin, callback) {
if (
bin instanceof Object &&
bin.publicSuffixListSelfie instanceof Object &&
publicSuffixList.fromSelfie(bin.publicSuffixListSelfie)
) {
return callback();
}
µm.assets.get(µm.pslAssetKey, applyPublicSuffixList);
};
this.publicSuffixListSelfie.load(onSelfieReady);
µm.assets.get(µm.pslAssetKey, function(details) {
onPSLReady(details, callback);
});
};
/******************************************************************************/
µMatrix.publicSuffixListSelfie = (function() {
let timer;
return {
create: function() {
this.cancel();
timer = vAPI.setTimeout(
function() {
timer = undefined;
vAPI.cacheStorage.set({
publicSuffixListSelfie: publicSuffixList.toSelfie()
});
},
60000
);
},
destroy: function() {
this.cancel();
vAPI.cacheStorage.remove('publicSuffixListSelfie');
update: function(details) {
onPSLReady(details, µm.noopFunc);
},
load: function(callback) {
this.cancel();
if ( typeof callback !== 'function' ) {
callback = µm.noopFunc;
}
vAPI.cacheStorage.get('publicSuffixListSelfie', function(bin) {
callback(
bin instanceof Object &&
bin.publicSuffixListSelfie instanceof Object &&
publicSuffixList.fromSelfie(bin.publicSuffixListSelfie)
);
onSelfieReady(bin, callback);
});
},
cancel: function() {
if ( timer !== undefined ) {
clearTimeout(timer);
}
timer = undefined;
}
};
})();
@ -854,7 +833,7 @@
) {
this.hostsFilesSelfie.destroy();
} else if ( details.assetKey === this.pslAssetKey ) {
this.publicSuffixListSelfie.destroy();
this.publicSuffixList.update(details);
}
vAPI.messaging.broadcast({
what: 'assetUpdated',

Loading…
Cancel
Save