Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions app/command.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { useEffect } from "react";
import { useSearchParams } from "react-router-dom";
import Locale from "./locales";
import { getClientConfig } from "@/app/config/client";

const isApp = !!getClientConfig()?.isApp;

type Command = (param: string) => void;
interface Commands {
Expand Down Expand Up @@ -37,13 +40,20 @@ interface ChatCommands {
newm?: Command;
next?: Command;
prev?: Command;
restart?: Command;
clear?: Command;
del?: Command;
}

export const ChatCommandPrefix = ":";

export function useChatCommand(commands: ChatCommands = {}) {
const chatCommands = { ...commands };

if (!isApp) {
delete chatCommands.restart;
}

function extract(userInput: string) {
return (
userInput.startsWith(ChatCommandPrefix) ? userInput.slice(1) : userInput
Expand All @@ -53,7 +63,7 @@ export function useChatCommand(commands: ChatCommands = {}) {
function search(userInput: string) {
const input = extract(userInput);
const desc = Locale.Chat.Commands;
return Object.keys(commands)
return Object.keys(chatCommands)
.filter((c) => c.startsWith(input))
.map((c) => ({
title: desc[c as keyof ChatCommands],
Expand All @@ -63,11 +73,11 @@ export function useChatCommand(commands: ChatCommands = {}) {

function match(userInput: string) {
const command = extract(userInput);
const matched = typeof commands[command] === "function";
const matched = typeof chatCommands[command] === "function";

return {
matched,
invoke: () => matched && commands[command]!(userInput),
invoke: () => matched && chatCommands[command]!(userInput),
};
}

Expand Down
1 change: 1 addition & 0 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ function _Chat() {
newm: () => navigate(Path.NewChat),
prev: () => chatStore.nextSession(-1),
next: () => chatStore.nextSession(1),
restart: () => window.__TAURI__?.process.relaunch(),
clear: () =>
chatStore.updateCurrentSession(
(session) => (session.clearContextIndex = session.messages.length),
Expand Down
24 changes: 21 additions & 3 deletions app/components/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,14 @@ export function Settings() {
setCheckingUpdate(true);
updateStore.getLatestVersion(force).then(() => {
setCheckingUpdate(false);
window.__TAURI__?.updater.checkUpdate().then((updateResult) => {
if (updateResult.status === "DONE") {
window.__TAURI__?.updater.installUpdate();
}
}).catch((e) => {
console.error("[Check Update Error]", e);
showToast(Locale.Settings.Update.Failed);
});
});

console.log("[Update] local version ", updateStore.version);
Expand Down Expand Up @@ -683,9 +691,19 @@ export function Settings() {
{checkingUpdate ? (
<LoadingIcon />
) : hasNewVersion ? (
<Link href={updateUrl} target="_blank" className="link">
{Locale.Settings.Update.GoToUpdate}
</Link>
<>
{clientConfig?.isApp ? (
<IconButton
icon={<DownloadIcon></DownloadIcon>}
text={Locale.Settings.Update.GoToUpdate}
onClick={() => checkUpdate(true)}
/>
) : (
<Link href={updateUrl} target="_blank" className="link">
{Locale.Settings.Update.GoToUpdate}
</Link>
)}
</>
) : (
<IconButton
icon={<ResetIcon></ResetIcon>}
Expand Down
17 changes: 17 additions & 0 deletions app/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,31 @@ declare interface Window {
invoke(command: string, payload?: Record<string, unknown>): Promise<any>;
dialog: {
save(options?: Record<string, unknown>): Promise<string | null>;
open(options?: OpenDialogOptions): Promise<null | string | string[]>;
// support locale language
message(message: string, options?: string | MessageDialogOptions): Promise<void>;
ask(message: string, options?: string | ConfirmDialogOptions): Promise<boolean>;
};
fs: {
writeBinaryFile(path: string, data: Uint8Array): Promise<void>;
};
process: {
relaunch(): Promise<void>;
};
notification:{
requestPermission(): Promise<Permission>;
isPermissionGranted(): Promise<boolean>;
sendNotification(options: string | Options): void;
};
updater: {
checkUpdate(): Promise<UpdateResult>;
installUpdate(): Promise<void>;
onUpdaterEvent(handler: (status: UpdateStatusResult) => void): Promise<UnlistenFn>;
};
// can do route in client app like CORS fetch, currently is not enabled yet only module added.
http: {
fetch<T>(url: string, options?: FetchOptions): Promise<Response<T>>;
getClient(options?: ClientOptions): Promise<Client>;
};
};
}
3 changes: 3 additions & 0 deletions app/locales/cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const cn = {
newm: "从面具新建聊天",
next: "下一个聊天",
prev: "上一个聊天",
restart: "重新启动客户端",
clear: "清除上下文",
del: "删除聊天",
},
Expand Down Expand Up @@ -167,6 +168,8 @@ const cn = {
IsChecking: "正在检查更新...",
FoundUpdate: (x: string) => `发现新版本:${x}`,
GoToUpdate: "前往更新",
Success: "更新成功。",
Failed: "更新失败。",
},
SendKey: "发送键",
Theme: "主题",
Expand Down
3 changes: 3 additions & 0 deletions app/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const en: LocaleType = {
newm: "Start a new chat with mask",
next: "Next Chat",
prev: "Previous Chat",
restart: "Restart a client",
clear: "Clear Context",
del: "Delete Chat",
},
Expand Down Expand Up @@ -169,6 +170,8 @@ const en: LocaleType = {
IsChecking: "Checking update...",
FoundUpdate: (x: string) => `Found new version: ${x}`,
GoToUpdate: "Update",
Success: "Update Succesfull.",
Failed: "Update Failed.",
},
SendKey: "Send Key",
Theme: "Theme",
Expand Down
3 changes: 3 additions & 0 deletions app/locales/id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const id: PartialLocaleType = {
newm: "Mulai Chat Baru dengan Masks",
next: "Chat Selanjutnya",
prev: "Chat Sebelumnya",
restart: "Restart klien",
clear: "Bersihkan Percakapan",
del: "Hapus Chat",
},
Expand Down Expand Up @@ -156,6 +157,8 @@ const id: PartialLocaleType = {
IsChecking: "Memeriksa pembaruan...",
FoundUpdate: (x: string) => `Versi terbaru ditemukan: ${x}`,
GoToUpdate: "Perbarui Sekarang",
Success: "Pembaruan Berhasil.",
Failed: "Pembaruan Gagal.",
},
AutoGenerateTitle: {
Title: "Hasilkan Judul Otomatis",
Expand Down
10 changes: 10 additions & 0 deletions app/store/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getClientConfig } from "../config/client";
import { createPersistStore } from "../utils/store";
import ChatGptIcon from "../icons/chatgpt.png";
import Locale from "../locales";
import { showToast } from "../components/ui-lib";

const ONE_MINUTE = 60 * 1000;
const isApp = !!getClientConfig()?.isApp;
Expand Down Expand Up @@ -109,6 +110,15 @@ export const useUpdateStore = createPersistStore(
icon: `${ChatGptIcon.src}`,
sound: "Default"
});
// this a wild for updating client app
window.__TAURI__?.updater.checkUpdate().then((updateResult) => {
if (updateResult.status === "DONE") {
window.__TAURI__?.updater.installUpdate();
}
}).catch((e) => {
console.error("[Check Update Error]", e);
showToast(Locale.Settings.Update.Failed);
});
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"endpoints": [
"https://github.com/Yidadaa/ChatGPT-Next-Web/releases/latest/download/latest.json"
],
"dialog": false,
"dialog": true,
"windows": {
"installMode": "passive"
},
Expand Down