|
273 | 273 | } |
274 | 274 |
|
275 | 275 | let µm = this, |
276 | | - countdownCount = µm.userSettings.selectedRecipeFiles.length; |
| 276 | + countdownCount = 0; |
277 | 277 |
|
278 | 278 | if ( reset ) { |
279 | 279 | µm.recipeManager.reset(); |
280 | 280 | } |
281 | 281 |
|
282 | | - var onLoaded = function(details) { |
| 282 | + let recipeMetadata; |
| 283 | + |
| 284 | + let onDone = function() { |
| 285 | + vAPI.messaging.broadcast({ what: 'loadRecipeFilesCompleted' }); |
| 286 | + µm.getBytesInUse(); |
| 287 | + callback(); |
| 288 | + }; |
| 289 | + |
| 290 | + let onLoaded = function(details) { |
283 | 291 | if ( details.content ) { |
| 292 | + let entry = recipeMetadata.get(details.assetKey); |
| 293 | + if ( entry.submitter === 'user' ) { |
| 294 | + let match = /^! +Title: *(.+)$/im.exec( |
| 295 | + details.content.slice(2048) |
| 296 | + ); |
| 297 | + if ( match !== null && match[1] !== entry.title ) { |
| 298 | + µm.assets.registerAssetSource( |
| 299 | + details.assetKey, |
| 300 | + { title: match[1] } |
| 301 | + ); |
| 302 | + } |
| 303 | + } |
284 | 304 | µm.recipeManager.fromString(details.content); |
285 | 305 | } |
286 | 306 | countdownCount -= 1; |
287 | 307 | if ( countdownCount === 0 ) { |
288 | | - callback(); |
| 308 | + onDone(); |
289 | 309 | } |
290 | 310 | }; |
291 | 311 |
|
292 | | - for ( let assetKey of µm.userSettings.selectedRecipeFiles ) { |
293 | | - this.assets.get(assetKey, onLoaded); |
294 | | - } |
295 | | - |
296 | | - let userRecipes = µm.userSettings.userRecipes; |
297 | | - if ( userRecipes.enabled ) { |
298 | | - µm.recipeManager.fromString( |
299 | | - '! uMatrix: Ruleset recipes 1.0\n' + userRecipes.content |
300 | | - ); |
301 | | - } |
| 312 | + let onMetadataReady = function(metadata) { |
| 313 | + recipeMetadata = metadata; |
| 314 | + for ( let entry of metadata ) { |
| 315 | + let assetKey = entry[0]; |
| 316 | + let recipeFile = entry[1]; |
| 317 | + if ( recipeFile.selected !== true ) { continue; } |
| 318 | + µm.assets.get(assetKey, onLoaded); |
| 319 | + countdownCount += 1; |
| 320 | + } |
| 321 | + let userRecipes = µm.userSettings.userRecipes; |
| 322 | + if ( userRecipes.enabled ) { |
| 323 | + µm.recipeManager.fromString( |
| 324 | + '! uMatrix: Ruleset recipes 1.0\n' + userRecipes.content |
| 325 | + ); |
| 326 | + } |
| 327 | + if ( countdownCount === 0 ) { |
| 328 | + onDone(); |
| 329 | + } |
| 330 | + }; |
302 | 331 |
|
| 332 | + this.getAvailableRecipeFiles(onMetadataReady); |
303 | 333 | }; |
304 | 334 |
|
305 | 335 | /******************************************************************************/ |
|
406 | 436 | type: 'recipes', |
407 | 437 | contentURL: assetKey, |
408 | 438 | external: true, |
409 | | - submitter: 'user', |
410 | | - title: assetKey |
| 439 | + submitter: 'user' |
411 | 440 | }; |
412 | 441 | this.assets.registerAssetSource(assetKey, entry); |
413 | 442 | availableRecipeFiles.set(assetKey, entry); |
|
717 | 746 | 'externalRecipeFiles', |
718 | 747 | 'userRecipes' |
719 | 748 | ); |
720 | | - if ( recipesChanged ) { |
721 | | - µm.recipeManager.reset(); |
722 | | - } |
723 | 749 | if ( typeof callback === 'function' ) { |
724 | 750 | callback({ |
725 | 751 | hostsChanged: hostsChanged, |
|
0 commit comments