refactor (client): compare Firefish versions lexicographically

This commit is contained in:
naskya 2024-03-17 02:59:30 +09:00
parent ba48f063a5
commit 80e3e0e91d
No known key found for this signature in database
GPG Key ID: 712D413B3A9FED5C
4 changed files with 3 additions and 31 deletions

View File

@ -40,7 +40,6 @@ import { i18n } from "@/i18n";
import { fetchInstance, instance } from "@/instance";
import { isSignedIn, me } from "@/me";
import { alert, api, confirm, popup, post, toast } from "@/os";
import { compareFirefishVersions } from "@/scripts/compare-versions";
import { deviceKind } from "@/scripts/device-kind";
import { getAccountFromId } from "@/scripts/get-account-from-id";
import { makeHotkey } from "@/scripts/hotkey";
@ -246,11 +245,7 @@ function checkForSplash() {
try {
// 変なバージョン文字列来るとcompareVersionsでエラーになるため
if (
lastVersion != null &&
compareFirefishVersions(lastVersion, version) === 1 &&
defaultStore.state.showUpdates
) {
if (lastVersion < version && defaultStore.state.showUpdates) {
// ログインしてる場合だけ
if (me) {
popup(

View File

@ -85,7 +85,6 @@ 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);
@ -122,8 +121,7 @@ os.api("admin/abuse-user-reports", {
if (defaultStore.state.showAdminUpdates) {
os.api("latest-version").then((res) => {
updateAvailable.value =
compareFirefishVersions(version, res?.latest_version) === 1;
updateAvailable.value = version < res?.latest_version;
});
}

View File

@ -1,19 +0,0 @@
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

@ -162,7 +162,6 @@ 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 === "";
@ -212,8 +211,7 @@ if (isAdmin) {
if (defaultStore.state.showAdminUpdates) {
os.api("latest-version").then((res) => {
updateAvailable.value =
compareFirefishVersions(version, res?.latest_version) === 1;
updateAvailable.value = version < res?.latest_version;
});
}