From 9f94cad615493794ac1c1763d4932f30d9ceee94 Mon Sep 17 00:00:00 2001 From: MystiPanda Date: Mon, 11 Mar 2024 12:17:46 +0800 Subject: [PATCH] feat: Allow to control whether auto check update --- src-tauri/src/config/verge.rs | 5 +++++ src/components/layout/update-button.tsx | 17 ++++++++++++----- src/components/setting/mods/misc-viewer.tsx | 14 ++++++++++++++ src/services/types.d.ts | 1 + 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src-tauri/src/config/verge.rs b/src-tauri/src/config/verge.rs index 579fde8..b978425 100644 --- a/src-tauri/src/config/verge.rs +++ b/src-tauri/src/config/verge.rs @@ -93,6 +93,9 @@ pub struct IVerge { /// 切换代理时自动关闭连接 pub auto_close_connection: Option, + /// 是否自动检查更新 + pub auto_check_update: Option, + /// 默认的延迟测试连接 pub default_latency_test: Option, @@ -193,6 +196,7 @@ impl IVerge { enable_proxy_guard: Some(false), proxy_guard_duration: Some(30), auto_close_connection: Some(true), + auto_check_update: Some(true), enable_builtin_enhanced: Some(true), auto_log_clean: Some(3), ..Self::default() @@ -249,6 +253,7 @@ impl IVerge { patch!(hotkeys); patch!(auto_close_connection); + patch!(auto_check_update); patch!(default_latency_test); patch!(default_latency_timeout); patch!(enable_builtin_enhanced); diff --git a/src/components/layout/update-button.tsx b/src/components/layout/update-button.tsx index b71ea07..601a890 100644 --- a/src/components/layout/update-button.tsx +++ b/src/components/layout/update-button.tsx @@ -4,6 +4,7 @@ import { Button } from "@mui/material"; import { checkUpdate } from "@tauri-apps/api/updater"; import { UpdateViewer } from "../setting/mods/update-viewer"; import { DialogRef } from "../base"; +import { useVerge } from "@/hooks/use-verge"; interface Props { className?: string; @@ -11,14 +12,20 @@ interface Props { export const UpdateButton = (props: Props) => { const { className } = props; + const { verge } = useVerge(); + const { auto_check_update } = verge || {}; const viewerRef = useRef(null); - const { data: updateInfo } = useSWR("checkUpdate", checkUpdate, { - errorRetryCount: 2, - revalidateIfStale: false, - focusThrottleInterval: 36e5, // 1 hour - }); + const { data: updateInfo } = useSWR( + auto_check_update || auto_check_update === null ? "checkUpdate" : null, + checkUpdate, + { + errorRetryCount: 2, + revalidateIfStale: false, + focusThrottleInterval: 36e5, // 1 hour + } + ); if (!updateInfo?.shouldUpdate) return null; diff --git a/src/components/setting/mods/misc-viewer.tsx b/src/components/setting/mods/misc-viewer.tsx index 024dc67..6e2de5e 100644 --- a/src/components/setting/mods/misc-viewer.tsx +++ b/src/components/setting/mods/misc-viewer.tsx @@ -20,6 +20,7 @@ export const MiscViewer = forwardRef((props, ref) => { const [values, setValues] = useState({ appLogLevel: "info", autoCloseConnection: true, + autoCheckUpdate: true, enableBuiltinEnhanced: true, proxyLayoutColumn: 6, defaultLatencyTest: "", @@ -33,6 +34,7 @@ export const MiscViewer = forwardRef((props, ref) => { setValues({ appLogLevel: verge?.app_log_level ?? "info", autoCloseConnection: verge?.auto_close_connection ?? true, + autoCheckUpdate: verge?.auto_check_update ?? true, enableBuiltinEnhanced: verge?.enable_builtin_enhanced ?? true, proxyLayoutColumn: verge?.proxy_layout_column || 6, defaultLatencyTest: verge?.default_latency_test || "", @@ -48,6 +50,7 @@ export const MiscViewer = forwardRef((props, ref) => { await patchVerge({ app_log_level: values.appLogLevel, auto_close_connection: values.autoCloseConnection, + auto_check_update: values.autoCheckUpdate, enable_builtin_enhanced: values.enableBuiltinEnhanced, proxy_layout_column: values.proxyLayoutColumn, default_latency_test: values.defaultLatencyTest, @@ -104,6 +107,17 @@ export const MiscViewer = forwardRef((props, ref) => { /> + + + + setValues((v) => ({ ...v, autoCheckUpdate: c })) + } + /> + +