diff --git a/src/renderer/managers/updater.ts b/src/renderer/managers/updater.ts index 5123c6b58..ee220fc97 100644 --- a/src/renderer/managers/updater.ts +++ b/src/renderer/managers/updater.ts @@ -63,6 +63,46 @@ const updaterState = await init>("dev.replugged.U const completedUpdates = new Set(); +const notDigit = /(?!\.)\D/gi; + +function listLJust(iterable: string[], length: number, defaultValue: string): void { + const l = iterable.length; + for (let i = 0; i < length - l; i++) { + iterable.push(defaultValue); + } +} + +function isLatest(localVersion: string, serverVersion: string): boolean { + const ver1 = localVersion + .replace(notDigit, "") + .split(".") + .filter((elm) => { + return elm !== ""; + }); + const ver2 = serverVersion + .replace(notDigit, "") + .split(".") + .filter((elm) => { + return elm !== ""; + }); + + listLJust(ver1, ver2.length, "0"); + listLJust(ver2, ver1.length, "0"); + + for (let i = 0; i < ver1.length; i++) { + ver1[i] = ver1[i].padStart(ver2[i].length, "0"); + } + + for (let i = 0; i < ver1.length; i++) { + ver2[i] = ver2[i].padStart(ver1[i].length, "0"); + } + + const ver1Int = parseInt(ver1.join(""), 10); + const ver2Int = parseInt(ver2.join(""), 10); + + return ver1Int >= ver2Int; +} + export function getUpdateState(id: string): UpdateSettings | null { const setting = updaterState.get(id); if (!setting) return null; @@ -135,7 +175,7 @@ export async function checkUpdate(id: string, verbose = true): Promise { const newVersion = res.manifest.version; - if (newVersion === version) { + if (isLatest(version, newVersion)) { if (verbose) logger.log(`Entity ${id} is up to date`); updaterState.set(id, { available: false,