- 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.
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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) {
|
||||
</label>
|
||||
</div> */}
|
||||
|
||||
{/* VS Code 自动同步设置 */}
|
||||
<div>
|
||||
<h3 className="text-sm font-medium text-gray-900 dark:text-gray-100 mb-3">
|
||||
Codex 设置
|
||||
</h3>
|
||||
<label className="flex items-center justify-between cursor-pointer">
|
||||
<div className="flex-1">
|
||||
<span className="text-sm text-gray-700 dark:text-gray-300">
|
||||
自动同步到 VS Code
|
||||
</span>
|
||||
<p className="text-xs text-gray-500 dark:text-gray-400 mt-0.5">
|
||||
切换 Codex 供应商时自动更新 VS Code 配置
|
||||
</p>
|
||||
</div>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={isAutoSyncEnabled}
|
||||
onChange={toggleAutoSync}
|
||||
className="w-4 h-4 text-blue-500 rounded focus:ring-blue-500/20"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
{/* VS Code 自动同步设置已移除 */}
|
||||
|
||||
{/* 配置文件位置 */}
|
||||
<div>
|
||||
|
||||
@@ -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<boolean>(false);
|
||||
// 默认开启自动同步;若本地存储存在记录,则以记录为准
|
||||
const [isAutoSyncEnabled, setIsAutoSyncEnabled] = useState<boolean>(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);
|
||||
};
|
||||
}, []);
|
||||
|
||||
Reference in New Issue
Block a user