chore (client): add scripts/compare-versions to compare Firefish versions

This commit is contained in:
naskya 2024-03-02 13:48:25 +09:00
parent 78bdec3af4
commit ec8a9096da
No known key found for this signature in database
GPG key ID: 712D413B3A9FED5C
4 changed files with 27 additions and 23 deletions

View file

@ -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
) {
// ログインしてる場合だけ

View file

@ -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<HTMLElement | null>(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;
});
}

View file

@ -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;
};

View file

@ -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;
});
}