From 31cdc2a5cf4103c99c268d130d938d4d9f769fda Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 19 Sep 2025 15:48:35 +0800 Subject: [PATCH] - feat(vscode-sync): restore auto-sync logic and enable by default - refactor(settings): remove the VS Code auto-sync toggle from Settings UI - feat(provider-list): enable auto-sync after "Apply to VS Code"; disable after "Remove" - chore(prettier): run Prettier on changed files - verify: typecheck and renderer build pass - Files - added: src/hooks/useVSCodeAutoSync.ts - modified: src/App.tsx - modified: src/components/ProviderList.tsx - modified: src/components/SettingsModal.tsx - Notes - Auto-sync now defaults to enabled for new users (stored in localStorage; existing saved state is respected). - No settings toggle is shown; manual Apply/Remove in the list still works as before. --- src/App.tsx | 4 ++-- src/components/SettingsModal.tsx | 25 +------------------------ src/hooks/useVSCodeAutoSync.ts | 12 +++++++++--- 3 files changed, 12 insertions(+), 29 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 9025499..3fd7737 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -114,7 +114,7 @@ function App() { unlisten(); } }; - }, [activeApp, isAutoSyncEnabled]); // 依赖自动同步状态,确保拿到最新开关 + }, [activeApp, isAutoSyncEnabled]); const loadProviders = async () => { const loadedProviders = await window.api.getProviders(activeApp); @@ -183,7 +183,7 @@ function App() { }); }; - // 同步Codex供应商到VS Code设置 + // 同步Codex供应商到VS Code设置(静默覆盖) const syncCodexToVSCode = async (providerId: string, silent = false) => { try { const status = await window.api.getVSCodeSettingsStatus(); diff --git a/src/components/SettingsModal.tsx b/src/components/SettingsModal.tsx index e183e29..e4f5b42 100644 --- a/src/components/SettingsModal.tsx +++ b/src/components/SettingsModal.tsx @@ -11,7 +11,6 @@ import { getVersion } from "@tauri-apps/api/app"; import "../lib/tauri-api"; import { relaunchApp } from "../lib/updater"; import { useUpdate } from "../contexts/UpdateContext"; -import { useVSCodeAutoSync } from "../hooks/useVSCodeAutoSync"; import type { Settings } from "../types"; interface SettingsModalProps { @@ -29,7 +28,6 @@ export default function SettingsModal({ onClose }: SettingsModalProps) { const [showUpToDate, setShowUpToDate] = useState(false); const { hasUpdate, updateInfo, updateHandle, checkUpdate, resetDismiss } = useUpdate(); - const { isAutoSyncEnabled, toggleAutoSync } = useVSCodeAutoSync(); useEffect(() => { loadSettings(); @@ -203,28 +201,7 @@ export default function SettingsModal({ onClose }: SettingsModalProps) { */} - {/* VS Code 自动同步设置 */} -
-

- Codex 设置 -

- -
+ {/* VS Code 自动同步设置已移除 */} {/* 配置文件位置 */}
diff --git a/src/hooks/useVSCodeAutoSync.ts b/src/hooks/useVSCodeAutoSync.ts index 42564a4..c762eab 100644 --- a/src/hooks/useVSCodeAutoSync.ts +++ b/src/hooks/useVSCodeAutoSync.ts @@ -4,7 +4,8 @@ const VSCODE_AUTO_SYNC_KEY = "vscode-auto-sync-enabled"; const VSCODE_AUTO_SYNC_EVENT = "vscode-auto-sync-changed"; export function useVSCodeAutoSync() { - const [isAutoSyncEnabled, setIsAutoSyncEnabled] = useState(false); + // 默认开启自动同步;若本地存储存在记录,则以记录为准 + const [isAutoSyncEnabled, setIsAutoSyncEnabled] = useState(true); // 从 localStorage 读取初始状态 useEffect(() => { @@ -22,7 +23,9 @@ export function useVSCodeAutoSync() { useEffect(() => { const onCustom = (e: Event) => { try { - const detail = (e as CustomEvent).detail as { enabled?: boolean } | undefined; + const detail = (e as CustomEvent).detail as + | { enabled?: boolean } + | undefined; if (detail && typeof detail.enabled === "boolean") { setIsAutoSyncEnabled(detail.enabled); } else { @@ -42,7 +45,10 @@ export function useVSCodeAutoSync() { window.addEventListener(VSCODE_AUTO_SYNC_EVENT, onCustom as EventListener); window.addEventListener("storage", onStorage); return () => { - window.removeEventListener(VSCODE_AUTO_SYNC_EVENT, onCustom as EventListener); + window.removeEventListener( + VSCODE_AUTO_SYNC_EVENT, + onCustom as EventListener, + ); window.removeEventListener("storage", onStorage); }; }, []);