diff --git a/packages/napcat-webui-frontend/src/components/system_info.tsx b/packages/napcat-webui-frontend/src/components/system_info.tsx
index 9f1e325a..e2246718 100644
--- a/packages/napcat-webui-frontend/src/components/system_info.tsx
+++ b/packages/napcat-webui-frontend/src/components/system_info.tsx
@@ -10,7 +10,6 @@ import { FaCircleInfo, FaInfo, FaQq } from 'react-icons/fa6';
import { IoLogoChrome, IoLogoOctocat } from 'react-icons/io';
import { RiMacFill } from 'react-icons/ri';
import { useState } from 'react';
-import toast from 'react-hot-toast';
import key from '@/const/key';
import WebUIManager from '@/controllers/webui_manager';
@@ -203,16 +202,161 @@ export interface NewVersionTipProps {
// );
// };
+// 更新状态类型
+type UpdateStatus = 'idle' | 'updating' | 'success' | 'error';
+
+// 更新对话框内容组件
+const UpdateDialogContent: React.FC<{
+ currentVersion: string;
+ latestVersion: string;
+ status: UpdateStatus;
+ errorMessage?: string;
+}> = ({ currentVersion, latestVersion, status, errorMessage }) => {
+ return (
+
+ {/* 版本信息 */}
+
+
+ 当前版本
+
+ v{currentVersion}
+
+
+
+ 最新版本
+ v{latestVersion}
+
+
+
+ {/* 更新状态显示 */}
+ {status === 'updating' && (
+
+
+
+
+ 正在更新中...
+
+
+ 请耐心等待,更新可能需要几分钟
+
+
+
+ )}
+
+ {status === 'success' && (
+
+
+
+
+ 更新完成
+
+
+ 请重启 NapCat 以应用新版本
+
+
+
+
+
+ 请手动重启 NapCat,更新才会生效
+
+
+
+ )}
+
+ {status === 'error' && (
+
+
+
+
+ 更新失败
+
+
+ {errorMessage || '请稍后重试或手动更新'}
+
+
+
+ )}
+
+ );
+};
+
const NewVersionTip = (props: NewVersionTipProps) => {
const { currentVersion } = props;
const dialog = useDialog();
const { data: latestVersion, error } = useRequest(WebUIManager.getLatestTag);
- const [updating, setUpdating] = useState(false);
+ const [updateStatus, setUpdateStatus] = useState('idle');
if (error || !latestVersion || !currentVersion || latestVersion === currentVersion) {
return null;
}
+ const handleUpdate = async () => {
+ setUpdateStatus('updating');
+
+ try {
+ await WebUIManager.UpdateNapCat();
+ setUpdateStatus('success');
+ // 显示更新成功对话框
+ dialog.alert({
+ title: '更新完成',
+ content: (
+
+ ),
+ confirmText: '我知道了',
+ size: 'md',
+ });
+ } catch (err) {
+ console.error('Update failed:', err);
+ const errMessage = err instanceof Error ? err.message : '未知错误';
+ setUpdateStatus('error');
+ // 显示更新失败对话框
+ dialog.alert({
+ title: '更新失败',
+ content: (
+
+ ),
+ confirmText: '确定',
+ size: 'md',
+ });
+ }
+ };
+
+ const showUpdateDialog = () => {
+ dialog.confirm({
+ title: '发现新版本',
+ content: (
+
+ ),
+ confirmText: '立即更新',
+ cancelText: '稍后更新',
+ size: 'md',
+ onConfirm: handleUpdate,
+ });
+ };
+
return (