2025-08-06 20:48:03 +08:00
|
|
|
|
import { useState, useEffect, useRef } from "react";
|
2025-09-28 20:47:44 +08:00
|
|
|
|
import { useTranslation } from "react-i18next";
|
2025-08-23 23:11:39 +08:00
|
|
|
|
import { Provider } from "./types";
|
2025-08-30 21:54:11 +08:00
|
|
|
|
import { AppType } from "./lib/tauri-api";
|
2025-08-06 20:48:03 +08:00
|
|
|
|
import ProviderList from "./components/ProviderList";
|
|
|
|
|
|
import AddProviderModal from "./components/AddProviderModal";
|
|
|
|
|
|
import EditProviderModal from "./components/EditProviderModal";
|
|
|
|
|
|
import { ConfirmDialog } from "./components/ConfirmDialog";
|
2025-08-31 21:27:58 +08:00
|
|
|
|
import { AppSwitcher } from "./components/AppSwitcher";
|
2025-09-07 10:48:27 +08:00
|
|
|
|
import SettingsModal from "./components/SettingsModal";
|
2025-09-10 19:46:38 +08:00
|
|
|
|
import { UpdateBadge } from "./components/UpdateBadge";
|
2025-09-08 15:38:06 +08:00
|
|
|
|
import { Plus, Settings, Moon, Sun } from "lucide-react";
|
2025-10-08 22:35:07 +08:00
|
|
|
|
import McpPanel from "./components/mcp/McpPanel";
|
2025-09-08 15:38:06 +08:00
|
|
|
|
import { buttonStyles } from "./lib/styles";
|
|
|
|
|
|
import { useDarkMode } from "./hooks/useDarkMode";
|
2025-09-17 23:47:17 +08:00
|
|
|
|
import { extractErrorMessage } from "./utils/errorUtils";
|
2025-08-04 22:16:26 +08:00
|
|
|
|
|
|
|
|
|
|
function App() {
|
2025-09-28 20:47:44 +08:00
|
|
|
|
const { t } = useTranslation();
|
2025-09-08 15:38:06 +08:00
|
|
|
|
const { isDarkMode, toggleDarkMode } = useDarkMode();
|
2025-08-30 21:54:11 +08:00
|
|
|
|
const [activeApp, setActiveApp] = useState<AppType>("claude");
|
2025-08-06 20:48:03 +08:00
|
|
|
|
const [providers, setProviders] = useState<Record<string, Provider>>({});
|
|
|
|
|
|
const [currentProviderId, setCurrentProviderId] = useState<string>("");
|
|
|
|
|
|
const [isAddModalOpen, setIsAddModalOpen] = useState(false);
|
|
|
|
|
|
const [editingProviderId, setEditingProviderId] = useState<string | null>(
|
2025-10-10 14:59:02 +08:00
|
|
|
|
null,
|
2025-08-06 20:48:03 +08:00
|
|
|
|
);
|
|
|
|
|
|
const [notification, setNotification] = useState<{
|
|
|
|
|
|
message: string;
|
|
|
|
|
|
type: "success" | "error";
|
|
|
|
|
|
} | null>(null);
|
|
|
|
|
|
const [isNotificationVisible, setIsNotificationVisible] = useState(false);
|
|
|
|
|
|
const [confirmDialog, setConfirmDialog] = useState<{
|
|
|
|
|
|
isOpen: boolean;
|
|
|
|
|
|
title: string;
|
|
|
|
|
|
message: string;
|
|
|
|
|
|
onConfirm: () => void;
|
|
|
|
|
|
} | null>(null);
|
2025-09-07 10:48:27 +08:00
|
|
|
|
const [isSettingsOpen, setIsSettingsOpen] = useState(false);
|
2025-10-08 22:35:07 +08:00
|
|
|
|
const [isMcpOpen, setIsMcpOpen] = useState(false);
|
2025-08-24 23:31:56 +08:00
|
|
|
|
const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
2025-08-06 16:16:09 +08:00
|
|
|
|
|
|
|
|
|
|
// 设置通知的辅助函数
|
2025-08-06 20:48:03 +08:00
|
|
|
|
const showNotification = (
|
|
|
|
|
|
message: string,
|
|
|
|
|
|
type: "success" | "error",
|
2025-10-10 14:59:02 +08:00
|
|
|
|
duration = 3000,
|
2025-08-06 20:48:03 +08:00
|
|
|
|
) => {
|
2025-08-06 16:16:09 +08:00
|
|
|
|
// 清除之前的定时器
|
|
|
|
|
|
if (timeoutRef.current) {
|
2025-08-06 20:48:03 +08:00
|
|
|
|
clearTimeout(timeoutRef.current);
|
2025-08-06 16:16:09 +08:00
|
|
|
|
}
|
2025-08-06 20:48:03 +08:00
|
|
|
|
|
2025-08-06 16:16:09 +08:00
|
|
|
|
// 立即显示通知
|
2025-08-06 20:48:03 +08:00
|
|
|
|
setNotification({ message, type });
|
|
|
|
|
|
setIsNotificationVisible(true);
|
|
|
|
|
|
|
2025-08-06 16:16:09 +08:00
|
|
|
|
// 设置淡出定时器
|
|
|
|
|
|
timeoutRef.current = setTimeout(() => {
|
2025-08-06 20:48:03 +08:00
|
|
|
|
setIsNotificationVisible(false);
|
2025-08-06 16:16:09 +08:00
|
|
|
|
// 等待淡出动画完成后清除通知
|
|
|
|
|
|
setTimeout(() => {
|
2025-08-06 20:48:03 +08:00
|
|
|
|
setNotification(null);
|
|
|
|
|
|
timeoutRef.current = null;
|
|
|
|
|
|
}, 300); // 与CSS动画时间匹配
|
|
|
|
|
|
}, duration);
|
|
|
|
|
|
};
|
2025-08-04 22:16:26 +08:00
|
|
|
|
|
|
|
|
|
|
// 加载供应商列表
|
|
|
|
|
|
useEffect(() => {
|
2025-08-06 20:48:03 +08:00
|
|
|
|
loadProviders();
|
2025-08-30 21:54:11 +08:00
|
|
|
|
}, [activeApp]); // 当切换应用时重新加载
|
2025-08-04 22:16:26 +08:00
|
|
|
|
|
2025-08-06 16:16:09 +08:00
|
|
|
|
// 清理定时器
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
return () => {
|
|
|
|
|
|
if (timeoutRef.current) {
|
2025-08-06 20:48:03 +08:00
|
|
|
|
clearTimeout(timeoutRef.current);
|
2025-08-06 16:16:09 +08:00
|
|
|
|
}
|
2025-08-06 20:48:03 +08:00
|
|
|
|
};
|
|
|
|
|
|
}, []);
|
2025-08-04 22:16:26 +08:00
|
|
|
|
|
2025-09-19 14:22:39 +08:00
|
|
|
|
// 监听托盘切换事件(包括菜单切换)
|
2025-09-06 16:21:21 +08:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
let unlisten: (() => void) | null = null;
|
|
|
|
|
|
|
|
|
|
|
|
const setupListener = async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
unlisten = await window.api.onProviderSwitched(async (data) => {
|
2025-09-13 15:37:39 +08:00
|
|
|
|
if (import.meta.env.DEV) {
|
2025-09-28 20:47:44 +08:00
|
|
|
|
console.log(t("console.providerSwitchReceived"), data);
|
2025-09-13 15:37:39 +08:00
|
|
|
|
}
|
2025-09-06 16:21:21 +08:00
|
|
|
|
|
|
|
|
|
|
// 如果当前应用类型匹配,则重新加载数据
|
|
|
|
|
|
if (data.appType === activeApp) {
|
|
|
|
|
|
await loadProviders();
|
|
|
|
|
|
}
|
2025-09-19 14:22:39 +08:00
|
|
|
|
|
2025-10-03 20:03:55 +08:00
|
|
|
|
// 若为 Claude,则同步插件配置
|
2025-10-01 21:23:55 +08:00
|
|
|
|
if (data.appType === "claude") {
|
|
|
|
|
|
await syncClaudePlugin(data.providerId, true);
|
|
|
|
|
|
}
|
2025-09-06 16:21:21 +08:00
|
|
|
|
});
|
|
|
|
|
|
} catch (error) {
|
2025-09-28 20:47:44 +08:00
|
|
|
|
console.error(t("console.setupListenerFailed"), error);
|
2025-09-06 16:21:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
setupListener();
|
|
|
|
|
|
|
|
|
|
|
|
// 清理监听器
|
|
|
|
|
|
return () => {
|
|
|
|
|
|
if (unlisten) {
|
|
|
|
|
|
unlisten();
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2025-10-03 20:03:55 +08:00
|
|
|
|
}, [activeApp]);
|
2025-09-06 16:21:21 +08:00
|
|
|
|
|
2025-08-04 22:16:26 +08:00
|
|
|
|
const loadProviders = async () => {
|
2025-08-30 21:54:11 +08:00
|
|
|
|
const loadedProviders = await window.api.getProviders(activeApp);
|
|
|
|
|
|
const currentId = await window.api.getCurrentProvider(activeApp);
|
2025-08-06 20:48:03 +08:00
|
|
|
|
setProviders(loadedProviders);
|
|
|
|
|
|
setCurrentProviderId(currentId);
|
2025-08-27 11:00:53 +08:00
|
|
|
|
|
2025-09-05 15:16:03 +08:00
|
|
|
|
// 如果供应商列表为空,尝试自动从 live 导入一条默认供应商
|
2025-08-07 20:27:16 +08:00
|
|
|
|
if (Object.keys(loadedProviders).length === 0) {
|
2025-08-07 21:28:45 +08:00
|
|
|
|
await handleAutoImportDefault();
|
2025-08-07 20:27:16 +08:00
|
|
|
|
}
|
2025-08-06 20:48:03 +08:00
|
|
|
|
};
|
2025-08-04 22:16:26 +08:00
|
|
|
|
|
2025-08-06 07:45:18 +08:00
|
|
|
|
// 生成唯一ID
|
|
|
|
|
|
const generateId = () => {
|
2025-08-07 23:58:07 +08:00
|
|
|
|
return crypto.randomUUID();
|
2025-08-06 20:48:03 +08:00
|
|
|
|
};
|
2025-08-06 07:45:18 +08:00
|
|
|
|
|
2025-08-06 20:48:03 +08:00
|
|
|
|
const handleAddProvider = async (provider: Omit<Provider, "id">) => {
|
2025-08-04 22:16:26 +08:00
|
|
|
|
const newProvider: Provider = {
|
|
|
|
|
|
...provider,
|
2025-08-06 20:48:03 +08:00
|
|
|
|
id: generateId(),
|
2025-09-07 22:29:08 +08:00
|
|
|
|
createdAt: Date.now(), // 添加创建时间戳
|
2025-08-06 20:48:03 +08:00
|
|
|
|
};
|
2025-08-30 21:54:11 +08:00
|
|
|
|
await window.api.addProvider(newProvider, activeApp);
|
2025-08-06 20:48:03 +08:00
|
|
|
|
await loadProviders();
|
|
|
|
|
|
setIsAddModalOpen(false);
|
2025-09-06 16:21:21 +08:00
|
|
|
|
// 更新托盘菜单
|
|
|
|
|
|
await window.api.updateTrayMenu();
|
2025-08-06 20:48:03 +08:00
|
|
|
|
};
|
2025-08-04 22:16:26 +08:00
|
|
|
|
|
2025-08-07 23:58:07 +08:00
|
|
|
|
const handleEditProvider = async (provider: Provider) => {
|
|
|
|
|
|
try {
|
2025-08-30 21:54:11 +08:00
|
|
|
|
await window.api.updateProvider(provider, activeApp);
|
2025-08-07 23:58:07 +08:00
|
|
|
|
await loadProviders();
|
|
|
|
|
|
setEditingProviderId(null);
|
|
|
|
|
|
// 显示编辑成功提示
|
2025-09-28 20:47:44 +08:00
|
|
|
|
showNotification(t("notifications.providerSaved"), "success", 2000);
|
2025-09-06 16:21:21 +08:00
|
|
|
|
// 更新托盘菜单
|
|
|
|
|
|
await window.api.updateTrayMenu();
|
2025-08-07 23:58:07 +08:00
|
|
|
|
} catch (error) {
|
2025-09-28 20:47:44 +08:00
|
|
|
|
console.error(t("console.updateProviderFailed"), error);
|
2025-08-07 23:58:07 +08:00
|
|
|
|
setEditingProviderId(null);
|
2025-09-17 23:47:17 +08:00
|
|
|
|
const errorMessage = extractErrorMessage(error);
|
|
|
|
|
|
const message = errorMessage
|
2025-09-28 20:47:44 +08:00
|
|
|
|
? t("notifications.saveFailed", { error: errorMessage })
|
|
|
|
|
|
: t("notifications.saveFailedGeneric");
|
2025-09-17 23:47:17 +08:00
|
|
|
|
showNotification(message, "error", errorMessage ? 6000 : 3000);
|
2025-08-07 23:58:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-08-04 22:16:26 +08:00
|
|
|
|
const handleDeleteProvider = async (id: string) => {
|
2025-08-06 20:48:03 +08:00
|
|
|
|
const provider = providers[id];
|
2025-08-06 16:29:52 +08:00
|
|
|
|
setConfirmDialog({
|
|
|
|
|
|
isOpen: true,
|
2025-09-28 20:47:44 +08:00
|
|
|
|
title: t("confirm.deleteProvider"),
|
|
|
|
|
|
message: t("confirm.deleteProviderMessage", { name: provider?.name }),
|
2025-08-06 16:29:52 +08:00
|
|
|
|
onConfirm: async () => {
|
2025-08-30 21:54:11 +08:00
|
|
|
|
await window.api.deleteProvider(id, activeApp);
|
2025-08-06 20:48:03 +08:00
|
|
|
|
await loadProviders();
|
|
|
|
|
|
setConfirmDialog(null);
|
2025-09-28 20:47:44 +08:00
|
|
|
|
showNotification(t("notifications.providerDeleted"), "success");
|
2025-09-06 16:21:21 +08:00
|
|
|
|
// 更新托盘菜单
|
|
|
|
|
|
await window.api.updateTrayMenu();
|
2025-08-06 20:48:03 +08:00
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
2025-08-04 22:16:26 +08:00
|
|
|
|
|
2025-10-01 21:23:55 +08:00
|
|
|
|
// 同步 Claude 插件配置(写入/移除固定 JSON)
|
|
|
|
|
|
const syncClaudePlugin = async (providerId: string, silent = false) => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const provider = providers[providerId];
|
|
|
|
|
|
if (!provider) return;
|
|
|
|
|
|
const isOfficial = provider.category === "official";
|
|
|
|
|
|
await window.api.applyClaudePluginConfig({ official: isOfficial });
|
|
|
|
|
|
if (!silent) {
|
|
|
|
|
|
showNotification(
|
|
|
|
|
|
isOfficial
|
|
|
|
|
|
? t("notifications.removedFromClaudePlugin")
|
|
|
|
|
|
: t("notifications.appliedToClaudePlugin"),
|
|
|
|
|
|
"success",
|
2025-10-10 14:59:02 +08:00
|
|
|
|
2000,
|
2025-10-01 21:23:55 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
|
console.error("同步 Claude 插件失败:", error);
|
|
|
|
|
|
if (!silent) {
|
|
|
|
|
|
const message =
|
|
|
|
|
|
error?.message || t("notifications.syncClaudePluginFailed");
|
|
|
|
|
|
showNotification(message, "error", 5000);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-08-04 22:16:26 +08:00
|
|
|
|
const handleSwitchProvider = async (id: string) => {
|
2025-10-08 21:22:56 +08:00
|
|
|
|
try {
|
|
|
|
|
|
const success = await window.api.switchProvider(id, activeApp);
|
|
|
|
|
|
if (success) {
|
|
|
|
|
|
setCurrentProviderId(id);
|
|
|
|
|
|
// 显示重启提示
|
|
|
|
|
|
const appName = t(`apps.${activeApp}`);
|
|
|
|
|
|
showNotification(
|
|
|
|
|
|
t("notifications.switchSuccess", { appName }),
|
|
|
|
|
|
"success",
|
2025-10-10 14:59:02 +08:00
|
|
|
|
2000,
|
2025-10-08 21:22:56 +08:00
|
|
|
|
);
|
|
|
|
|
|
// 更新托盘菜单
|
|
|
|
|
|
await window.api.updateTrayMenu();
|
2025-09-19 11:06:26 +08:00
|
|
|
|
|
2025-10-08 21:22:56 +08:00
|
|
|
|
if (activeApp === "claude") {
|
|
|
|
|
|
await syncClaudePlugin(id, true);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
showNotification(t("notifications.switchFailed"), "error");
|
2025-10-01 21:23:55 +08:00
|
|
|
|
}
|
2025-10-08 21:22:56 +08:00
|
|
|
|
} catch (error) {
|
|
|
|
|
|
const detail = extractErrorMessage(error);
|
|
|
|
|
|
const msg = detail
|
|
|
|
|
|
? `${t("notifications.switchFailed")}: ${detail}`
|
|
|
|
|
|
: t("notifications.switchFailed");
|
|
|
|
|
|
// 详细错误展示稍长时间,便于用户阅读
|
|
|
|
|
|
showNotification(msg, "error", detail ? 6000 : 3000);
|
2025-08-06 07:59:11 +08:00
|
|
|
|
}
|
2025-08-06 20:48:03 +08:00
|
|
|
|
};
|
2025-08-04 22:16:26 +08:00
|
|
|
|
|
2025-10-05 23:33:07 +08:00
|
|
|
|
const handleImportSuccess = async () => {
|
|
|
|
|
|
await loadProviders();
|
|
|
|
|
|
try {
|
|
|
|
|
|
await window.api.updateTrayMenu();
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error("[App] Failed to refresh tray menu after import", error);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-09-05 15:16:03 +08:00
|
|
|
|
// 自动从 live 导入一条默认供应商(仅首次初始化时)
|
2025-08-07 21:28:45 +08:00
|
|
|
|
const handleAutoImportDefault = async () => {
|
|
|
|
|
|
try {
|
2025-08-30 21:54:11 +08:00
|
|
|
|
const result = await window.api.importCurrentConfigAsDefault(activeApp);
|
2025-08-27 11:00:53 +08:00
|
|
|
|
|
2025-08-07 21:28:45 +08:00
|
|
|
|
if (result.success) {
|
2025-08-27 11:00:53 +08:00
|
|
|
|
await loadProviders();
|
2025-09-28 20:47:44 +08:00
|
|
|
|
showNotification(t("notifications.autoImported"), "success", 3000);
|
2025-09-06 16:21:21 +08:00
|
|
|
|
// 更新托盘菜单
|
|
|
|
|
|
await window.api.updateTrayMenu();
|
2025-08-07 21:28:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
// 如果导入失败(比如没有现有配置),静默处理,不显示错误
|
|
|
|
|
|
} catch (error) {
|
2025-09-28 20:47:44 +08:00
|
|
|
|
console.error(t("console.autoImportFailed"), error);
|
2025-08-07 21:28:45 +08:00
|
|
|
|
// 静默处理,不影响用户体验
|
|
|
|
|
|
}
|
2025-08-27 11:00:53 +08:00
|
|
|
|
};
|
2025-08-07 21:28:45 +08:00
|
|
|
|
|
2025-08-04 22:16:26 +08:00
|
|
|
|
return (
|
2025-09-14 23:22:57 +08:00
|
|
|
|
<div className="h-screen flex flex-col bg-gray-50 dark:bg-gray-950">
|
|
|
|
|
|
{/* 顶部导航区域 - 固定高度 */}
|
|
|
|
|
|
<header className="flex-shrink-0 bg-white border-b border-gray-200 dark:bg-gray-900 dark:border-gray-800 px-6 py-4">
|
2025-09-06 16:21:21 +08:00
|
|
|
|
<div className="flex items-center justify-between">
|
2025-09-07 10:48:27 +08:00
|
|
|
|
<div className="flex items-center gap-2">
|
2025-09-15 10:24:41 +08:00
|
|
|
|
<a
|
|
|
|
|
|
href="https://github.com/farion1231/cc-switch"
|
|
|
|
|
|
target="_blank"
|
|
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
|
|
className="text-xl font-semibold text-blue-500 dark:text-blue-400 hover:text-blue-600 dark:hover:text-blue-300 transition-colors"
|
2025-09-28 20:47:44 +08:00
|
|
|
|
title={t("header.viewOnGithub")}
|
2025-09-15 10:24:41 +08:00
|
|
|
|
>
|
2025-09-07 10:48:27 +08:00
|
|
|
|
CC Switch
|
2025-09-15 10:24:41 +08:00
|
|
|
|
</a>
|
2025-09-08 15:38:06 +08:00
|
|
|
|
<button
|
|
|
|
|
|
onClick={toggleDarkMode}
|
|
|
|
|
|
className={buttonStyles.icon}
|
2025-09-28 20:47:44 +08:00
|
|
|
|
title={
|
|
|
|
|
|
isDarkMode
|
|
|
|
|
|
? t("header.toggleLightMode")
|
|
|
|
|
|
: t("header.toggleDarkMode")
|
|
|
|
|
|
}
|
2025-09-08 15:38:06 +08:00
|
|
|
|
>
|
|
|
|
|
|
{isDarkMode ? <Sun size={18} /> : <Moon size={18} />}
|
|
|
|
|
|
</button>
|
2025-09-10 19:46:38 +08:00
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
|
<button
|
|
|
|
|
|
onClick={() => setIsSettingsOpen(true)}
|
|
|
|
|
|
className={buttonStyles.icon}
|
2025-09-28 20:47:44 +08:00
|
|
|
|
title={t("common.settings")}
|
2025-09-10 19:46:38 +08:00
|
|
|
|
>
|
|
|
|
|
|
<Settings size={18} />
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<UpdateBadge onClick={() => setIsSettingsOpen(true)} />
|
|
|
|
|
|
</div>
|
2025-09-07 10:48:27 +08:00
|
|
|
|
</div>
|
2025-09-06 16:21:21 +08:00
|
|
|
|
|
|
|
|
|
|
<div className="flex items-center gap-4">
|
|
|
|
|
|
<AppSwitcher activeApp={activeApp} onSwitch={setActiveApp} />
|
|
|
|
|
|
|
2025-10-08 21:22:56 +08:00
|
|
|
|
<button
|
2025-10-08 22:35:07 +08:00
|
|
|
|
onClick={() => setIsMcpOpen(true)}
|
2025-10-10 11:58:40 +08:00
|
|
|
|
className="inline-flex items-center gap-2 px-7 py-2 text-sm font-medium rounded-lg transition-colors bg-emerald-500 text-white hover:bg-emerald-600 dark:bg-emerald-600 dark:hover:bg-emerald-700"
|
2025-10-08 21:22:56 +08:00
|
|
|
|
>
|
|
|
|
|
|
MCP
|
|
|
|
|
|
</button>
|
|
|
|
|
|
|
2025-09-06 16:21:21 +08:00
|
|
|
|
<button
|
|
|
|
|
|
onClick={() => setIsAddModalOpen(true)}
|
2025-09-08 15:38:06 +08:00
|
|
|
|
className={`inline-flex items-center gap-2 ${buttonStyles.primary}`}
|
2025-09-06 16:21:21 +08:00
|
|
|
|
>
|
|
|
|
|
|
<Plus size={16} />
|
2025-09-28 20:47:44 +08:00
|
|
|
|
{t("header.addProvider")}
|
2025-09-06 16:21:21 +08:00
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
2025-08-04 22:16:26 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</header>
|
|
|
|
|
|
|
2025-09-14 23:22:57 +08:00
|
|
|
|
{/* 主内容区域 - 独立滚动 */}
|
|
|
|
|
|
<main className="flex-1 overflow-y-scroll">
|
|
|
|
|
|
<div className="pt-3 px-6 pb-6">
|
|
|
|
|
|
<div className="max-w-4xl mx-auto">
|
|
|
|
|
|
{/* 通知组件 - 相对于视窗定位 */}
|
|
|
|
|
|
{notification && (
|
|
|
|
|
|
<div
|
2025-10-09 16:44:28 +08:00
|
|
|
|
className={`fixed top-20 left-1/2 transform -translate-x-1/2 z-[80] px-4 py-3 rounded-lg shadow-lg transition-all duration-300 ${
|
2025-09-14 23:22:57 +08:00
|
|
|
|
notification.type === "error"
|
|
|
|
|
|
? "bg-red-500 text-white"
|
|
|
|
|
|
: "bg-green-500 text-white"
|
|
|
|
|
|
} ${isNotificationVisible ? "opacity-100 translate-y-0" : "opacity-0 -translate-y-2"}`}
|
|
|
|
|
|
>
|
|
|
|
|
|
{notification.message}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
2025-08-06 20:48:03 +08:00
|
|
|
|
|
2025-09-14 23:22:57 +08:00
|
|
|
|
<ProviderList
|
|
|
|
|
|
providers={providers}
|
|
|
|
|
|
currentProviderId={currentProviderId}
|
|
|
|
|
|
onSwitch={handleSwitchProvider}
|
|
|
|
|
|
onDelete={handleDeleteProvider}
|
|
|
|
|
|
onEdit={setEditingProviderId}
|
2025-09-19 08:30:29 +08:00
|
|
|
|
appType={activeApp}
|
|
|
|
|
|
onNotify={showNotification}
|
2025-09-14 23:22:57 +08:00
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
2025-09-06 16:21:21 +08:00
|
|
|
|
</div>
|
2025-08-04 22:16:26 +08:00
|
|
|
|
</main>
|
|
|
|
|
|
|
|
|
|
|
|
{isAddModalOpen && (
|
|
|
|
|
|
<AddProviderModal
|
2025-08-30 21:54:11 +08:00
|
|
|
|
appType={activeApp}
|
2025-08-04 22:16:26 +08:00
|
|
|
|
onAdd={handleAddProvider}
|
|
|
|
|
|
onClose={() => setIsAddModalOpen(false)}
|
|
|
|
|
|
/>
|
|
|
|
|
|
)}
|
2025-08-05 09:51:41 +08:00
|
|
|
|
|
|
|
|
|
|
{editingProviderId && providers[editingProviderId] && (
|
|
|
|
|
|
<EditProviderModal
|
2025-08-30 21:54:11 +08:00
|
|
|
|
appType={activeApp}
|
2025-08-05 09:51:41 +08:00
|
|
|
|
provider={providers[editingProviderId]}
|
|
|
|
|
|
onSave={handleEditProvider}
|
|
|
|
|
|
onClose={() => setEditingProviderId(null)}
|
|
|
|
|
|
/>
|
|
|
|
|
|
)}
|
2025-08-06 16:29:52 +08:00
|
|
|
|
|
|
|
|
|
|
{confirmDialog && (
|
|
|
|
|
|
<ConfirmDialog
|
|
|
|
|
|
isOpen={confirmDialog.isOpen}
|
|
|
|
|
|
title={confirmDialog.title}
|
|
|
|
|
|
message={confirmDialog.message}
|
|
|
|
|
|
onConfirm={confirmDialog.onConfirm}
|
|
|
|
|
|
onCancel={() => setConfirmDialog(null)}
|
|
|
|
|
|
/>
|
|
|
|
|
|
)}
|
2025-09-07 10:48:27 +08:00
|
|
|
|
|
|
|
|
|
|
{isSettingsOpen && (
|
2025-10-05 23:33:07 +08:00
|
|
|
|
<SettingsModal
|
|
|
|
|
|
onClose={() => setIsSettingsOpen(false)}
|
|
|
|
|
|
onImportSuccess={handleImportSuccess}
|
|
|
|
|
|
/>
|
2025-09-07 10:48:27 +08:00
|
|
|
|
)}
|
2025-10-08 22:35:07 +08:00
|
|
|
|
|
|
|
|
|
|
{isMcpOpen && (
|
2025-10-09 11:04:36 +08:00
|
|
|
|
<McpPanel
|
2025-10-10 12:35:02 +08:00
|
|
|
|
appType={activeApp}
|
2025-10-09 11:04:36 +08:00
|
|
|
|
onClose={() => setIsMcpOpen(false)}
|
|
|
|
|
|
onNotify={showNotification}
|
|
|
|
|
|
/>
|
2025-10-08 22:35:07 +08:00
|
|
|
|
)}
|
2025-08-04 22:16:26 +08:00
|
|
|
|
</div>
|
2025-08-06 20:48:03 +08:00
|
|
|
|
);
|
2025-08-04 22:16:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-06 20:48:03 +08:00
|
|
|
|
export default App;
|