From 5f5629b08794d9cb84742097ff120c6870c5cc0b Mon Sep 17 00:00:00 2001 From: Khai Truong <56820749+khaitruong922@users.noreply.github.com> Date: Fri, 13 Sep 2024 03:04:02 +0700 Subject: [PATCH] Fix recommended dictionary download queue (#1410) * fix queue not working * disable download button if in queue * remove useless void --- ext/js/pages/settings/dictionary-import-controller.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ext/js/pages/settings/dictionary-import-controller.js b/ext/js/pages/settings/dictionary-import-controller.js index 206c721632..15bc4b908f 100644 --- a/ext/js/pages/settings/dictionary-import-controller.js +++ b/ext/js/pages/settings/dictionary-import-controller.js @@ -120,15 +120,16 @@ export class DictionaryImportController { while (this._recommendedDictionaryQueue.length > 0) { this._recommendedDictionaryActiveImport = true; try { - const url = this._recommendedDictionaryQueue.shift(); + const url = this._recommendedDictionaryQueue[0]; if (!url) { continue; } const importProgressTracker = new ImportProgressTracker(this._getUrlImportSteps(), 1); const onProgress = importProgressTracker.onProgress.bind(importProgressTracker); - void this._importDictionaries( + await this._importDictionaries( this._generateFilesFromUrls([url], onProgress), importProgressTracker, ); + void this._recommendedDictionaryQueue.shift(); } catch (error) { log.error(error); } @@ -219,7 +220,11 @@ export class DictionaryImportController { const homepage = querySelectorNotNull(template, '.homepage'); /** @type {HTMLButtonElement} */ const button = querySelectorNotNull(template, '.action-button[data-action=import-recommended-dictionary]'); - button.disabled = installedDictionaryNames.has(dictionary.name) || installedDictionaryDownloadUrls.has(dictionary.downloadUrl); + button.disabled = ( + installedDictionaryNames.has(dictionary.name) || + installedDictionaryDownloadUrls.has(dictionary.downloadUrl) || + this._recommendedDictionaryQueue.includes(dictionary.downloadUrl) + ); const urlAttribute = document.createAttribute('data-import-url'); urlAttribute.value = dictionary.downloadUrl;