2025-10-17 17:49:16 +08:00
|
|
|
|
import { useEffect, useMemo, useState } from "react";
|
2025-09-28 20:47:44 +08:00
|
|
|
|
import { useTranslation } from "react-i18next";
|
2025-10-16 10:49:56 +08:00
|
|
|
|
import { toast } from "sonner";
|
2025-10-19 22:12:12 +08:00
|
|
|
|
import { Plus, Settings, Edit3 } from "lucide-react";
|
2025-10-17 17:49:16 +08:00
|
|
|
|
import type { Provider } from "@/types";
|
|
|
|
|
|
import { useProvidersQuery } from "@/lib/query";
|
2025-10-18 16:52:02 +08:00
|
|
|
|
import {
|
|
|
|
|
|
providersApi,
|
|
|
|
|
|
settingsApi,
|
2025-10-30 14:59:15 +08:00
|
|
|
|
type AppId,
|
2025-10-18 16:52:02 +08:00
|
|
|
|
type ProviderSwitchEvent,
|
|
|
|
|
|
} from "@/lib/api";
|
2025-10-17 17:49:16 +08:00
|
|
|
|
import { useProviderActions } from "@/hooks/useProviderActions";
|
2025-10-16 10:49:56 +08:00
|
|
|
|
import { extractErrorMessage } from "@/utils/errorUtils";
|
|
|
|
|
|
import { AppSwitcher } from "@/components/AppSwitcher";
|
|
|
|
|
|
import { ProviderList } from "@/components/providers/ProviderList";
|
|
|
|
|
|
import { AddProviderDialog } from "@/components/providers/AddProviderDialog";
|
|
|
|
|
|
import { EditProviderDialog } from "@/components/providers/EditProviderDialog";
|
|
|
|
|
|
import { ConfirmDialog } from "@/components/ConfirmDialog";
|
2025-10-16 11:40:02 +08:00
|
|
|
|
import { SettingsDialog } from "@/components/settings/SettingsDialog";
|
2025-10-16 10:49:56 +08:00
|
|
|
|
import { UpdateBadge } from "@/components/UpdateBadge";
|
|
|
|
|
|
import UsageScriptModal from "@/components/UsageScriptModal";
|
2025-11-14 15:24:48 +08:00
|
|
|
|
import UnifiedMcpPanel from "@/components/mcp/UnifiedMcpPanel";
|
feat(prompts+i18n): add prompt management and improve prompt editor i18n (#193)
* feat(prompts): add prompt management across Tauri service and React UI
- backend: add commands/prompt.rs, services/prompt.rs, register in commands/mod.rs and lib.rs, refine app_config.rs
- frontend: add PromptPanel, PromptFormModal, PromptListItem, MarkdownEditor, usePromptActions, integrate in App.tsx
- api: add src/lib/api/prompts.ts
- i18n: update src/i18n/locales/{en,zh}.json
- build: update package.json and pnpm-lock.yaml
* feat(i18n): improve i18n for prompts and Markdown editor
- update src/i18n/locales/{en,zh}.json keys and strings
- apply i18n in PromptFormModal, PromptPanel, and MarkdownEditor
- align prompt text with src-tauri/src/services/prompt.rs
* feat(prompts): add enable/disable toggle and simplify panel UI
- Add PromptToggle component and integrate in prompt list items
- Implement toggleEnabled with optimistic update; enable via API, disable via upsert with enabled=false;
reload after success
- Simplify PromptPanel: remove file import and current-file preview to keep CRUD flow focused
- Tweak header controls style (use mcp variant) and minor copy: rename “Prompt Management” to “Prompts”
- i18n: add disableSuccess/disableFailed messages
- Backend (Tauri): prevent duplicate backups when importing original prompt content
* style: unify code formatting with trailing commas
* feat(prompts): add Gemini filename support to PromptFormModal
Update filename mapping to use Record<AppId, string> pattern, supporting
GEMINI.md alongside CLAUDE.md and AGENTS.md.
* fix(prompts): sync enabled prompt to file when updating
When updating a prompt that is currently enabled, automatically sync
the updated content to the corresponding live file (CLAUDE.md/AGENTS.md/GEMINI.md).
This ensures the active prompt file always reflects the latest content
when editing enabled prompts.
2025-11-12 16:41:41 +08:00
|
|
|
|
import PromptPanel from "@/components/prompts/PromptPanel";
|
2025-10-16 10:49:56 +08:00
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
|
|
2025-08-04 22:16:26 +08:00
|
|
|
|
function App() {
|
2025-09-28 20:47:44 +08:00
|
|
|
|
const { t } = useTranslation();
|
2025-10-16 10:49:56 +08:00
|
|
|
|
|
2025-10-30 14:59:15 +08:00
|
|
|
|
const [activeApp, setActiveApp] = useState<AppId>("claude");
|
2025-10-19 22:12:12 +08:00
|
|
|
|
const [isEditMode, setIsEditMode] = useState(false);
|
2025-09-07 10:48:27 +08:00
|
|
|
|
const [isSettingsOpen, setIsSettingsOpen] = useState(false);
|
2025-10-16 10:49:56 +08:00
|
|
|
|
const [isAddOpen, setIsAddOpen] = useState(false);
|
2025-10-08 22:35:07 +08:00
|
|
|
|
const [isMcpOpen, setIsMcpOpen] = useState(false);
|
feat(prompts+i18n): add prompt management and improve prompt editor i18n (#193)
* feat(prompts): add prompt management across Tauri service and React UI
- backend: add commands/prompt.rs, services/prompt.rs, register in commands/mod.rs and lib.rs, refine app_config.rs
- frontend: add PromptPanel, PromptFormModal, PromptListItem, MarkdownEditor, usePromptActions, integrate in App.tsx
- api: add src/lib/api/prompts.ts
- i18n: update src/i18n/locales/{en,zh}.json
- build: update package.json and pnpm-lock.yaml
* feat(i18n): improve i18n for prompts and Markdown editor
- update src/i18n/locales/{en,zh}.json keys and strings
- apply i18n in PromptFormModal, PromptPanel, and MarkdownEditor
- align prompt text with src-tauri/src/services/prompt.rs
* feat(prompts): add enable/disable toggle and simplify panel UI
- Add PromptToggle component and integrate in prompt list items
- Implement toggleEnabled with optimistic update; enable via API, disable via upsert with enabled=false;
reload after success
- Simplify PromptPanel: remove file import and current-file preview to keep CRUD flow focused
- Tweak header controls style (use mcp variant) and minor copy: rename “Prompt Management” to “Prompts”
- i18n: add disableSuccess/disableFailed messages
- Backend (Tauri): prevent duplicate backups when importing original prompt content
* style: unify code formatting with trailing commas
* feat(prompts): add Gemini filename support to PromptFormModal
Update filename mapping to use Record<AppId, string> pattern, supporting
GEMINI.md alongside CLAUDE.md and AGENTS.md.
* fix(prompts): sync enabled prompt to file when updating
When updating a prompt that is currently enabled, automatically sync
the updated content to the corresponding live file (CLAUDE.md/AGENTS.md/GEMINI.md).
This ensures the active prompt file always reflects the latest content
when editing enabled prompts.
2025-11-12 16:41:41 +08:00
|
|
|
|
const [isPromptOpen, setIsPromptOpen] = useState(false);
|
2025-10-16 10:49:56 +08:00
|
|
|
|
const [editingProvider, setEditingProvider] = useState<Provider | null>(null);
|
|
|
|
|
|
const [usageProvider, setUsageProvider] = useState<Provider | null>(null);
|
|
|
|
|
|
const [confirmDelete, setConfirmDelete] = useState<Provider | null>(null);
|
2025-08-06 20:48:03 +08:00
|
|
|
|
|
2025-10-16 10:49:56 +08:00
|
|
|
|
const { data, isLoading, refetch } = useProvidersQuery(activeApp);
|
|
|
|
|
|
const providers = useMemo(() => data?.providers ?? {}, [data]);
|
|
|
|
|
|
const currentProviderId = data?.currentProviderId ?? "";
|
2025-08-04 22:16:26 +08:00
|
|
|
|
|
2025-10-17 17:49:16 +08:00
|
|
|
|
// 🎯 使用 useProviderActions Hook 统一管理所有 Provider 操作
|
|
|
|
|
|
const {
|
|
|
|
|
|
addProvider,
|
|
|
|
|
|
updateProvider,
|
|
|
|
|
|
switchProvider,
|
|
|
|
|
|
deleteProvider,
|
|
|
|
|
|
saveUsageScript,
|
|
|
|
|
|
} = useProviderActions(activeApp);
|
2025-08-04 22:16:26 +08:00
|
|
|
|
|
2025-10-17 17:49:16 +08:00
|
|
|
|
// 监听来自托盘菜单的切换事件
|
2025-09-06 16:21:21 +08:00
|
|
|
|
useEffect(() => {
|
2025-10-16 10:49:56 +08:00
|
|
|
|
let unsubscribe: (() => void) | undefined;
|
2025-09-06 16:21:21 +08:00
|
|
|
|
|
|
|
|
|
|
const setupListener = async () => {
|
|
|
|
|
|
try {
|
2025-10-16 12:13:51 +08:00
|
|
|
|
unsubscribe = await providersApi.onSwitched(
|
2025-10-16 10:49:56 +08:00
|
|
|
|
async (event: ProviderSwitchEvent) => {
|
|
|
|
|
|
if (event.appType === activeApp) {
|
|
|
|
|
|
await refetch();
|
|
|
|
|
|
}
|
2025-10-24 11:56:18 +08:00
|
|
|
|
},
|
2025-10-16 10:49:56 +08:00
|
|
|
|
);
|
2025-09-06 16:21:21 +08:00
|
|
|
|
} catch (error) {
|
2025-10-16 10:49:56 +08:00
|
|
|
|
console.error("[App] Failed to subscribe provider switch event", error);
|
2025-09-06 16:21:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
setupListener();
|
|
|
|
|
|
return () => {
|
2025-10-16 10:49:56 +08:00
|
|
|
|
unsubscribe?.();
|
2025-09-06 16:21:21 +08:00
|
|
|
|
};
|
2025-10-16 10:49:56 +08:00
|
|
|
|
}, [activeApp, refetch]);
|
2025-09-06 16:21:21 +08:00
|
|
|
|
|
2025-10-17 17:49:16 +08:00
|
|
|
|
// 打开网站链接
|
|
|
|
|
|
const handleOpenWebsite = async (url: string) => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
await settingsApi.openExternal(url);
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
const detail =
|
|
|
|
|
|
extractErrorMessage(error) ||
|
|
|
|
|
|
t("notifications.openLinkFailed", {
|
|
|
|
|
|
defaultValue: "链接打开失败",
|
|
|
|
|
|
});
|
|
|
|
|
|
toast.error(detail);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2025-10-01 21:23:55 +08:00
|
|
|
|
|
2025-10-17 17:49:16 +08:00
|
|
|
|
// 编辑供应商
|
|
|
|
|
|
const handleEditProvider = async (provider: Provider) => {
|
|
|
|
|
|
await updateProvider(provider);
|
|
|
|
|
|
setEditingProvider(null);
|
|
|
|
|
|
};
|
2025-09-19 11:06:26 +08:00
|
|
|
|
|
2025-10-17 17:49:16 +08:00
|
|
|
|
// 确认删除供应商
|
|
|
|
|
|
const handleConfirmDelete = async () => {
|
2025-10-16 10:49:56 +08:00
|
|
|
|
if (!confirmDelete) return;
|
2025-10-17 17:49:16 +08:00
|
|
|
|
await deleteProvider(confirmDelete.id);
|
|
|
|
|
|
setConfirmDelete(null);
|
|
|
|
|
|
};
|
2025-08-04 22:16:26 +08:00
|
|
|
|
|
2025-10-24 11:56:18 +08:00
|
|
|
|
// 复制供应商
|
|
|
|
|
|
const handleDuplicateProvider = async (provider: Provider) => {
|
2025-10-24 13:02:07 +08:00
|
|
|
|
// 1️⃣ 计算新的 sortIndex:如果原供应商有 sortIndex,则复制它
|
|
|
|
|
|
const newSortIndex =
|
|
|
|
|
|
provider.sortIndex !== undefined ? provider.sortIndex + 1 : undefined;
|
|
|
|
|
|
|
2025-10-24 11:56:18 +08:00
|
|
|
|
const duplicatedProvider: Omit<Provider, "id" | "createdAt"> = {
|
|
|
|
|
|
name: `${provider.name} copy`,
|
|
|
|
|
|
settingsConfig: JSON.parse(JSON.stringify(provider.settingsConfig)), // 深拷贝
|
|
|
|
|
|
websiteUrl: provider.websiteUrl,
|
|
|
|
|
|
category: provider.category,
|
2025-10-24 13:02:07 +08:00
|
|
|
|
sortIndex: newSortIndex, // 复制原 sortIndex + 1
|
2025-10-24 11:56:18 +08:00
|
|
|
|
meta: provider.meta
|
|
|
|
|
|
? JSON.parse(JSON.stringify(provider.meta))
|
|
|
|
|
|
: undefined, // 深拷贝
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-10-24 13:02:07 +08:00
|
|
|
|
// 2️⃣ 如果原供应商有 sortIndex,需要将后续所有供应商的 sortIndex +1
|
|
|
|
|
|
if (provider.sortIndex !== undefined) {
|
|
|
|
|
|
const updates = Object.values(providers)
|
|
|
|
|
|
.filter(
|
|
|
|
|
|
(p) =>
|
|
|
|
|
|
p.sortIndex !== undefined &&
|
|
|
|
|
|
p.sortIndex >= newSortIndex! &&
|
|
|
|
|
|
p.id !== provider.id,
|
|
|
|
|
|
)
|
|
|
|
|
|
.map((p) => ({
|
|
|
|
|
|
id: p.id,
|
|
|
|
|
|
sortIndex: p.sortIndex! + 1,
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
// 先更新现有供应商的 sortIndex,为新供应商腾出位置
|
|
|
|
|
|
if (updates.length > 0) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
await providersApi.updateSortOrder(updates, activeApp);
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error("[App] Failed to update sort order", error);
|
|
|
|
|
|
toast.error(
|
|
|
|
|
|
t("provider.sortUpdateFailed", {
|
|
|
|
|
|
defaultValue: "排序更新失败",
|
|
|
|
|
|
}),
|
|
|
|
|
|
);
|
|
|
|
|
|
return; // 如果排序更新失败,不继续添加
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 3️⃣ 添加复制的供应商
|
2025-10-24 11:56:18 +08:00
|
|
|
|
await addProvider(duplicatedProvider);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-10-17 17:49:16 +08:00
|
|
|
|
// 导入配置成功后刷新
|
|
|
|
|
|
const handleImportSuccess = async () => {
|
2025-10-16 10:49:56 +08:00
|
|
|
|
await refetch();
|
2025-10-05 23:33:07 +08:00
|
|
|
|
try {
|
2025-10-16 10:49:56 +08:00
|
|
|
|
await providersApi.updateTrayMenu();
|
2025-10-05 23:33:07 +08:00
|
|
|
|
} catch (error) {
|
2025-10-16 10:49:56 +08:00
|
|
|
|
console.error("[App] Failed to refresh tray menu", error);
|
2025-10-05 23:33:07 +08:00
|
|
|
|
}
|
2025-10-17 17:49:16 +08:00
|
|
|
|
};
|
2025-08-07 21:28:45 +08:00
|
|
|
|
|
2025-08-04 22:16:26 +08:00
|
|
|
|
return (
|
2025-10-16 10:49:56 +08:00
|
|
|
|
<div className="flex h-screen flex-col bg-gray-50 dark:bg-gray-950">
|
|
|
|
|
|
<header className="flex-shrink-0 border-b border-gray-200 bg-white px-6 py-4 dark:border-gray-800 dark:bg-gray-900">
|
2025-10-19 23:29:13 +08:00
|
|
|
|
<div className="flex flex-wrap items-center justify-between gap-2">
|
|
|
|
|
|
<div className="flex items-center gap-1">
|
2025-09-15 10:24:41 +08:00
|
|
|
|
<a
|
|
|
|
|
|
href="https://github.com/farion1231/cc-switch"
|
|
|
|
|
|
target="_blank"
|
2025-10-16 10:49:56 +08:00
|
|
|
|
rel="noreferrer"
|
|
|
|
|
|
className="text-xl font-semibold text-blue-500 transition-colors hover:text-blue-600 dark:text-blue-400 dark:hover:text-blue-300"
|
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-10-16 10:49:56 +08:00
|
|
|
|
<Button
|
|
|
|
|
|
variant="ghost"
|
|
|
|
|
|
size="icon"
|
|
|
|
|
|
onClick={() => setIsSettingsOpen(true)}
|
2025-10-19 22:12:12 +08:00
|
|
|
|
title={t("common.settings")}
|
|
|
|
|
|
className="ml-2"
|
2025-09-08 15:38:06 +08:00
|
|
|
|
>
|
2025-10-16 10:49:56 +08:00
|
|
|
|
<Settings className="h-4 w-4" />
|
|
|
|
|
|
</Button>
|
2025-10-19 22:12:12 +08:00
|
|
|
|
<Button
|
|
|
|
|
|
variant="ghost"
|
|
|
|
|
|
size="icon"
|
|
|
|
|
|
onClick={() => setIsEditMode(!isEditMode)}
|
|
|
|
|
|
title={t(
|
2025-10-24 11:56:18 +08:00
|
|
|
|
isEditMode ? "header.exitEditMode" : "header.enterEditMode",
|
2025-10-19 22:12:12 +08:00
|
|
|
|
)}
|
|
|
|
|
|
className={
|
|
|
|
|
|
isEditMode
|
|
|
|
|
|
? "text-blue-500 hover:text-blue-600 dark:text-blue-400 dark:hover:text-blue-300"
|
|
|
|
|
|
: ""
|
|
|
|
|
|
}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Edit3 className="h-4 w-4" />
|
|
|
|
|
|
</Button>
|
2025-10-16 10:49:56 +08:00
|
|
|
|
<UpdateBadge onClick={() => setIsSettingsOpen(true)} />
|
2025-09-07 10:48:27 +08:00
|
|
|
|
</div>
|
2025-09-06 16:21:21 +08:00
|
|
|
|
|
2025-10-19 23:29:13 +08:00
|
|
|
|
<div className="flex flex-wrap items-center gap-2">
|
2025-09-06 16:21:21 +08:00
|
|
|
|
<AppSwitcher activeApp={activeApp} onSwitch={setActiveApp} />
|
feat(prompts+i18n): add prompt management and improve prompt editor i18n (#193)
* feat(prompts): add prompt management across Tauri service and React UI
- backend: add commands/prompt.rs, services/prompt.rs, register in commands/mod.rs and lib.rs, refine app_config.rs
- frontend: add PromptPanel, PromptFormModal, PromptListItem, MarkdownEditor, usePromptActions, integrate in App.tsx
- api: add src/lib/api/prompts.ts
- i18n: update src/i18n/locales/{en,zh}.json
- build: update package.json and pnpm-lock.yaml
* feat(i18n): improve i18n for prompts and Markdown editor
- update src/i18n/locales/{en,zh}.json keys and strings
- apply i18n in PromptFormModal, PromptPanel, and MarkdownEditor
- align prompt text with src-tauri/src/services/prompt.rs
* feat(prompts): add enable/disable toggle and simplify panel UI
- Add PromptToggle component and integrate in prompt list items
- Implement toggleEnabled with optimistic update; enable via API, disable via upsert with enabled=false;
reload after success
- Simplify PromptPanel: remove file import and current-file preview to keep CRUD flow focused
- Tweak header controls style (use mcp variant) and minor copy: rename “Prompt Management” to “Prompts”
- i18n: add disableSuccess/disableFailed messages
- Backend (Tauri): prevent duplicate backups when importing original prompt content
* style: unify code formatting with trailing commas
* feat(prompts): add Gemini filename support to PromptFormModal
Update filename mapping to use Record<AppId, string> pattern, supporting
GEMINI.md alongside CLAUDE.md and AGENTS.md.
* fix(prompts): sync enabled prompt to file when updating
When updating a prompt that is currently enabled, automatically sync
the updated content to the corresponding live file (CLAUDE.md/AGENTS.md/GEMINI.md).
This ensures the active prompt file always reflects the latest content
when editing enabled prompts.
2025-11-12 16:41:41 +08:00
|
|
|
|
<Button
|
|
|
|
|
|
variant="mcp"
|
|
|
|
|
|
onClick={() => setIsPromptOpen(true)}
|
|
|
|
|
|
className="min-w-[80px]"
|
|
|
|
|
|
>
|
|
|
|
|
|
{t("prompts.manage")}
|
|
|
|
|
|
</Button>
|
2025-10-16 15:32:26 +08:00
|
|
|
|
<Button
|
|
|
|
|
|
variant="mcp"
|
|
|
|
|
|
onClick={() => setIsMcpOpen(true)}
|
|
|
|
|
|
className="min-w-[80px]"
|
|
|
|
|
|
>
|
2025-10-08 21:22:56 +08:00
|
|
|
|
MCP
|
2025-10-16 10:49:56 +08:00
|
|
|
|
</Button>
|
|
|
|
|
|
<Button onClick={() => setIsAddOpen(true)}>
|
|
|
|
|
|
<Plus className="h-4 w-4" />
|
2025-10-19 11:55:46 +08:00
|
|
|
|
{t("header.addProvider")}
|
2025-10-16 10:49:56 +08:00
|
|
|
|
</Button>
|
2025-09-06 16:21:21 +08:00
|
|
|
|
</div>
|
2025-08-04 22:16:26 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</header>
|
|
|
|
|
|
|
2025-10-17 21:51:37 +08:00
|
|
|
|
<main className="flex-1 overflow-y-scroll">
|
2025-10-16 10:49:56 +08:00
|
|
|
|
<div className="mx-auto max-w-4xl px-6 py-6">
|
|
|
|
|
|
<ProviderList
|
|
|
|
|
|
providers={providers}
|
|
|
|
|
|
currentProviderId={currentProviderId}
|
2025-10-30 14:59:15 +08:00
|
|
|
|
appId={activeApp}
|
2025-10-16 10:49:56 +08:00
|
|
|
|
isLoading={isLoading}
|
2025-10-19 22:12:12 +08:00
|
|
|
|
isEditMode={isEditMode}
|
2025-10-17 17:49:16 +08:00
|
|
|
|
onSwitch={switchProvider}
|
2025-10-16 10:49:56 +08:00
|
|
|
|
onEdit={setEditingProvider}
|
2025-10-17 17:49:16 +08:00
|
|
|
|
onDelete={setConfirmDelete}
|
2025-10-24 11:56:18 +08:00
|
|
|
|
onDuplicate={handleDuplicateProvider}
|
2025-10-16 10:49:56 +08:00
|
|
|
|
onConfigureUsage={setUsageProvider}
|
|
|
|
|
|
onOpenWebsite={handleOpenWebsite}
|
|
|
|
|
|
onCreate={() => setIsAddOpen(true)}
|
|
|
|
|
|
/>
|
2025-09-06 16:21:21 +08:00
|
|
|
|
</div>
|
2025-08-04 22:16:26 +08:00
|
|
|
|
</main>
|
|
|
|
|
|
|
2025-10-16 10:49:56 +08:00
|
|
|
|
<AddProviderDialog
|
|
|
|
|
|
open={isAddOpen}
|
|
|
|
|
|
onOpenChange={setIsAddOpen}
|
2025-10-30 14:59:15 +08:00
|
|
|
|
appId={activeApp}
|
2025-10-17 17:49:16 +08:00
|
|
|
|
onSubmit={addProvider}
|
2025-10-16 10:49:56 +08:00
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
|
|
<EditProviderDialog
|
|
|
|
|
|
open={Boolean(editingProvider)}
|
|
|
|
|
|
provider={editingProvider}
|
|
|
|
|
|
onOpenChange={(open) => {
|
|
|
|
|
|
if (!open) {
|
|
|
|
|
|
setEditingProvider(null);
|
|
|
|
|
|
}
|
|
|
|
|
|
}}
|
|
|
|
|
|
onSubmit={handleEditProvider}
|
2025-10-30 14:59:15 +08:00
|
|
|
|
appId={activeApp}
|
2025-10-16 10:49:56 +08:00
|
|
|
|
/>
|
2025-08-05 09:51:41 +08:00
|
|
|
|
|
2025-10-16 10:49:56 +08:00
|
|
|
|
{usageProvider && (
|
|
|
|
|
|
<UsageScriptModal
|
|
|
|
|
|
provider={usageProvider}
|
2025-10-30 14:59:15 +08:00
|
|
|
|
appId={activeApp}
|
refactor: migrate UsageScriptModal to shadcn/ui Dialog component
Migrate the usage script configuration modal from custom modal implementation to shadcn/ui Dialog component to maintain consistent styling across the entire application.
## Changes
### UsageScriptModal.tsx
- Replace custom modal structure (fixed positioning, backdrop) with Dialog component
- Remove X icon import (Dialog includes built-in close button)
- Add Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter imports
- Add Button component import for action buttons
- Update props interface to include isOpen boolean prop
- Restructure component layout:
- Use DialogHeader with DialogTitle for header section
- Apply -mx-6 px-6 pattern for full-width scrollable content
- Use DialogFooter with flex-col sm:flex-row sm:justify-between layout
- Convert custom buttons to Button components:
- Test/Format buttons: variant="outline" size="sm"
- Cancel button: variant="ghost" size="sm"
- Save button: variant="default" size="sm"
- Maintain all existing functionality (preset templates, JSON editor, validation, testing, formatting)
### App.tsx
- Update UsageScriptModal usage to pass isOpen prop
- Use Boolean(usageProvider) to control dialog open state
## Benefits
- **Consistent styling**: All dialogs now use the same shadcn/ui Dialog component
- **Better accessibility**: Automatic focus management, ESC key handling, ARIA attributes
- **Code maintainability**: Reduced custom modal boilerplate, easier to update styling globally
- **User experience**: Unified look and feel across settings, providers, MCP, and usage script dialogs
All TypeScript type checks and Prettier formatting checks pass.
2025-10-16 16:32:50 +08:00
|
|
|
|
isOpen={Boolean(usageProvider)}
|
2025-10-16 10:49:56 +08:00
|
|
|
|
onClose={() => setUsageProvider(null)}
|
|
|
|
|
|
onSave={(script) => {
|
2025-10-17 17:49:16 +08:00
|
|
|
|
void saveUsageScript(usageProvider, script);
|
2025-10-16 10:49:56 +08:00
|
|
|
|
}}
|
2025-08-05 09:51:41 +08:00
|
|
|
|
/>
|
|
|
|
|
|
)}
|
2025-08-06 16:29:52 +08:00
|
|
|
|
|
2025-10-16 10:49:56 +08:00
|
|
|
|
<ConfirmDialog
|
|
|
|
|
|
isOpen={Boolean(confirmDelete)}
|
2025-10-19 11:55:46 +08:00
|
|
|
|
title={t("confirm.deleteProvider")}
|
2025-10-16 10:49:56 +08:00
|
|
|
|
message={
|
|
|
|
|
|
confirmDelete
|
|
|
|
|
|
? t("confirm.deleteProviderMessage", {
|
|
|
|
|
|
name: confirmDelete.name,
|
|
|
|
|
|
})
|
|
|
|
|
|
: ""
|
|
|
|
|
|
}
|
|
|
|
|
|
onConfirm={() => void handleConfirmDelete()}
|
|
|
|
|
|
onCancel={() => setConfirmDelete(null)}
|
|
|
|
|
|
/>
|
2025-09-07 10:48:27 +08:00
|
|
|
|
|
2025-10-16 11:40:02 +08:00
|
|
|
|
<SettingsDialog
|
|
|
|
|
|
open={isSettingsOpen}
|
|
|
|
|
|
onOpenChange={setIsSettingsOpen}
|
|
|
|
|
|
onImportSuccess={handleImportSuccess}
|
|
|
|
|
|
/>
|
2025-10-08 22:35:07 +08:00
|
|
|
|
|
feat(prompts+i18n): add prompt management and improve prompt editor i18n (#193)
* feat(prompts): add prompt management across Tauri service and React UI
- backend: add commands/prompt.rs, services/prompt.rs, register in commands/mod.rs and lib.rs, refine app_config.rs
- frontend: add PromptPanel, PromptFormModal, PromptListItem, MarkdownEditor, usePromptActions, integrate in App.tsx
- api: add src/lib/api/prompts.ts
- i18n: update src/i18n/locales/{en,zh}.json
- build: update package.json and pnpm-lock.yaml
* feat(i18n): improve i18n for prompts and Markdown editor
- update src/i18n/locales/{en,zh}.json keys and strings
- apply i18n in PromptFormModal, PromptPanel, and MarkdownEditor
- align prompt text with src-tauri/src/services/prompt.rs
* feat(prompts): add enable/disable toggle and simplify panel UI
- Add PromptToggle component and integrate in prompt list items
- Implement toggleEnabled with optimistic update; enable via API, disable via upsert with enabled=false;
reload after success
- Simplify PromptPanel: remove file import and current-file preview to keep CRUD flow focused
- Tweak header controls style (use mcp variant) and minor copy: rename “Prompt Management” to “Prompts”
- i18n: add disableSuccess/disableFailed messages
- Backend (Tauri): prevent duplicate backups when importing original prompt content
* style: unify code formatting with trailing commas
* feat(prompts): add Gemini filename support to PromptFormModal
Update filename mapping to use Record<AppId, string> pattern, supporting
GEMINI.md alongside CLAUDE.md and AGENTS.md.
* fix(prompts): sync enabled prompt to file when updating
When updating a prompt that is currently enabled, automatically sync
the updated content to the corresponding live file (CLAUDE.md/AGENTS.md/GEMINI.md).
This ensures the active prompt file always reflects the latest content
when editing enabled prompts.
2025-11-12 16:41:41 +08:00
|
|
|
|
<PromptPanel
|
|
|
|
|
|
open={isPromptOpen}
|
|
|
|
|
|
onOpenChange={setIsPromptOpen}
|
|
|
|
|
|
appId={activeApp}
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
refactor(mcp): complete v3.7.0 cleanup - remove legacy code and warnings
This commit finalizes the v3.7.0 unified MCP architecture migration by
removing all deprecated code paths and eliminating compiler warnings.
Frontend Changes (~950 lines removed):
- Remove deprecated components: McpPanel, McpListItem, McpToggle
- Remove deprecated hook: useMcpActions
- Remove unused API methods: importFrom*, syncEnabledTo*, syncAllServers
- Simplify McpFormModal by removing dual-mode logic (unified/legacy)
- Remove syncOtherSide checkbox and conflict detection
- Clean up unused imports and state variables
- Delete associated test files
Backend Changes (~400 lines cleaned):
- Remove unused Tauri commands: import_mcp_from_*, sync_enabled_mcp_to_*
- Delete unused Gemini MCP functions: get_mcp_status, upsert/delete_mcp_server
- Add #[allow(deprecated)] to compatibility layer commands
- Add #[allow(dead_code)] to legacy helper functions for future migration
- Simplify boolean expression in mcp.rs per Clippy suggestion
API Deprecation:
- Mark legacy APIs with @deprecated JSDoc (getConfig, upsertServerInConfig, etc.)
- Preserve backward compatibility for v3.x, planned removal in v4.0
Verification:
- ✅ Zero TypeScript errors (pnpm typecheck)
- ✅ Zero Clippy warnings (cargo clippy)
- ✅ All code formatted (prettier + cargo fmt)
- ✅ Builds successfully
Total cleanup: ~1,350 lines of code removed/marked
Breaking changes: None (all legacy APIs still functional)
2025-11-14 22:43:25 +08:00
|
|
|
|
<UnifiedMcpPanel open={isMcpOpen} onOpenChange={setIsMcpOpen} />
|
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;
|