forcing downloading to be synchronous to ensure successful writing
This commit is contained in:
		
							parent
							
								
									f38d690b57
								
							
						
					
					
						commit
						9c2759c41e
					
				
					 1 changed files with 24 additions and 26 deletions
				
			
		|  | @ -78,7 +78,7 @@ export default class FilterManager { | ||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		}; | ||||||
| 
 | 
 | ||||||
| 		if (!filters.isEmpty()) { | 		if (!filters.isEmpty()) { | ||||||
| 			while (!filters.isEmpty()) { | 			while (!filters.isEmpty()) { | ||||||
|  | @ -87,32 +87,30 @@ export default class FilterManager { | ||||||
| 				// Inform the user of download state.
 | 				// Inform the user of download state.
 | ||||||
| 				new logging (texts.localized(`settings_filters_update_status`), filter_URL); | 				new logging (texts.localized(`settings_filters_update_status`), filter_URL); | ||||||
| 
 | 
 | ||||||
| 				// Create promise of downloading.
 | 				try { | ||||||
| 				let filter_download = net.download(filter_URL, `JSON`, false, true); | 					let DOWNLOAD = await net.download(filter_URL, `JSON`, false, true); | ||||||
| 				filter_download |  | ||||||
| 					.then(async function (result) { |  | ||||||
| 						// Only work when the filter is valid.
 |  | ||||||
| 						if (result) { |  | ||||||
| 							// Write the filter to storage.
 |  | ||||||
| 							if (!(await global.write(["filters", filter_URL], result, -1, {"silent": true, "strict": true}))) { |  | ||||||
| 								throw ReferenceError; |  | ||||||
| 							}; |  | ||||||
| 					 | 					 | ||||||
| 							// Add the filter to the sync list.
 | 					// Only work when the filter is valid.
 | ||||||
| 							if ((await global.read(["settings", `filters`])) ? !((Object.keys(await global.read(["settings", `filters`]))).includes(filter_URL)) : true) { | 					if (DOWNLOAD) { | ||||||
| 								if (!(global.write(["settings", `filters`, filter_URL], true, 1, {"silent": true}))) { | 						// Write the filter to storage.
 | ||||||
| 									throw ReferenceError; | 						if (!(await global.write(["filters", filter_URL], DOWNLOAD, -1, {"silent": true, "strict": true}))) { | ||||||
| 								}; | 							throw ReferenceError; | ||||||
| 							}; |  | ||||||
| 
 |  | ||||||
| 							// Notify that the update is completed.
 |  | ||||||
| 							new logging(texts.localized(`settings_filters_update_status_complete`),filter_URL); |  | ||||||
| 						}; | 						}; | ||||||
| 					}) | 
 | ||||||
| 					.catch((error) => { | 						// Add the filter to the sync list.
 | ||||||
| 						// Inform the user of the download failure.
 | 						if (((await global.read(["settings", `filters`])) ? !((Object.keys(await global.read(["settings", `filters`]))).includes(filter_URL)) : true) | ||||||
| 						logging.error(error.name, texts.localized(`settings_filters_update_status_failure`, null, [error.name, filter_URL]), error.stack); | 							? (!(await global.write(["settings", `filters`, filter_URL], true, 1, {"silent": true}))) | ||||||
| 					}); | 							: false) { | ||||||
|  | 								throw ReferenceError; | ||||||
|  | 						}; | ||||||
|  | 
 | ||||||
|  | 						// Notify that the update is completed.
 | ||||||
|  | 						new logging(texts.localized(`settings_filters_update_status_complete`),filter_URL); | ||||||
|  | 					}; | ||||||
|  | 				} catch (error) { | ||||||
|  | 					// Inform the user of the download failure.
 | ||||||
|  | 					logging.error(error.name, texts.localized(`settings_filters_update_status_failure`, null, [error.name, filter_URL]), error.stack); | ||||||
|  | 				}; | ||||||
| 			} | 			} | ||||||
| 		} else { | 		} else { | ||||||
| 			// Inform the user of the download being unnecessary.
 | 			// Inform the user of the download being unnecessary.
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue