feat: Allow to control whether auto check update

This commit is contained in:
MystiPanda 2024-03-11 12:17:46 +08:00
parent 7778d9f773
commit 9f94cad615
4 changed files with 32 additions and 5 deletions

View File

@ -93,6 +93,9 @@ pub struct IVerge {
/// 切换代理时自动关闭连接
pub auto_close_connection: Option<bool>,
/// 是否自动检查更新
pub auto_check_update: Option<bool>,
/// 默认的延迟测试连接
pub default_latency_test: Option<String>,
@ -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);

View File

@ -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<DialogRef>(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;

View File

@ -20,6 +20,7 @@ export const MiscViewer = forwardRef<DialogRef>((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<DialogRef>((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<DialogRef>((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<DialogRef>((props, ref) => {
/>
</ListItem>
<ListItem sx={{ padding: "5px 2px" }}>
<ListItemText primary={t("Auto Check Update")} />
<Switch
edge="end"
checked={values.autoCheckUpdate}
onChange={(_, c) =>
setValues((v) => ({ ...v, autoCheckUpdate: c }))
}
/>
</ListItem>
<ListItem sx={{ padding: "5px 2px" }}>
<ListItemText primary={t("Enable Builtin Enhanced")} />
<Switch

View File

@ -233,6 +233,7 @@ interface IVergeConfig {
css_injection?: string;
};
auto_close_connection?: boolean;
auto_check_update?: boolean;
default_latency_test?: string;
default_latency_timeout?: number;
enable_builtin_enhanced?: boolean;