Skip to content

Commit

Permalink
fix: patch clash config issue
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat616 committed Sep 15, 2024
1 parent cf61bb7 commit ef5b767
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
16 changes: 8 additions & 8 deletions backend/tauri/src/config/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use serde_yaml::Mapping;

use crate::enhance::Logs;

pub const RUNTIME_PATCHABLE_KEYS: [&str; 4] = ["allow-lan", "ipv6", "log-level", "mode"];

#[derive(Default, Debug, Clone, Deserialize, Serialize)]
pub struct IRuntime {
pub config: Option<Mapping>,
Expand All @@ -18,17 +20,15 @@ impl IRuntime {
Self::default()
}

// 这里只更改 allow-lan | ipv6 | log-level
// 这里只更改 allow-lan | ipv6 | log-level | mode
pub fn patch_config(&mut self, patch: Mapping) {
tracing::debug!("patching runtime config: {:?}", patch);
if let Some(config) = self.config.as_mut() {
["allow-lan", "ipv6", "log-level"]
.into_iter()
.for_each(|key| {
if let Some(value) = patch.get(key).to_owned() {
config.insert(key.into(), value.clone());
}
});
RUNTIME_PATCHABLE_KEYS.iter().for_each(|key| {
if let Some(value) = patch.get(*key).to_owned() {
config.insert(key.to_string().into(), value.clone());
}
});
}
}
}
6 changes: 6 additions & 0 deletions backend/tauri/src/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ pub async fn get_ipsb_asn() -> CmdResult<Mapping> {
#[tracing_attributes::instrument]
pub async fn patch_clash_config(payload: Mapping) -> CmdResult {
tracing::debug!("patch_clash_config: {payload:?}");
if RUNTIME_PATCHABLE_KEYS
.iter()
.any(|key| payload.contains_key(key))
{
wrap_err!(crate::core::clash::api::patch_configs(&payload).await);
}
if let Err(e) = feat::patch_clash(payload).await {
tracing::error!("{e}");
return Err(format!("{e}"));
Expand Down
9 changes: 4 additions & 5 deletions frontend/nyanpasu/src/pages/proxies.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useAtom } from "jotai";
import { RefObject, useEffect, useRef, useState } from "react";
import { RefObject, useEffect, useMemo, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import ContentDisplay from "@/components/base/content-display";
import {
Expand Down Expand Up @@ -95,11 +95,10 @@ export default function ProxyPage() {

const nodeListRef = useRef<NodeListRef>(null);

const Header = () => {
const Header = useMemo(() => {
const handleSwitch = (key: string) => {
setCurrentMode(key);
};

return (
<Box display="flex" alignItems="center" gap={1}>
<ButtonGroup size="small">
Expand All @@ -117,7 +116,7 @@ export default function ProxyPage() {
</ButtonGroup>
</Box>
);
};
}, [getCurrentMode, setCurrentMode, t]);

const leftViewportRef = useRef<HTMLDivElement>(null);

Expand All @@ -126,7 +125,7 @@ export default function ProxyPage() {
return (
<SidePage
title={t("Proxy Groups")}
header={<Header />}
header={Header}
sideBar={<SideBar />}
leftViewportRef={leftViewportRef}
rightViewportRef={rightViewportRef}
Expand Down

0 comments on commit ef5b767

Please sign in to comment.