diff --git a/packages/client/src/init.ts b/packages/client/src/init.ts index dea59ba5b2..9a0b6e3818 100644 --- a/packages/client/src/init.ts +++ b/packages/client/src/init.ts @@ -54,6 +54,7 @@ import { reloadChannel } from "@/scripts/unison-reload"; import { ColdDeviceStorage, defaultStore } from "@/store"; import { useStream, isReloading } from "@/stream"; import widgets from "@/widgets"; +import { compareFirefishVersions } from "@/scripts/compare-versions"; function checkForSplash() { const splash = document.getElementById("splash"); @@ -250,23 +251,11 @@ function checkForSplash() { // テーマリビルドするため localStorage.removeItem("theme"); - const isUpdated = (prevVersion: string, currentVersion: string) => { - const p = prevVersion.split("-"); - const c = currentVersion.split("-"); - - if (p[0] < c[0]) return true; - if (p[0] === c[0] && p[1] == null && c[1] != null) return true; - if (p[0] === c[0] && p[1] != null && c[1] != null && p[1] < c[1]) - return true; - - return false; - }; - try { // 変なバージョン文字列来るとcompareVersionsでエラーになるため if ( lastVersion != null && - isUpdated(lastVersion, version) && + compareFirefishVersions(lastVersion, version) === 1 && defaultStore.state.showUpdates ) { // ログインしてる場合だけ diff --git a/packages/client/src/pages/admin/index.vue b/packages/client/src/pages/admin/index.vue index 1dd8540414..29c43946f3 100644 --- a/packages/client/src/pages/admin/index.vue +++ b/packages/client/src/pages/admin/index.vue @@ -85,6 +85,7 @@ import { provideMetadataReceiver, } from "@/scripts/page-metadata"; import icon from "@/scripts/icon"; +import { compareFirefishVersions } from "@/scripts/compare-versions"; const isEmpty = (x: string | null) => x == null || x === ""; const el = ref(null); @@ -121,11 +122,8 @@ os.api("admin/abuse-user-reports", { if (defaultStore.state.showAdminUpdates) { os.api("latest-version").then((res) => { - const cleanRes = parseInt(res?.latest_version.replace(/[^0-9]/g, "")); - const cleanVersion = parseInt(version.replace(/[^0-9]/g, "")); - if (cleanRes > cleanVersion) { - updateAvailable.value = true; - } + updateAvailable.value = + compareFirefishVersions(version, res?.latest_version) === 1; }); } diff --git a/packages/client/src/scripts/compare-versions.ts b/packages/client/src/scripts/compare-versions.ts new file mode 100644 index 0000000000..7b232db838 --- /dev/null +++ b/packages/client/src/scripts/compare-versions.ts @@ -0,0 +1,19 @@ +const less = -1; +const same = 0; +const more = 1; + +export const compareFirefishVersions = ( + oldVersion: string, + newVersion: string, +) => { + if (oldVersion === newVersion) return same; + + const o = oldVersion.split("-"); + const n = newVersion.split("-"); + + if (o[0] < n[0]) return more; + if (o[0] === n[0] && o[1] == null && n[1] != null) return more; + if (o[0] === n[0] && o[1] != null && n[1] != null && o[1] < n[1]) return more; + + return less; +}; diff --git a/packages/client/src/ui/_common_/navbar.vue b/packages/client/src/ui/_common_/navbar.vue index b629ddb85f..178eb630f9 100644 --- a/packages/client/src/ui/_common_/navbar.vue +++ b/packages/client/src/ui/_common_/navbar.vue @@ -168,6 +168,7 @@ import { i18n } from "@/i18n"; import { instance } from "@/instance"; import { version } from "@/config"; import icon from "@/scripts/icon"; +import { compareFirefishVersions } from "@/scripts/compare-versions"; const isEmpty = (x: string | null) => x == null || x === ""; @@ -217,11 +218,8 @@ if (isAdmin) { if (defaultStore.state.showAdminUpdates) { os.api("latest-version").then((res) => { - const cleanRes = parseInt(res?.latest_version.replace(/[^0-9]/g, "")); - const cleanVersion = parseInt(version.replace(/[^0-9]/g, "")); - if (cleanRes > cleanVersion) { - updateAvailable.value = true; - } + updateAvailable.value = + compareFirefishVersions(version, res?.latest_version) === 1; }); }