Skip to content

Commit

Permalink
fix: clash config select issue, and close #1303
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat616 committed Aug 13, 2024
1 parent 82e06f5 commit eaa85ff
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ end_of_line = lf
indent_size = 2
insert_final_newline = true

[*.lua]
charset = utf-8
indent_size = 4

[*.rs]
charset = utf-8
end_of_line = lf
Expand Down
2 changes: 1 addition & 1 deletion backend/tauri/src/enhance/builtin/clash_rs_comp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ if config["allow_lan"] == true then
config["bind_address"] = "0.0.0.0"
end

return config;
return config
5 changes: 5 additions & 0 deletions backend/tauri/src/enhance/builtin/config_fixer.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if type(config['log-level']) == 'boolean' then
config['log-level'] = 'debug'
end

return config
9 changes: 8 additions & 1 deletion backend/tauri/src/enhance/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
config::{nyanpasu::ClashCore, profile::item_type::ProfileItemType, ProfileItem},
utils::{dirs, help},
};
use enumflags2::BitFlags;
use enumflags2::{BitFlag, BitFlags};
use serde::{Deserialize, Serialize};
use serde_yaml::Mapping;
use std::fs;
Expand Down Expand Up @@ -118,6 +118,12 @@ impl ChainItem {
ChainTypeWrapper::new_js(include_str!("./builtin/meta_hy_alpn.js").to_string()),
);

// 修复配置的一些问题
let config_fixer = ChainItem::to_script(
"config_fixer",
ChainTypeWrapper::new_lua(include_str!("./builtin/config_fixer.lua").to_string()),
);

// 移除或转换 Clash Rs 不支持的字段
let clash_rs_comp = ChainItem::to_script(
"clash_rs_comp",
Expand All @@ -127,6 +133,7 @@ impl ChainItem {
vec![
(ClashCore::Mihomo | ClashCore::MihomoAlpha, hy_alpn),
(ClashCore::Mihomo | ClashCore::MihomoAlpha, meta_guard),
(ClashCore::all(), config_fixer),
(ClashCore::ClashRs.into(), clash_rs_comp),
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const clash = {
selected: getConfigs.data?.[propName] || fallbackSelect,
onSelected: (value: OptionValue) => {
Promise.all([
setClashInfo({ [propName]: !getConfigs.data?.[propName] }),
setClashInfo({ [propName]: value }),
setConfigs({ [propName]: value }),
]).finally(() => {
mutate(
Expand Down

0 comments on commit eaa85ff

Please sign in to comment.