From 8ecc26a8df18d1709aae5e76d7c4fb2d878a8c58 Mon Sep 17 00:00:00 2001 From: Stefan Vukovic Date: Sat, 6 Jul 2024 21:04:29 +0200 Subject: [PATCH] count updates --- ext/js/pages/settings/dictionary-controller.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ext/js/pages/settings/dictionary-controller.js b/ext/js/pages/settings/dictionary-controller.js index 8b60450528..24890de432 100644 --- a/ext/js/pages/settings/dictionary-controller.js +++ b/ext/js/pages/settings/dictionary-controller.js @@ -122,12 +122,12 @@ class DictionaryEntry { } /** - * @returns {Promise} + * @returns {Promise} */ async checkForUpdate() { this._updatesAvailable.hidden = true; const {isUpdatable, indexUrl, revision} = this._dictionaryInfo; - if (!isUpdatable || !indexUrl) { return; } + if (!isUpdatable || !indexUrl) { return false; } const response = await fetch(indexUrl); /** @type {unknown} */ @@ -140,10 +140,11 @@ class DictionaryEntry { const validIndex = /** @type {import('dictionary-data').Index} */ (index); if (!this._compareRevisions(revision, validIndex.revision)) { - return; + return false; } this._updatesAvailable.hidden = false; + return true; } // Private @@ -900,7 +901,10 @@ export class DictionaryController { this._setButtonsEnabled(false); const updateChecks = this._dictionaryEntries.map((entry) => entry.checkForUpdate()); - await Promise.all(updateChecks); + const updateCount = (await Promise.all(updateChecks)).reduce((sum, value) => (sum + (value ? 1 : 0)), 0); + if (this._checkUpdatesButton !== null) { + this._checkUpdatesButton.textContent = updateCount ? `${updateCount} updates` : 'No updates'; + } } finally { this._setButtonsEnabled(true); this._checkingUpdates = false;