Skip to content

Commit

Permalink
fix version compare
Browse files Browse the repository at this point in the history
  • Loading branch information
lloydzhou committed Oct 11, 2024
1 parent 2eebfcf commit bd9de4d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/components/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import Locale, {
changeLang,
getLang,
} from "../locales";
import { copyToClipboard, clientUpdate } from "../utils";
import { copyToClipboard, clientUpdate, semverCompare } from "../utils";
import Link from "next/link";
import {
Anthropic,
Expand Down Expand Up @@ -585,7 +585,7 @@ export function Settings() {
const [checkingUpdate, setCheckingUpdate] = useState(false);
const currentVersion = updateStore.formatVersion(updateStore.version);
const remoteId = updateStore.formatVersion(updateStore.remoteVersion);
const hasNewVersion = currentVersion !== remoteId;
const hasNewVersion = semverCompare(currentVersion, remoteId) === -1;
const updateUrl = getClientConfig()?.isApp ? RELEASE_URL : UPDATE_URL;

function checkUpdate(force = false) {
Expand Down
11 changes: 11 additions & 0 deletions app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,14 @@ export function clientUpdate() {
showToast(Locale.Settings.Update.Failed);
});
}

// https://gist.github.com/iwill/a83038623ba4fef6abb9efca87ae9ccb
export function semverCompare(a, b) {
if (a.startsWith(b + "-")) return -1;
if (b.startsWith(a + "-")) return 1;
return a.localeCompare(b, undefined, {
numeric: true,
sensitivity: "case",
caseFirst: "upper",
});
}

0 comments on commit bd9de4d

Please sign in to comment.