From 00e3f13bc9029cbf73f74f9fc90bf543185f75a2 Mon Sep 17 00:00:00 2001 From: Tunglies Date: Sun, 18 May 2025 00:52:22 +0800 Subject: [PATCH] fix: profile-view wrong type of http request timeout value --- UPDATELOG.md | 1 + src-tauri/src/core/core.rs | 10 +++- src/components/profile/profile-viewer.tsx | 69 ++++++++++++++--------- 3 files changed, 50 insertions(+), 30 deletions(-) diff --git a/UPDATELOG.md b/UPDATELOG.md index 48fb22225..d1d10b10e 100644 --- a/UPDATELOG.md +++ b/UPDATELOG.md @@ -23,6 +23,7 @@ - 安装服务模式后无法立即开启 TUN 模式 - 同步更新多语言翻译 - 修复 .window-state.json 无法删除的问题 + - 无法修改配置更新 HTTP 请求超时 #### 新增了: - Mihomo(Meta)内核升级至 1.19.8 diff --git a/src-tauri/src/core/core.rs b/src-tauri/src/core/core.rs index bfa7408db..ead5314ce 100644 --- a/src-tauri/src/core/core.rs +++ b/src-tauri/src/core/core.rs @@ -17,9 +17,13 @@ use crate::{ use anyhow::Result; use chrono::Local; use once_cell::sync::OnceCell; -use std::fs::{create_dir_all, File}; -use std::io::Write; -use std::{fmt, path::PathBuf, sync::Arc}; +use std::{ + fmt, + fs::{create_dir_all, File}, + io::Write, + path::PathBuf, + sync::Arc, +}; use tauri_plugin_shell::{process::CommandChild, ShellExt}; use tokio::sync::Mutex; diff --git a/src/components/profile/profile-viewer.tsx b/src/components/profile/profile-viewer.tsx index 6358647c6..60bc064c6 100644 --- a/src/components/profile/profile-viewer.tsx +++ b/src/components/profile/profile-viewer.tsx @@ -89,6 +89,10 @@ export const ProfileViewer = forwardRef( const handleOk = useLockFn( formIns.handleSubmit(async (form) => { + if (form.option?.timeout_seconds) { + form.option.timeout_seconds = +form.option.timeout_seconds; + } + setLoading(true); try { // 基本验证 @@ -106,21 +110,22 @@ export const ProfileViewer = forwardRef( if (form.option?.user_agent === "") { delete form.option.user_agent; } - + const name = form.name || `${form.type} file`; const item = { ...form, name }; const isRemote = form.type === "remote"; const isUpdate = openType === "edit"; - + // 判断是否是当前激活的配置 - const isActivating = isUpdate && form.uid === (profiles?.current ?? ""); - + const isActivating = + isUpdate && form.uid === (profiles?.current ?? ""); + // 保存原始代理设置以便回退成功后恢复 - const originalOptions = { + const originalOptions = { with_proxy: form.option?.with_proxy, - self_proxy: form.option?.self_proxy + self_proxy: form.option?.self_proxy, }; - + // 执行创建或更新操作,本地配置不需要回退机制 if (!isRemote) { if (openType === "new") { @@ -141,46 +146,52 @@ export const ProfileViewer = forwardRef( } } catch (err) { // 首次创建/更新失败,尝试使用自身代理 - showNotice('info', t("Profile creation failed, retrying with Clash proxy...")); - + showNotice( + "info", + t("Profile creation failed, retrying with Clash proxy..."), + ); + // 使用自身代理的配置 const retryItem = { ...item, option: { ...item.option, with_proxy: false, - self_proxy: true - } + self_proxy: true, + }, }; - + // 使用自身代理再次尝试 if (openType === "new") { await createProfile(retryItem, fileDataRef.current); } else { if (!form.uid) throw new Error("UID not found"); await patchProfile(form.uid, retryItem); - + // 编辑模式下恢复原始代理设置 await patchProfile(form.uid, { option: originalOptions }); } - - showNotice('success', t("Profile creation succeeded with Clash proxy")); + + showNotice( + "success", + t("Profile creation succeeded with Clash proxy"), + ); } } - + // 成功后的操作 setOpen(false); setTimeout(() => formIns.reset(), 500); fileDataRef.current = null; - + // 只传递当前配置激活状态,让父组件决定是否需要触发配置重载 props.onChange(isActivating); } catch (err: any) { - showNotice('error', err.message || err.toString()); + showNotice("error", err.message || err.toString()); } finally { setLoading(false); } - }) + }), ); const handleClose = () => { @@ -271,7 +282,7 @@ export const ProfileViewer = forwardRef( /> )} /> - + ( label={t("HTTP Request Timeout")} slotProps={{ input: { - endAdornment: ( - {t("seconds")} - ), - } + endAdornment: ( + + {t("seconds")} + + ), + }, }} /> )} @@ -308,9 +321,11 @@ export const ProfileViewer = forwardRef( slotProps={{ input: { endAdornment: ( - {t("mins")} + + {t("mins")} + ), - } + }, }} /> )} @@ -364,7 +379,7 @@ export const ProfileViewer = forwardRef( )} ); - } + }, ); const StyledBox = styled(Box)(() => ({