Revert "fix: improve VS Code config toggle handling with async state management"
This reverts commit 32e66e054b.
This commit is contained in:
@@ -33,7 +33,6 @@ const CodexConfigEditor: React.FC<CodexConfigEditorProps> = ({
|
|||||||
const [writeVscodeConfig, setWriteVscodeConfig] = useState(false);
|
const [writeVscodeConfig, setWriteVscodeConfig] = useState(false);
|
||||||
const [vscodeError, setVscodeError] = useState("");
|
const [vscodeError, setVscodeError] = useState("");
|
||||||
const [vscodeSuccess, setVscodeSuccess] = useState("");
|
const [vscodeSuccess, setVscodeSuccess] = useState("");
|
||||||
const [isWritingVscode, setIsWritingVscode] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (commonConfigError && !isCommonConfigModalOpen) {
|
if (commonConfigError && !isCommonConfigModalOpen) {
|
||||||
@@ -49,20 +48,20 @@ const CodexConfigEditor: React.FC<CodexConfigEditorProps> = ({
|
|||||||
return () => window.clearTimeout(timer);
|
return () => window.clearTimeout(timer);
|
||||||
}, [vscodeSuccess]);
|
}, [vscodeSuccess]);
|
||||||
|
|
||||||
const handleVscodeConfigToggle = async (checked: boolean) => {
|
// 监听 writeVscodeConfig 变化并执行写入
|
||||||
if (isWritingVscode) return;
|
useEffect(() => {
|
||||||
|
if (!writeVscodeConfig) return;
|
||||||
|
|
||||||
setWriteVscodeConfig(checked);
|
const performWrite = async () => {
|
||||||
setVscodeError("");
|
setVscodeError("");
|
||||||
setVscodeSuccess("");
|
setVscodeSuccess("");
|
||||||
|
|
||||||
if (typeof window === "undefined" || !window.api?.writeVscodeSettings) {
|
if (typeof window === "undefined" || !window.api?.writeVscodeSettings) {
|
||||||
setVscodeError("当前环境暂不支持写入 VS Code 配置");
|
setVscodeError("当前环境暂不支持写入 VS Code 配置");
|
||||||
setWriteVscodeConfig(!checked);
|
setWriteVscodeConfig(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checked) {
|
|
||||||
const trimmed = configValue.trim();
|
const trimmed = configValue.trim();
|
||||||
if (!trimmed) {
|
if (!trimmed) {
|
||||||
setVscodeError("请先填写 config.toml,再写入 VS Code 配置");
|
setVscodeError("请先填写 config.toml,再写入 VS Code 配置");
|
||||||
@@ -77,7 +76,6 @@ const CodexConfigEditor: React.FC<CodexConfigEditorProps> = ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setIsWritingVscode(true);
|
|
||||||
try {
|
try {
|
||||||
const success = await window.api.writeVscodeSettings(baseUrl);
|
const success = await window.api.writeVscodeSettings(baseUrl);
|
||||||
if (success) {
|
if (success) {
|
||||||
@@ -89,29 +87,11 @@ const CodexConfigEditor: React.FC<CodexConfigEditorProps> = ({
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
setVscodeError(`写入 VS Code 配置失败: ${String(error)}`);
|
setVscodeError(`写入 VS Code 配置失败: ${String(error)}`);
|
||||||
setWriteVscodeConfig(false);
|
setWriteVscodeConfig(false);
|
||||||
} finally {
|
|
||||||
setIsWritingVscode(false);
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return;
|
performWrite();
|
||||||
}
|
}, [writeVscodeConfig, configValue]);
|
||||||
|
|
||||||
setIsWritingVscode(true);
|
|
||||||
try {
|
|
||||||
const success = await window.api.writeVscodeSettings();
|
|
||||||
if (success) {
|
|
||||||
setVscodeSuccess("已移除 VS Code 配置");
|
|
||||||
} else {
|
|
||||||
setVscodeError("移除 VS Code 配置失败,请稍后重试");
|
|
||||||
setWriteVscodeConfig(true);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
setVscodeError(`移除 VS Code 配置失败: ${String(error)}`);
|
|
||||||
setWriteVscodeConfig(true);
|
|
||||||
} finally {
|
|
||||||
setIsWritingVscode(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// 支持按下 ESC 关闭弹窗
|
// 支持按下 ESC 关闭弹窗
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -188,8 +168,7 @@ const CodexConfigEditor: React.FC<CodexConfigEditorProps> = ({
|
|||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
checked={writeVscodeConfig}
|
checked={writeVscodeConfig}
|
||||||
onChange={(e) => handleVscodeConfigToggle(e.target.checked)}
|
onChange={(e) => setWriteVscodeConfig(e.target.checked)}
|
||||||
disabled={isWritingVscode}
|
|
||||||
className="w-4 h-4 text-blue-500 bg-white dark:bg-gray-800 border-gray-200 dark:border-gray-700 rounded focus:ring-blue-500 dark:focus:ring-blue-400 focus:ring-2"
|
className="w-4 h-4 text-blue-500 bg-white dark:bg-gray-800 border-gray-200 dark:border-gray-700 rounded focus:ring-blue-500 dark:focus:ring-blue-400 focus:ring-2"
|
||||||
/>
|
/>
|
||||||
写入 VS Code 配置
|
写入 VS Code 配置
|
||||||
|
|||||||
Reference in New Issue
Block a user