From e10285f85b896015432796899e5e767dd5b80965 Mon Sep 17 00:00:00 2001 From: Teltta <92880720+Teltta@users.noreply.github.com> Date: Sun, 8 Oct 2023 17:00:42 +0300 Subject: [PATCH 1/3] Fix --- src/renderer/managers/updater.ts | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/renderer/managers/updater.ts b/src/renderer/managers/updater.ts index 5123c6b58..cec6335ce 100644 --- a/src/renderer/managers/updater.ts +++ b/src/renderer/managers/updater.ts @@ -63,6 +63,36 @@ 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 +165,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, From 1dc1abdf039434f2e2a65a5f7d5a0ec48dbd7a56 Mon Sep 17 00:00:00 2001 From: Teltta <92880720+Teltta@users.noreply.github.com> Date: Sun, 8 Oct 2023 17:10:08 +0300 Subject: [PATCH 2/3] Prettier --- src/renderer/managers/updater.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/renderer/managers/updater.ts b/src/renderer/managers/updater.ts index cec6335ce..5f71cab32 100644 --- a/src/renderer/managers/updater.ts +++ b/src/renderer/managers/updater.ts @@ -73,8 +73,18 @@ function listLjust(iterable: string[], length: number, defaultValue: string): vo } 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 !== ""}); + 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"); From 60ab587aa47529894f3863e1f44bb8c78eab821a Mon Sep 17 00:00:00 2001 From: Teltta <92880720+Teltta@users.noreply.github.com> Date: Sun, 8 Oct 2023 17:13:24 +0300 Subject: [PATCH 3/3] Fix CSpell --- src/renderer/managers/updater.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/renderer/managers/updater.ts b/src/renderer/managers/updater.ts index 5f71cab32..ee220fc97 100644 --- a/src/renderer/managers/updater.ts +++ b/src/renderer/managers/updater.ts @@ -65,7 +65,7 @@ const completedUpdates = new Set(); const notDigit = /(?!\.)\D/gi; -function listLjust(iterable: string[], length: number, defaultValue: string): void { +function listLJust(iterable: string[], length: number, defaultValue: string): void { const l = iterable.length; for (let i = 0; i < length - l; i++) { iterable.push(defaultValue); @@ -86,8 +86,8 @@ function isLatest(localVersion: string, serverVersion: string): boolean { return elm !== ""; }); - listLjust(ver1, ver2.length, "0"); - listLjust(ver2, ver1.length, "0"); + 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");