Merge pull request #5632 from ConnectAI-E/feature/H0llyW00dzZ-updater
Feature/h0lly w00dz z updater
This commit is contained in:
commit
cda4494cec
|
@ -49,7 +49,7 @@ import Locale, {
|
||||||
changeLang,
|
changeLang,
|
||||||
getLang,
|
getLang,
|
||||||
} from "../locales";
|
} from "../locales";
|
||||||
import { copyToClipboard } from "../utils";
|
import { copyToClipboard, clientUpdate, semverCompare } from "../utils";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import {
|
import {
|
||||||
Anthropic,
|
Anthropic,
|
||||||
|
@ -585,7 +585,7 @@ export function Settings() {
|
||||||
const [checkingUpdate, setCheckingUpdate] = useState(false);
|
const [checkingUpdate, setCheckingUpdate] = useState(false);
|
||||||
const currentVersion = updateStore.formatVersion(updateStore.version);
|
const currentVersion = updateStore.formatVersion(updateStore.version);
|
||||||
const remoteId = updateStore.formatVersion(updateStore.remoteVersion);
|
const remoteId = updateStore.formatVersion(updateStore.remoteVersion);
|
||||||
const hasNewVersion = currentVersion !== remoteId;
|
const hasNewVersion = semverCompare(currentVersion, remoteId) === -1;
|
||||||
const updateUrl = getClientConfig()?.isApp ? RELEASE_URL : UPDATE_URL;
|
const updateUrl = getClientConfig()?.isApp ? RELEASE_URL : UPDATE_URL;
|
||||||
|
|
||||||
function checkUpdate(force = false) {
|
function checkUpdate(force = false) {
|
||||||
|
@ -1357,9 +1357,17 @@ export function Settings() {
|
||||||
{checkingUpdate ? (
|
{checkingUpdate ? (
|
||||||
<LoadingIcon />
|
<LoadingIcon />
|
||||||
) : hasNewVersion ? (
|
) : hasNewVersion ? (
|
||||||
<Link href={updateUrl} target="_blank" className="link">
|
clientConfig?.isApp ? (
|
||||||
{Locale.Settings.Update.GoToUpdate}
|
<IconButton
|
||||||
</Link>
|
icon={<ResetIcon></ResetIcon>}
|
||||||
|
text={Locale.Settings.Update.GoToUpdate}
|
||||||
|
onClick={() => clientUpdate()}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Link href={updateUrl} target="_blank" className="link">
|
||||||
|
{Locale.Settings.Update.GoToUpdate}
|
||||||
|
</Link>
|
||||||
|
)
|
||||||
) : (
|
) : (
|
||||||
<IconButton
|
<IconButton
|
||||||
icon={<ResetIcon></ResetIcon>}
|
icon={<ResetIcon></ResetIcon>}
|
||||||
|
|
|
@ -26,6 +26,13 @@ declare interface Window {
|
||||||
isPermissionGranted(): Promise<boolean>;
|
isPermissionGranted(): Promise<boolean>;
|
||||||
sendNotification(options: string | Options): void;
|
sendNotification(options: string | Options): void;
|
||||||
};
|
};
|
||||||
|
updater: {
|
||||||
|
checkUpdate(): Promise<UpdateResult>;
|
||||||
|
installUpdate(): Promise<void>;
|
||||||
|
onUpdaterEvent(
|
||||||
|
handler: (status: UpdateStatusResult) => void,
|
||||||
|
): Promise<UnlistenFn>;
|
||||||
|
};
|
||||||
http: {
|
http: {
|
||||||
fetch<T>(
|
fetch<T>(
|
||||||
url: string,
|
url: string,
|
||||||
|
|
|
@ -205,6 +205,8 @@ const cn = {
|
||||||
IsChecking: "正在检查更新...",
|
IsChecking: "正在检查更新...",
|
||||||
FoundUpdate: (x: string) => `发现新版本:${x}`,
|
FoundUpdate: (x: string) => `发现新版本:${x}`,
|
||||||
GoToUpdate: "前往更新",
|
GoToUpdate: "前往更新",
|
||||||
|
Success: "更新成功!",
|
||||||
|
Failed: "更新失败",
|
||||||
},
|
},
|
||||||
SendKey: "发送键",
|
SendKey: "发送键",
|
||||||
Theme: "主题",
|
Theme: "主题",
|
||||||
|
|
|
@ -207,6 +207,8 @@ const en: LocaleType = {
|
||||||
IsChecking: "Checking update...",
|
IsChecking: "Checking update...",
|
||||||
FoundUpdate: (x: string) => `Found new version: ${x}`,
|
FoundUpdate: (x: string) => `Found new version: ${x}`,
|
||||||
GoToUpdate: "Update",
|
GoToUpdate: "Update",
|
||||||
|
Success: "Update Successful.",
|
||||||
|
Failed: "Update Failed.",
|
||||||
},
|
},
|
||||||
SendKey: "Send Key",
|
SendKey: "Send Key",
|
||||||
Theme: "Theme",
|
Theme: "Theme",
|
||||||
|
|
|
@ -6,6 +6,7 @@ import {
|
||||||
} from "../constant";
|
} from "../constant";
|
||||||
import { getClientConfig } from "../config/client";
|
import { getClientConfig } from "../config/client";
|
||||||
import { createPersistStore } from "../utils/store";
|
import { createPersistStore } from "../utils/store";
|
||||||
|
import { clientUpdate } from "../utils";
|
||||||
import ChatGptIcon from "../icons/chatgpt.png";
|
import ChatGptIcon from "../icons/chatgpt.png";
|
||||||
import Locale from "../locales";
|
import Locale from "../locales";
|
||||||
import { ClientApi } from "../client/api";
|
import { ClientApi } from "../client/api";
|
||||||
|
@ -119,6 +120,7 @@ export const useUpdateStore = createPersistStore(
|
||||||
icon: `${ChatGptIcon.src}`,
|
icon: `${ChatGptIcon.src}`,
|
||||||
sound: "Default",
|
sound: "Default",
|
||||||
});
|
});
|
||||||
|
clientUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
34
app/utils.ts
34
app/utils.ts
|
@ -386,3 +386,37 @@ export function getOperationId(operation: {
|
||||||
`${operation.method.toUpperCase()}${operation.path.replaceAll("/", "_")}`
|
`${operation.method.toUpperCase()}${operation.path.replaceAll("/", "_")}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function clientUpdate() {
|
||||||
|
// this a wild for updating client app
|
||||||
|
return window.__TAURI__?.updater
|
||||||
|
.checkUpdate()
|
||||||
|
.then((updateResult) => {
|
||||||
|
if (updateResult.shouldUpdate) {
|
||||||
|
window.__TAURI__?.updater
|
||||||
|
.installUpdate()
|
||||||
|
.then((result) => {
|
||||||
|
showToast(Locale.Settings.Update.Success);
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
console.error("[Install Update Error]", e);
|
||||||
|
showToast(Locale.Settings.Update.Failed);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
console.error("[Check Update Error]", e);
|
||||||
|
showToast(Locale.Settings.Update.Failed);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://gist.github.com/iwill/a83038623ba4fef6abb9efca87ae9ccb
|
||||||
|
export function semverCompare(a: string, b: string) {
|
||||||
|
if (a.startsWith(b + "-")) return -1;
|
||||||
|
if (b.startsWith(a + "-")) return 1;
|
||||||
|
return a.localeCompare(b, undefined, {
|
||||||
|
numeric: true,
|
||||||
|
sensitivity: "case",
|
||||||
|
caseFirst: "upper",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -99,7 +99,7 @@
|
||||||
"endpoints": [
|
"endpoints": [
|
||||||
"https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/releases/latest/download/latest.json"
|
"https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/releases/latest/download/latest.json"
|
||||||
],
|
],
|
||||||
"dialog": false,
|
"dialog": true,
|
||||||
"windows": {
|
"windows": {
|
||||||
"installMode": "passive"
|
"installMode": "passive"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue