Raymond Hill 7 years ago
parent e768b78b73
commit aba697f2f0
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

@ -48,6 +48,9 @@ vAPI.messaging.addListener(function onMessage(msg) {
case 'loadHostsFilesCompleted': case 'loadHostsFilesCompleted':
renderHostsFiles(); renderHostsFiles();
break; break;
case 'loadRecipeFilesCompleted':
renderHostsFiles();
break;
default: default:
break; break;
} }
@ -70,9 +73,7 @@ var renderHostsFiles = function(soft) {
// Assemble a pretty list name if possible // Assemble a pretty list name if possible
var listNameFromListKey = function(collection, listKey) { var listNameFromListKey = function(collection, listKey) {
let list = collection.get(listKey); let list = collection.get(listKey);
let listTitle = list ? list.title : ''; return list && list.title || listKey;
if ( listTitle === '' ) { return listKey; }
return listTitle;
}; };
var liFromListEntry = function(collection, listKey, li) { var liFromListEntry = function(collection, listKey, li) {
@ -132,13 +133,22 @@ var renderHostsFiles = function(soft) {
return li; return li;
}; };
var onRenderAssetFiles = function(collection, listSelector) { var onRenderAssetFiles = function(collection, listSelector) {
// Incremental rendering: this will allow us to easily discard unused
// DOM list entries.
uDom(listSelector + ' .listEntry:not(.notAnAsset)').addClass('discard');
var assetKeys = Array.from(collection.keys()); var assetKeys = Array.from(collection.keys());
// Sort works this way: // Sort works this way:
// - Send /^https?:/ items at the end (custom hosts file URL) // - Send /^https?:/ items at the end (custom hosts file URL)
assetKeys.sort(function(a, b) { assetKeys.sort(function(a, b) {
var ta = collection.get(a).title || a, let ea = collection.get(a),
tb = collection.get(b).title || b; eb = collection.get(b);
if ( ea.submitter !== eb.submitter ) {
return ea.submitter !== 'user' ? -1 : 1;
}
let ta = ea.title || a,
tb = eb.title || b;
if ( reExternalHostFile.test(ta) === reExternalHostFile.test(tb) ) { if ( reExternalHostFile.test(ta) === reExternalHostFile.test(tb) ) {
return ta.localeCompare(tb); return ta.localeCompare(tb);
} }
@ -178,10 +188,6 @@ var renderHostsFiles = function(soft) {
listDetails.contributor === true listDetails.contributor === true
); );
// Incremental rendering: this will allow us to easily discard unused
// DOM list entries.
uDom('#hosts .listEntry:not(.notAnAsset)').addClass('discard');
onRenderAssetFiles(details.hosts, '#hosts'); onRenderAssetFiles(details.hosts, '#hosts');
onRenderAssetFiles(details.recipes, '#recipes'); onRenderAssetFiles(details.recipes, '#recipes');

@ -273,33 +273,63 @@
} }
let µm = this, let µm = this,
countdownCount = µm.userSettings.selectedRecipeFiles.length; countdownCount = 0;
if ( reset ) { if ( reset ) {
µm.recipeManager.reset(); µm.recipeManager.reset();
} }
var onLoaded = function(details) { let recipeMetadata;
let onDone = function() {
vAPI.messaging.broadcast({ what: 'loadRecipeFilesCompleted' });
µm.getBytesInUse();
callback();
};
let onLoaded = function(details) {
if ( details.content ) { if ( details.content ) {
let entry = recipeMetadata.get(details.assetKey);
if ( entry.submitter === 'user' ) {
let match = /^! +Title: *(.+)$/im.exec(
details.content.slice(2048)
);
if ( match !== null && match[1] !== entry.title ) {
µm.assets.registerAssetSource(
details.assetKey,
{ title: match[1] }
);
}
}
µm.recipeManager.fromString(details.content); µm.recipeManager.fromString(details.content);
} }
countdownCount -= 1; countdownCount -= 1;
if ( countdownCount === 0 ) { if ( countdownCount === 0 ) {
callback(); onDone();
} }
}; };
for ( let assetKey of µm.userSettings.selectedRecipeFiles ) { let onMetadataReady = function(metadata) {
this.assets.get(assetKey, onLoaded); recipeMetadata = metadata;
} for ( let entry of metadata ) {
let assetKey = entry[0];
let userRecipes = µm.userSettings.userRecipes; let recipeFile = entry[1];
if ( userRecipes.enabled ) { if ( recipeFile.selected !== true ) { continue; }
µm.recipeManager.fromString( µm.assets.get(assetKey, onLoaded);
'! uMatrix: Ruleset recipes 1.0\n' + userRecipes.content countdownCount += 1;
); }
} let userRecipes = µm.userSettings.userRecipes;
if ( userRecipes.enabled ) {
µm.recipeManager.fromString(
'! uMatrix: Ruleset recipes 1.0\n' + userRecipes.content
);
}
if ( countdownCount === 0 ) {
onDone();
}
};
this.getAvailableRecipeFiles(onMetadataReady);
}; };
/******************************************************************************/ /******************************************************************************/
@ -406,8 +436,7 @@
type: 'recipes', type: 'recipes',
contentURL: assetKey, contentURL: assetKey,
external: true, external: true,
submitter: 'user', submitter: 'user'
title: assetKey
}; };
this.assets.registerAssetSource(assetKey, entry); this.assets.registerAssetSource(assetKey, entry);
availableRecipeFiles.set(assetKey, entry); availableRecipeFiles.set(assetKey, entry);
@ -717,9 +746,6 @@
'externalRecipeFiles', 'externalRecipeFiles',
'userRecipes' 'userRecipes'
); );
if ( recipesChanged ) {
µm.recipeManager.reset();
}
if ( typeof callback === 'function' ) { if ( typeof callback === 'function' ) {
callback({ callback({
hostsChanged: hostsChanged, hostsChanged: hostsChanged,

Loading…
Cancel
Save