diff --git a/src/renderer/managers/updater.ts b/src/renderer/managers/updater.ts index 5123c6b58..dbe63fe66 100644 --- a/src/renderer/managers/updater.ts +++ b/src/renderer/managers/updater.ts @@ -134,8 +134,25 @@ export async function checkUpdate(id: string, verbose = true): Promise { } const newVersion = res.manifest.version; + const versions = [newVersion.split("."), version.split(".")]; - if (newVersion === version) { + if ( + newVersion !== version && + (versions[0][0] > versions[1][0] || + (versions[0][0] === versions[1][0] && versions[0][1] > versions[1][1]) || + (versions[0][0] === versions[1][0] && + versions[0][1] === versions[1][1] && + versions[0][2] > versions[1][2])) + ) { + logger.log(`Entity ${id} has an update available`); + updaterState.set(id, { + available: true, + url: res.url, + webUrl: res.webUrl, + lastChecked: Date.now(), + version: newVersion, + }); + } else { if (verbose) logger.log(`Entity ${id} is up to date`); updaterState.set(id, { available: false, @@ -144,17 +161,7 @@ export async function checkUpdate(id: string, verbose = true): Promise { webUrl: res.webUrl, version: newVersion, }); - return; } - - logger.log(`Entity ${id} has an update available`); - updaterState.set(id, { - available: true, - url: res.url, - webUrl: res.webUrl, - lastChecked: Date.now(), - version: newVersion, - }); } export async function installUpdate(id: string, force = false, verbose = true): Promise { @@ -219,10 +226,18 @@ export async function checkAllUpdates(autoCheck = false, verbose = false): Promi logger.log("Checking for updates"); - await Promise.all([ - checkUpdate(REPLUGGED_ID, verbose), - ...addons.map((addon) => checkUpdate(addon.manifest.id, verbose)), - ]); + const delay = (ms: number): Promise => new Promise((resolve) => setTimeout(resolve, ms)); + + async function checkUpdatesWithRateLimit(): Promise { + await checkUpdate(REPLUGGED_ID, verbose); + + for (const addon of addons) { + await checkUpdate(addon.manifest.id, verbose); + await delay(1000 / 15); // Delay for 1 second divided by 15 (15 requests per second) + } + } + + await checkUpdatesWithRateLimit(); logger.log("All updates checked"); updaterSettings.set("lastChecked", Date.now());