Quellcode durchsuchen

fix version compare

lloydzhou vor 1 Jahr
Ursprung
Commit
bd9de4dc4d
2 geänderte Dateien mit 13 neuen und 2 gelöschten Zeilen
  1. 2 2
      app/components/settings.tsx
  2. 11 0
      app/utils.ts

+ 2 - 2
app/components/settings.tsx

@@ -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,
@@ -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) {

+ 11 - 0
app/utils.ts

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