Skip to content

Commit

Permalink
count updates
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanVukovic99 committed Jul 6, 2024
1 parent b5a9895 commit 8ecc26a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions ext/js/pages/settings/dictionary-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ class DictionaryEntry {
}

/**
* @returns {Promise<void>}
* @returns {Promise<boolean>}
*/
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} */
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8ecc26a

Please sign in to comment.