chore: update & fmt & clippy

This commit is contained in:
MystiPanda 2024-06-12 10:00:22 +08:00
parent fb6ffd8e09
commit 75cd7dd4b9
No known key found for this signature in database
18 changed files with 100 additions and 127 deletions

114
src-tauri/Cargo.lock generated
View File

@ -312,9 +312,9 @@ dependencies = [
[[package]] [[package]]
name = "async-signal" name = "async-signal"
version = "0.2.7" version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "329972aa325176e89114919f2a80fdae4f4c040f66a370b1a1159c6c0f94e7aa" checksum = "794f185324c2f00e771cd9f1ae8b5ac68be2ca7abb129a87afd6e86d228bc54d"
dependencies = [ dependencies = [
"async-io 2.3.3", "async-io 2.3.3",
"async-lock 3.4.0", "async-lock 3.4.0",
@ -1985,8 +1985,8 @@ dependencies = [
"aho-corasick 1.1.3", "aho-corasick 1.1.3",
"bstr", "bstr",
"log 0.4.21", "log 0.4.21",
"regex-automata 0.4.6", "regex-automata 0.4.7",
"regex-syntax 0.8.3", "regex-syntax 0.8.4",
] ]
[[package]] [[package]]
@ -2249,12 +2249,12 @@ dependencies = [
[[package]] [[package]]
name = "http-body-util" name = "http-body-util"
version = "0.1.1" version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0475f8b2ac86659c21b64320d5d653f9efe42acd2a4e560073ec61a155a34f1d" checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f"
dependencies = [ dependencies = [
"bytes", "bytes",
"futures-core", "futures-util",
"http 1.1.0", "http 1.1.0",
"http-body 1.0.0", "http-body 1.0.0",
"pin-project-lite", "pin-project-lite",
@ -2268,9 +2268,9 @@ checksum = "21dec9db110f5f872ed9699c3ecf50cf16f423502706ba5c72462e28d3157573"
[[package]] [[package]]
name = "httparse" name = "httparse"
version = "1.8.0" version = "1.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" checksum = "d0e7a4dd27b9476dc40cb050d3632d3bba3a70ddbff012285f7f8559a1e7e545"
[[package]] [[package]]
name = "httpdate" name = "httpdate"
@ -2563,12 +2563,14 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]] [[package]]
name = "idna" name = "idna"
version = "0.5.0" version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" checksum = "4716a3a0933a1d01c2f72450e89596eb51dd34ef3c211ccd875acdf1f8fe47ed"
dependencies = [ dependencies = [
"unicode-bidi", "icu_normalizer",
"unicode-normalization", "icu_properties",
"smallvec",
"utf8_iter",
] ]
[[package]] [[package]]
@ -2581,7 +2583,7 @@ dependencies = [
"globset", "globset",
"log 0.4.21", "log 0.4.21",
"memchr", "memchr",
"regex-automata 0.4.6", "regex-automata 0.4.7",
"same-file", "same-file",
"walkdir", "walkdir",
"winapi-util", "winapi-util",
@ -2711,7 +2713,7 @@ checksum = "c416c05ba2a10240e022887617af3128fccdbf69713214da0fc81a5690d00df7"
dependencies = [ dependencies = [
"ahash", "ahash",
"once_cell", "once_cell",
"regex 1.10.4", "regex 1.10.5",
] ]
[[package]] [[package]]
@ -4338,14 +4340,14 @@ dependencies = [
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.10.4" version = "1.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f"
dependencies = [ dependencies = [
"aho-corasick 1.1.3", "aho-corasick 1.1.3",
"memchr", "memchr",
"regex-automata 0.4.6", "regex-automata 0.4.7",
"regex-syntax 0.8.3", "regex-syntax 0.8.4",
] ]
[[package]] [[package]]
@ -4359,13 +4361,13 @@ dependencies = [
[[package]] [[package]]
name = "regex-automata" name = "regex-automata"
version = "0.4.6" version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df"
dependencies = [ dependencies = [
"aho-corasick 1.1.3", "aho-corasick 1.1.3",
"memchr", "memchr",
"regex-syntax 0.8.3", "regex-syntax 0.8.4",
] ]
[[package]] [[package]]
@ -4385,9 +4387,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
[[package]] [[package]]
name = "regex-syntax" name = "regex-syntax"
version = "0.8.3" version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
[[package]] [[package]]
name = "regress" name = "regress"
@ -5381,7 +5383,7 @@ checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f"
[[package]] [[package]]
name = "tauri" name = "tauri"
version = "1.6.7" version = "1.6.7"
source = "git+https://github.com/tauri-apps/tauri?branch=1.x#3752eb1e6be2a8c31ea5519b5f1886d5721e4435" source = "git+https://github.com/tauri-apps/tauri?branch=1.x#d2786bf699ffca1d5e9c234a3b1b4d5ec173af87"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"base64 0.21.7", "base64 0.21.7",
@ -5414,7 +5416,7 @@ dependencies = [
"png", "png",
"rand 0.8.5", "rand 0.8.5",
"raw-window-handle", "raw-window-handle",
"regex 1.10.4", "regex 1.10.5",
"reqwest 0.11.27", "reqwest 0.11.27",
"rfd", "rfd",
"semver 1.0.23", "semver 1.0.23",
@ -5444,7 +5446,7 @@ dependencies = [
[[package]] [[package]]
name = "tauri-build" name = "tauri-build"
version = "1.5.2" version = "1.5.2"
source = "git+https://github.com/tauri-apps/tauri?branch=1.x#3752eb1e6be2a8c31ea5519b5f1886d5721e4435" source = "git+https://github.com/tauri-apps/tauri?branch=1.x#d2786bf699ffca1d5e9c234a3b1b4d5ec173af87"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"cargo_toml", "cargo_toml",
@ -5462,7 +5464,7 @@ dependencies = [
[[package]] [[package]]
name = "tauri-codegen" name = "tauri-codegen"
version = "1.4.3" version = "1.4.3"
source = "git+https://github.com/tauri-apps/tauri?branch=1.x#3752eb1e6be2a8c31ea5519b5f1886d5721e4435" source = "git+https://github.com/tauri-apps/tauri?branch=1.x#d2786bf699ffca1d5e9c234a3b1b4d5ec173af87"
dependencies = [ dependencies = [
"base64 0.21.7", "base64 0.21.7",
"brotli", "brotli",
@ -5472,7 +5474,7 @@ dependencies = [
"png", "png",
"proc-macro2", "proc-macro2",
"quote", "quote",
"regex 1.10.4", "regex 1.10.5",
"semver 1.0.23", "semver 1.0.23",
"serde", "serde",
"serde_json", "serde_json",
@ -5487,7 +5489,7 @@ dependencies = [
[[package]] [[package]]
name = "tauri-macros" name = "tauri-macros"
version = "1.4.4" version = "1.4.4"
source = "git+https://github.com/tauri-apps/tauri?branch=1.x#3752eb1e6be2a8c31ea5519b5f1886d5721e4435" source = "git+https://github.com/tauri-apps/tauri?branch=1.x#d2786bf699ffca1d5e9c234a3b1b4d5ec173af87"
dependencies = [ dependencies = [
"heck 0.5.0", "heck 0.5.0",
"proc-macro2", "proc-macro2",
@ -5500,7 +5502,7 @@ dependencies = [
[[package]] [[package]]
name = "tauri-runtime" name = "tauri-runtime"
version = "0.14.3" version = "0.14.3"
source = "git+https://github.com/tauri-apps/tauri?branch=1.x#3752eb1e6be2a8c31ea5519b5f1886d5721e4435" source = "git+https://github.com/tauri-apps/tauri?branch=1.x#d2786bf699ffca1d5e9c234a3b1b4d5ec173af87"
dependencies = [ dependencies = [
"gtk", "gtk",
"http 0.2.12", "http 0.2.12",
@ -5520,7 +5522,7 @@ dependencies = [
[[package]] [[package]]
name = "tauri-runtime-wry" name = "tauri-runtime-wry"
version = "0.14.8" version = "0.14.8"
source = "git+https://github.com/tauri-apps/tauri?branch=1.x#3752eb1e6be2a8c31ea5519b5f1886d5721e4435" source = "git+https://github.com/tauri-apps/tauri?branch=1.x#d2786bf699ffca1d5e9c234a3b1b4d5ec173af87"
dependencies = [ dependencies = [
"arboard", "arboard",
"cocoa 0.24.1", "cocoa 0.24.1",
@ -5540,7 +5542,7 @@ dependencies = [
[[package]] [[package]]
name = "tauri-utils" name = "tauri-utils"
version = "1.5.4" version = "1.5.4"
source = "git+https://github.com/tauri-apps/tauri?branch=1.x#3752eb1e6be2a8c31ea5519b5f1886d5721e4435" source = "git+https://github.com/tauri-apps/tauri?branch=1.x#d2786bf699ffca1d5e9c234a3b1b4d5ec173af87"
dependencies = [ dependencies = [
"brotli", "brotli",
"ctor", "ctor",
@ -5651,7 +5653,7 @@ dependencies = [
"num-derive", "num-derive",
"num-traits", "num-traits",
"ordered-float", "ordered-float",
"regex 1.10.4", "regex 1.10.5",
"semver 0.11.0", "semver 0.11.0",
"sha2 0.9.9", "sha2 0.9.9",
"signal-hook", "signal-hook",
@ -5780,21 +5782,6 @@ dependencies = [
"zerovec", "zerovec",
] ]
[[package]]
name = "tinyvec"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50"
dependencies = [
"tinyvec_macros",
]
[[package]]
name = "tinyvec_macros"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "1.38.0" version = "1.38.0"
@ -6030,7 +6017,7 @@ dependencies = [
"matchers", "matchers",
"nu-ansi-term", "nu-ansi-term",
"once_cell", "once_cell",
"regex 1.10.4", "regex 1.10.5",
"sharded-slab", "sharded-slab",
"smallvec", "smallvec",
"thread_local 1.1.8", "thread_local 1.1.8",
@ -6125,27 +6112,12 @@ dependencies = [
"version_check", "version_check",
] ]
[[package]]
name = "unicode-bidi"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75"
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.12" version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "unicode-normalization"
version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5"
dependencies = [
"tinyvec",
]
[[package]] [[package]]
name = "unicode-segmentation" name = "unicode-segmentation"
version = "1.11.0" version = "1.11.0"
@ -6175,9 +6147,9 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
[[package]] [[package]]
name = "url" name = "url"
version = "2.5.0" version = "2.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" checksum = "f7c25da092f0a868cdf09e8674cd3b7ef3a7d92a24253e663a2fb85e2496de56"
dependencies = [ dependencies = [
"form_urlencoded", "form_urlencoded",
"idna", "idna",
@ -6606,7 +6578,7 @@ version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aac48ef20ddf657755fdcda8dfed2a7b4fc7e4581acce6fe9b88c3d64f29dee7" checksum = "aac48ef20ddf657755fdcda8dfed2a7b4fc7e4581acce6fe9b88c3d64f29dee7"
dependencies = [ dependencies = [
"regex 1.10.4", "regex 1.10.5",
"serde", "serde",
"serde_json", "serde_json",
"thiserror", "thiserror",
@ -7255,12 +7227,12 @@ checksum = "213b7324336b53d2414b2db8537e56544d981803139155afa84f76eeebb7a546"
[[package]] [[package]]
name = "xdg-home" name = "xdg-home"
version = "1.1.0" version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21e5a325c3cb8398ad6cf859c1135b25dd29e186679cf2da7581d9679f63b38e" checksum = "ca91dcf8f93db085f3a0a29358cd0b9d670915468f4290e8b85d118a34211ab8"
dependencies = [ dependencies = [
"libc", "libc",
"winapi", "windows-sys 0.52.0",
] ]
[[package]] [[package]]

View File

@ -327,7 +327,7 @@ pub fn copy_icon_file(path: String, name: String) -> CmdResult<String> {
Err(err) => Err(err.to_string()), Err(err) => Err(err.to_string()),
} }
} else { } else {
return Err("file not found".to_string()); Err("file not found".to_string())
} }
} }

View File

@ -1,4 +1,5 @@
mod clash; mod clash;
#[allow(clippy::module_inception)]
mod config; mod config;
mod draft; mod draft;
mod prfitem; mod prfitem;

View File

@ -103,7 +103,9 @@ impl PrfOption {
a.user_agent = b.user_agent.or(a.user_agent); a.user_agent = b.user_agent.or(a.user_agent);
a.with_proxy = b.with_proxy.or(a.with_proxy); a.with_proxy = b.with_proxy.or(a.with_proxy);
a.self_proxy = b.self_proxy.or(a.self_proxy); a.self_proxy = b.self_proxy.or(a.self_proxy);
a.danger_accept_invalid_certs = b.danger_accept_invalid_certs.or(a.danger_accept_invalid_certs); a.danger_accept_invalid_certs = b
.danger_accept_invalid_certs
.or(a.danger_accept_invalid_certs);
a.update_interval = b.update_interval.or(a.update_interval); a.update_interval = b.update_interval.or(a.update_interval);
Some(a) Some(a)
} }
@ -182,7 +184,8 @@ impl PrfItem {
let opt_ref = option.as_ref(); let opt_ref = option.as_ref();
let with_proxy = opt_ref.map_or(false, |o| o.with_proxy.unwrap_or(false)); let with_proxy = opt_ref.map_or(false, |o| o.with_proxy.unwrap_or(false));
let self_proxy = opt_ref.map_or(false, |o| o.self_proxy.unwrap_or(false)); let self_proxy = opt_ref.map_or(false, |o| o.self_proxy.unwrap_or(false));
let accept_invalid_certs = opt_ref.map_or(false, |o| o.danger_accept_invalid_certs.unwrap_or(false)); let accept_invalid_certs =
opt_ref.map_or(false, |o| o.danger_accept_invalid_certs.unwrap_or(false));
let user_agent = opt_ref.and_then(|o| o.user_agent.clone()); let user_agent = opt_ref.and_then(|o| o.user_agent.clone());
let update_interval = opt_ref.and_then(|o| o.update_interval); let update_interval = opt_ref.and_then(|o| o.update_interval);
@ -300,7 +303,7 @@ impl PrfItem {
Some(value) => { Some(value) => {
let str_value = value.to_str().unwrap_or(""); let str_value = value.to_str().unwrap_or("");
Some(str_value.to_string()) Some(str_value.to_string())
}, }
None => None, None => None,
}; };

View File

@ -116,12 +116,12 @@ impl CoreManager {
// 服务模式启动失败就直接运行sidecar // 服务模式启动失败就直接运行sidecar
log::debug!(target: "app", "try to run core in service mode"); log::debug!(target: "app", "try to run core in service mode");
match (|| async { let res = async {
service::check_service().await?; service::check_service().await?;
service::run_core_by_service(&config_path).await service::run_core_by_service(&config_path).await
})() }
.await .await;
{ match res {
Ok(_) => return Ok(()), Ok(_) => return Ok(()),
Err(err) => { Err(err) => {
// 修改这个值免得stop出错 // 修改这个值免得stop出错

View File

@ -43,7 +43,7 @@ impl Hotkey {
} }
} }
} }
*self.current.lock() = hotkeys.clone(); self.current.lock().clone_from(hotkeys);
} }
Ok(()) Ok(())
@ -142,7 +142,7 @@ impl Hotkey {
}); });
new_map.iter().for_each(|(&key, &func)| { new_map.iter().for_each(|(&key, &func)| {
if old_map.get(key).is_none() { if !old_map.contains_key(key) {
add_list.push((key, func)); add_list.push((key, func));
} }
}); });

View File

@ -22,7 +22,8 @@ pub fn grant_permission(core: String) -> anyhow::Result<()> {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
let output = { let output = {
let path = path.replace(' ', "\\ "); // 避免路径中有空格 let path = path.replace(' ', "\\ "); // 避免路径中有空格
let shell = format!("setcap cap_net_bind_service,cap_net_admin,cap_dac_override=+ep {path}"); let shell =
format!("setcap cap_net_bind_service,cap_net_admin,cap_dac_override=+ep {path}");
let sudo = match Command::new("which").arg("pkexec").output() { let sudo = match Command::new("which").arg("pkexec").output() {
Ok(output) => { Ok(output) => {

View File

@ -1,13 +1,14 @@
pub mod clash_api; pub mod clash_api;
#[allow(clippy::module_inception)]
mod core; mod core;
pub mod handle; pub mod handle;
pub mod hotkey; pub mod hotkey;
pub mod logger; pub mod logger;
pub mod manager; pub mod manager;
pub mod service;
pub mod sysopt; pub mod sysopt;
pub mod timer; pub mod timer;
pub mod tray; pub mod tray;
pub mod service;
pub mod win_uwp; pub mod win_uwp;
pub use self::core::*; pub use self::core::*;

View File

@ -44,11 +44,12 @@ static DEFAULT_BYPASS: &str =
fn get_bypass() -> String { fn get_bypass() -> String {
let bypass = DEFAULT_BYPASS.to_string(); let bypass = DEFAULT_BYPASS.to_string();
let custom_bypass = match { let res = {
let verge = Config::verge(); let verge = Config::verge();
let verge = verge.latest(); let verge = verge.latest();
verge.system_proxy_bypass.clone() verge.system_proxy_bypass.clone()
} { };
let custom_bypass = match res {
Some(bypass) => bypass, Some(bypass) => bypass,
None => "".to_string(), None => "".to_string(),
}; };
@ -65,7 +66,7 @@ fn get_bypass() -> String {
format!("{},{}", bypass, custom_bypass) format!("{},{}", bypass, custom_bypass)
}; };
bypass.into() bypass
} }
impl Sysopt { impl Sysopt {
@ -152,19 +153,18 @@ impl Sysopt {
verge.proxy_auto_config.unwrap_or(false), verge.proxy_auto_config.unwrap_or(false),
) )
}; };
if pac { if pac && (cur_autoproxy.is_none() || old_autoproxy.is_none()) {
if cur_autoproxy.is_none() || old_autoproxy.is_none() { drop(cur_autoproxy);
drop(cur_autoproxy); drop(old_autoproxy);
drop(old_autoproxy); return self.init_sysproxy();
return self.init_sysproxy();
}
} else {
if cur_sysproxy.is_none() || old_sysproxy.is_none() {
drop(cur_sysproxy);
drop(old_sysproxy);
return self.init_sysproxy();
}
} }
if !pac && (cur_sysproxy.is_none() || old_sysproxy.is_none()) {
drop(cur_sysproxy);
drop(old_sysproxy);
return self.init_sysproxy();
}
let port = Config::verge() let port = Config::verge()
.latest() .latest()
.verge_mixed_port .verge_mixed_port

View File

@ -88,13 +88,13 @@ impl ChainItem {
impl ChainSupport { impl ChainSupport {
pub fn is_support(&self, core: Option<&String>) -> bool { pub fn is_support(&self, core: Option<&String>) -> bool {
match core { match core {
Some(core) => match (self, core.as_str()) { Some(core) => matches!(
(ChainSupport::All, _) => true, (self, core.as_str()),
(ChainSupport::Clash, "clash") => true, (ChainSupport::All, _)
(ChainSupport::ClashMeta, "clash-meta") => true, | (ChainSupport::Clash, "clash")
(ChainSupport::ClashMetaAlpha, "clash-meta-alpha") => true, | (ChainSupport::ClashMeta, "clash-meta")
_ => false, | (ChainSupport::ClashMetaAlpha, "clash-meta-alpha")
}, ),
None => true, None => true,
} }
} }

View File

@ -60,11 +60,7 @@ pub fn use_sort(config: Mapping) -> Mapping {
let supported_keys: HashSet<&str> = HANDLE_FIELDS.into_iter().chain(DEFAULT_FIELDS).collect(); let supported_keys: HashSet<&str> = HANDLE_FIELDS.into_iter().chain(DEFAULT_FIELDS).collect();
let config_keys: HashSet<&str> = config let config_keys: HashSet<&str> = config.keys().filter_map(|e| e.as_str()).collect();
.keys()
.filter_map(|e| e.as_str())
.into_iter()
.collect();
config_keys.difference(&supported_keys).for_each(|&key| { config_keys.difference(&supported_keys).for_each(|&key| {
let key = Value::from(key); let key = Value::from(key);

View File

@ -12,7 +12,7 @@ const MERGE_FIELDS: [&str; 6] = [
fn deep_merge(a: &mut Value, b: &Value) { fn deep_merge(a: &mut Value, b: &Value) {
match (a, b) { match (a, b) {
(&mut Value::Mapping(ref mut a), &Value::Mapping(ref b)) => { (&mut Value::Mapping(ref mut a), Value::Mapping(b)) => {
for (k, v) in b { for (k, v) in b {
deep_merge(a.entry(k.clone()).or_insert(Value::Null), v); deep_merge(a.entry(k.clone()).or_insert(Value::Null), v);
} }

View File

@ -136,17 +136,15 @@ pub fn enhance() -> (Mapping, Vec<String>, HashMap<String, ResultLog>) {
.map(|(_, c)| c) .map(|(_, c)| c)
.for_each(|item| { .for_each(|item| {
log::debug!(target: "app", "run builtin script {}", item.uid); log::debug!(target: "app", "run builtin script {}", item.uid);
if let ChainType::Script(script) = item.data {
match item.data { match use_script(script, config.to_owned()) {
ChainType::Script(script) => match use_script(script, config.to_owned()) {
Ok((res_config, _)) => { Ok((res_config, _)) => {
config = res_config; config = res_config;
} }
Err(err) => { Err(err) => {
log::error!(target: "app", "builtin script error `{err}`"); log::error!(target: "app", "builtin script error `{err}`");
} }
}, }
_ => {}
} }
}); });
} }
@ -155,7 +153,7 @@ pub fn enhance() -> (Mapping, Vec<String>, HashMap<String, ResultLog>) {
config = use_sort(config); config = use_sort(config);
let mut exists_set = HashSet::new(); let mut exists_set = HashSet::new();
exists_set.extend(exists_keys.into_iter()); exists_set.extend(exists_keys);
exists_keys = exists_set.into_iter().collect(); exists_keys = exists_set.into_iter().collect();
(config, exists_keys, result_map) (config, exists_keys, result_map)

View File

@ -16,7 +16,7 @@ pub fn use_script(script: String, config: Mapping) -> Result<(Mapping, Vec<(Stri
2, 2,
NativeFunction::from_closure( NativeFunction::from_closure(
move |_: &JsValue, args: &[JsValue], context: &mut Context| { move |_: &JsValue, args: &[JsValue], context: &mut Context| {
let level = args.get(0).unwrap().to_string(context)?; let level = args.first().unwrap().to_string(context)?;
let level = level.to_std_string().unwrap(); let level = level.to_std_string().unwrap();
let data = args.get(1).unwrap().to_string(context)?; let data = args.get(1).unwrap().to_string(context)?;
let data = data.to_std_string().unwrap(); let data = data.to_std_string().unwrap();

View File

@ -106,7 +106,7 @@ pub fn toggle_tun_mode() {
pub async fn patch_clash(patch: Mapping) -> Result<()> { pub async fn patch_clash(patch: Mapping) -> Result<()> {
Config::clash().draft().patch_config(patch.clone()); Config::clash().draft().patch_config(patch.clone());
match { let res = {
let redir_port = patch.get("redir-port"); let redir_port = patch.get("redir-port");
let tproxy_port = patch.get("tproxy-port"); let tproxy_port = patch.get("tproxy-port");
let mixed_port = patch.get("mixed-port"); let mixed_port = patch.get("mixed-port");
@ -156,7 +156,8 @@ pub async fn patch_clash(patch: Mapping) -> Result<()> {
Config::runtime().latest().patch_config(patch); Config::runtime().latest().patch_config(patch);
<Result<()>>::Ok(()) <Result<()>>::Ok(())
} { };
match res {
Ok(()) => { Ok(()) => {
Config::clash().apply(); Config::clash().apply();
Config::clash().data().save_config()?; Config::clash().data().save_config()?;
@ -193,7 +194,7 @@ pub async fn patch_verge(patch: IVerge) -> Result<()> {
let tproxy_enabled = patch.verge_tproxy_enabled; let tproxy_enabled = patch.verge_tproxy_enabled;
let socks_enabled = patch.verge_socks_enabled; let socks_enabled = patch.verge_socks_enabled;
let http_enabled = patch.verge_http_enabled; let http_enabled = patch.verge_http_enabled;
match { let res = {
let service_mode = patch.enable_service_mode; let service_mode = patch.enable_service_mode;
if service_mode.is_some() { if service_mode.is_some() {
@ -255,7 +256,8 @@ pub async fn patch_verge(patch: IVerge) -> Result<()> {
} }
<Result<()>>::Ok(()) <Result<()>>::Ok(())
} { };
match res {
Ok(()) => { Ok(()) => {
Config::verge().apply(); Config::verge().apply();
Config::verge().data().save_file()?; Config::verge().data().save_file()?;

View File

@ -137,7 +137,7 @@ pub fn delete_log() -> Result<()> {
} }
let service_log_dir = log_dir.join("service"); let service_log_dir = log_dir.join("service");
for file in fs::read_dir(&service_log_dir)?.flatten() { for file in fs::read_dir(service_log_dir)?.flatten() {
let _ = process_file(file); let _ = process_file(file);
} }
@ -318,11 +318,11 @@ pub fn startup_script() -> Result<()> {
Some(dir) => { Some(dir) => {
let _ = Command::new(shell) let _ = Command::new(shell)
.current_dir(dir.to_path_buf()) .current_dir(dir.to_path_buf())
.args(&[path]) .args([path])
.output()?; .output()?;
} }
None => { None => {
let _ = Command::new(shell).args(&[path]).output()?; let _ = Command::new(shell).args([path]).output()?;
} }
} }
} }

View File

@ -205,7 +205,6 @@ pub fn create_window(app_handle: &AppHandle) {
} }
Err(_) => { Err(_) => {
log::error!("failed to create window"); log::error!("failed to create window");
return;
} }
} }
} }

View File

@ -30,7 +30,7 @@ pub fn check_singleton() -> Result<()> {
let param = argvs[1].as_str(); let param = argvs[1].as_str();
if param.starts_with("clash:") { if param.starts_with("clash:") {
reqwest::get(format!( reqwest::get(format!(
"http://127.0.0.1:{port}/commands/scheme?param={param}" "http://127.0.0.1:{port}/commands/scheme?param={param}"
)) ))
.await? .await?
.text() .text()