mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-19 02:12:10 +08:00
style: adjust rustfmt max_width to 120
This commit is contained in:
@@ -47,11 +47,7 @@ async fn finalize_restored_verge_config(
|
||||
// Ensure side-effects (flags, tray, sysproxy, hotkeys, auto-backup refresh, etc.) run.
|
||||
// Use not_save_file = true to avoid extra I/O (we already persisted the restored file).
|
||||
if let Err(err) = super::patch_verge(&restored, true).await {
|
||||
logging!(
|
||||
error,
|
||||
Type::Backup,
|
||||
"Failed to apply restored verge config: {err:#?}"
|
||||
);
|
||||
logging!(error, Type::Backup, "Failed to apply restored verge config: {err:#?}");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -83,28 +79,17 @@ pub async fn create_backup_and_upload_webdav() -> Result<()> {
|
||||
/// List WebDAV backups
|
||||
pub async fn list_wevdav_backup() -> Result<Vec<ListFile>> {
|
||||
backup::WebDavClient::global().list().await.map_err(|err| {
|
||||
logging!(
|
||||
error,
|
||||
Type::Backup,
|
||||
"Failed to list WebDAV backup files: {err:#?}"
|
||||
);
|
||||
logging!(error, Type::Backup, "Failed to list WebDAV backup files: {err:#?}");
|
||||
err
|
||||
})
|
||||
}
|
||||
|
||||
/// Delete WebDAV backup
|
||||
pub async fn delete_webdav_backup(filename: String) -> Result<()> {
|
||||
backup::WebDavClient::global()
|
||||
.delete(filename)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
logging!(
|
||||
error,
|
||||
Type::Backup,
|
||||
"Failed to delete WebDAV backup file: {err:#?}"
|
||||
);
|
||||
err
|
||||
})
|
||||
backup::WebDavClient::global().delete(filename).await.map_err(|err| {
|
||||
logging!(error, Type::Backup, "Failed to delete WebDAV backup file: {err:#?}");
|
||||
err
|
||||
})
|
||||
}
|
||||
|
||||
/// Restore WebDAV backup
|
||||
@@ -122,11 +107,7 @@ pub async fn restore_webdav_backup(filename: String) -> Result<()> {
|
||||
.download(filename, backup_storage_path.clone())
|
||||
.await
|
||||
.map_err(|err| {
|
||||
logging!(
|
||||
error,
|
||||
Type::Backup,
|
||||
"Failed to download WebDAV backup file: {err:#?}"
|
||||
);
|
||||
logging!(error, Type::Backup, "Failed to download WebDAV backup file: {err:#?}");
|
||||
err
|
||||
})?;
|
||||
|
||||
@@ -153,11 +134,7 @@ where
|
||||
F: FnOnce(&str) -> String,
|
||||
{
|
||||
let (file_name, temp_file_path) = backup::create_backup().await.map_err(|err| {
|
||||
logging!(
|
||||
error,
|
||||
Type::Backup,
|
||||
"Failed to create local backup: {err:#?}"
|
||||
);
|
||||
logging!(error, Type::Backup, "Failed to create local backup: {err:#?}");
|
||||
err
|
||||
})?;
|
||||
|
||||
@@ -166,11 +143,7 @@ where
|
||||
let target_path = backup_dir.join(final_name.as_str());
|
||||
|
||||
if let Err(err) = move_file(temp_file_path.clone(), target_path.clone()).await {
|
||||
logging!(
|
||||
error,
|
||||
Type::Backup,
|
||||
"Failed to move local backup file: {err:#?}"
|
||||
);
|
||||
logging!(error, Type::Backup, "Failed to move local backup file: {err:#?}");
|
||||
// 清理临时文件
|
||||
if let Err(clean_err) = temp_file_path.remove_if_exists().await {
|
||||
logging!(
|
||||
@@ -251,12 +224,7 @@ pub async fn delete_local_backup(filename: String) -> Result<()> {
|
||||
let backup_dir = local_backup_dir()?;
|
||||
let target_path = backup_dir.join(filename.as_str());
|
||||
if !target_path.exists() {
|
||||
logging!(
|
||||
warn,
|
||||
Type::Backup,
|
||||
"Local backup file not found: {}",
|
||||
filename
|
||||
);
|
||||
logging!(warn, Type::Backup, "Local backup file not found: {}", filename);
|
||||
return Ok(());
|
||||
}
|
||||
target_path.remove_if_exists().await?;
|
||||
|
||||
@@ -75,16 +75,10 @@ pub async fn change_clash_mode(mode: String) {
|
||||
"mode": mode
|
||||
});
|
||||
logging!(debug, Type::Core, "change clash mode to {mode}");
|
||||
match handle::Handle::mihomo()
|
||||
.await
|
||||
.patch_base_config(&json_value)
|
||||
.await
|
||||
{
|
||||
match handle::Handle::mihomo().await.patch_base_config(&json_value).await {
|
||||
Ok(_) => {
|
||||
// 更新订阅
|
||||
Config::clash()
|
||||
.await
|
||||
.edit_draft(|d| d.patch_config(&mapping));
|
||||
Config::clash().await.edit_draft(|d| d.patch_config(&mapping));
|
||||
|
||||
// 分离数据获取和异步调用
|
||||
let clash_data = Config::clash().await.data_arc();
|
||||
@@ -99,11 +93,7 @@ pub async fn change_clash_mode(mode: String) {
|
||||
);
|
||||
}
|
||||
|
||||
let is_auto_close_connection = Config::verge()
|
||||
.await
|
||||
.data_arc()
|
||||
.auto_close_connection
|
||||
.unwrap_or(false);
|
||||
let is_auto_close_connection = Config::verge().await.data_arc().auto_close_connection.unwrap_or(false);
|
||||
if is_auto_close_connection {
|
||||
after_change_clash_mode();
|
||||
}
|
||||
@@ -117,11 +107,7 @@ pub async fn test_delay(url: String) -> anyhow::Result<u32> {
|
||||
use crate::utils::network::{NetworkManager, ProxyType};
|
||||
use tokio::time::Instant;
|
||||
|
||||
let tun_mode = Config::verge()
|
||||
.await
|
||||
.latest_arc()
|
||||
.enable_tun_mode
|
||||
.unwrap_or(false);
|
||||
let tun_mode = Config::verge().await.latest_arc().enable_tun_mode.unwrap_or(false);
|
||||
|
||||
// 如果是TUN模式,不使用代理,否则使用自身代理
|
||||
let proxy_type = if !tun_mode {
|
||||
|
||||
@@ -27,9 +27,7 @@ pub async fn patch_clash(patch: &Mapping) -> Result<()> {
|
||||
.await
|
||||
);
|
||||
}
|
||||
Config::runtime()
|
||||
.await
|
||||
.edit_draft(|d| d.patch_config(patch));
|
||||
Config::runtime().await.edit_draft(|d| d.patch_config(patch));
|
||||
CoreManager::global().update_config().await?;
|
||||
}
|
||||
handle::Handle::refresh_clash();
|
||||
@@ -257,10 +255,7 @@ pub async fn patch_verge(patch: &IVerge, not_save_file: bool) -> Result<()> {
|
||||
return Err(err);
|
||||
}
|
||||
Config::verge().await.apply();
|
||||
logging_error!(
|
||||
Type::Backup,
|
||||
AutoBackupManager::global().refresh_settings().await
|
||||
);
|
||||
logging_error!(Type::Backup, AutoBackupManager::global().refresh_settings().await);
|
||||
if !not_save_file {
|
||||
// 分离数据获取和异步调用
|
||||
let verge_data = Config::verge().await.data_arc();
|
||||
|
||||
@@ -23,13 +23,7 @@ pub async fn switch_proxy_node(group_name: &str, proxy_name: &str) {
|
||||
.await
|
||||
{
|
||||
Ok(_) => {
|
||||
logging!(
|
||||
info,
|
||||
Type::Tray,
|
||||
"切换代理成功: {} -> {}",
|
||||
group_name,
|
||||
proxy_name
|
||||
);
|
||||
logging!(info, Type::Tray, "切换代理成功: {} -> {}", group_name, proxy_name);
|
||||
let _ = handle::Handle::app_handle().emit("verge://refresh-proxy-config", ());
|
||||
let _ = tray::Tray::global().update_menu().await;
|
||||
return;
|
||||
@@ -52,13 +46,7 @@ pub async fn switch_proxy_node(group_name: &str, proxy_name: &str) {
|
||||
.await
|
||||
{
|
||||
Ok(_) => {
|
||||
logging!(
|
||||
info,
|
||||
Type::Tray,
|
||||
"代理切换回退成功: {} -> {}",
|
||||
group_name,
|
||||
proxy_name
|
||||
);
|
||||
logging!(info, Type::Tray, "代理切换回退成功: {} -> {}", group_name, proxy_name);
|
||||
let _ = tray::Tray::global().update_menu().await;
|
||||
}
|
||||
Err(err) => {
|
||||
@@ -74,42 +62,20 @@ pub async fn switch_proxy_node(group_name: &str, proxy_name: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
async fn should_update_profile(
|
||||
uid: &String,
|
||||
ignore_auto_update: bool,
|
||||
) -> Result<Option<(String, Option<PrfOption>)>> {
|
||||
async fn should_update_profile(uid: &String, ignore_auto_update: bool) -> Result<Option<(String, Option<PrfOption>)>> {
|
||||
let profiles = Config::profiles().await;
|
||||
let profiles = profiles.latest_arc();
|
||||
let item = profiles.get_item(uid)?;
|
||||
let is_remote = item.itype.as_ref().is_some_and(|s| s == "remote");
|
||||
|
||||
if !is_remote {
|
||||
logging!(
|
||||
info,
|
||||
Type::Config,
|
||||
"[订阅更新] {uid} 不是远程订阅,跳过更新"
|
||||
);
|
||||
logging!(info, Type::Config, "[订阅更新] {uid} 不是远程订阅,跳过更新");
|
||||
Ok(None)
|
||||
} else if item.url.is_none() {
|
||||
logging!(
|
||||
warn,
|
||||
Type::Config,
|
||||
"Warning: [订阅更新] {uid} 缺少URL,无法更新"
|
||||
);
|
||||
logging!(warn, Type::Config, "Warning: [订阅更新] {uid} 缺少URL,无法更新");
|
||||
bail!("failed to get the profile item url");
|
||||
} else if !ignore_auto_update
|
||||
&& !item
|
||||
.option
|
||||
.as_ref()
|
||||
.and_then(|o| o.allow_auto_update)
|
||||
.unwrap_or(true)
|
||||
{
|
||||
logging!(
|
||||
info,
|
||||
Type::Config,
|
||||
"[订阅更新] {} 禁止自动更新,跳过更新",
|
||||
uid
|
||||
);
|
||||
} else if !ignore_auto_update && !item.option.as_ref().and_then(|o| o.allow_auto_update).unwrap_or(true) {
|
||||
logging!(info, Type::Config, "[订阅更新] {} 禁止自动更新,跳过更新", uid);
|
||||
Ok(None)
|
||||
} else {
|
||||
logging!(
|
||||
@@ -122,9 +88,7 @@ async fn should_update_profile(
|
||||
.ok_or_else(|| anyhow::anyhow!("Profile URL is None"))?
|
||||
);
|
||||
Ok(Some((
|
||||
item.url
|
||||
.clone()
|
||||
.ok_or_else(|| anyhow::anyhow!("Profile URL is None"))?,
|
||||
item.url.clone().ok_or_else(|| anyhow::anyhow!("Profile URL is None"))?,
|
||||
item.option.clone(),
|
||||
)))
|
||||
}
|
||||
@@ -172,11 +136,7 @@ async fn perform_profile_update(
|
||||
|
||||
match PrfItem::from_url(url, None, None, merged_opt.as_ref()).await {
|
||||
Ok(mut item) => {
|
||||
logging!(
|
||||
info,
|
||||
Type::Config,
|
||||
"[订阅更新] 使用 Clash代理 更新订阅配置成功"
|
||||
);
|
||||
logging!(info, Type::Config, "[订阅更新] 使用 Clash代理 更新订阅配置成功");
|
||||
profiles_draft_update_item_safe(uid, &mut item).await?;
|
||||
handle::Handle::notice_message("update_with_clash_proxy", profile_name);
|
||||
drop(last_err);
|
||||
@@ -197,11 +157,7 @@ async fn perform_profile_update(
|
||||
|
||||
match PrfItem::from_url(url, None, None, merged_opt.as_ref()).await {
|
||||
Ok(mut item) => {
|
||||
logging!(
|
||||
info,
|
||||
Type::Config,
|
||||
"[订阅更新] 使用 系统代理 更新订阅配置成功"
|
||||
);
|
||||
logging!(info, Type::Config, "[订阅更新] 使用 系统代理 更新订阅配置成功");
|
||||
profiles_draft_update_item_safe(uid, &mut item).await?;
|
||||
handle::Handle::notice_message("update_with_clash_proxy", profile_name);
|
||||
drop(last_err);
|
||||
@@ -217,10 +173,7 @@ async fn perform_profile_update(
|
||||
}
|
||||
}
|
||||
|
||||
handle::Handle::notice_message(
|
||||
"update_failed_even_with_clash",
|
||||
format!("{profile_name} - {last_err}"),
|
||||
);
|
||||
handle::Handle::notice_message("update_failed_even_with_clash", format!("{profile_name} - {last_err}"));
|
||||
Ok(is_current)
|
||||
}
|
||||
|
||||
@@ -234,9 +187,7 @@ pub async fn update_profile(
|
||||
let url_opt = should_update_profile(uid, ignore_auto_update).await?;
|
||||
|
||||
let should_refresh = match url_opt {
|
||||
Some((url, opt)) => {
|
||||
perform_profile_update(uid, &url, opt.as_ref(), option).await? && auto_refresh
|
||||
}
|
||||
Some((url, opt)) => perform_profile_update(uid, &url, opt.as_ref(), option).await? && auto_refresh,
|
||||
None => auto_refresh,
|
||||
};
|
||||
|
||||
|
||||
@@ -17,11 +17,7 @@ pub async fn toggle_system_proxy() {
|
||||
&& auto_close_connection
|
||||
&& let Err(err) = handle::Handle::mihomo().await.close_all_connections().await
|
||||
{
|
||||
logging!(
|
||||
error,
|
||||
Type::ProxyMode,
|
||||
"Failed to close all connections: {err}"
|
||||
);
|
||||
logging!(error, Type::ProxyMode, "Failed to close all connections: {err}");
|
||||
}
|
||||
|
||||
let patch_result = super::patch_verge(
|
||||
@@ -86,9 +82,7 @@ pub async fn copy_clash_env() {
|
||||
let env_type = verge_cfg.env_type.as_deref().unwrap_or(default_env);
|
||||
|
||||
let export_text = match env_type {
|
||||
"bash" => format!(
|
||||
"export https_proxy={http_proxy} http_proxy={http_proxy} all_proxy={socks5_proxy}"
|
||||
),
|
||||
"bash" => format!("export https_proxy={http_proxy} http_proxy={http_proxy} all_proxy={socks5_proxy}"),
|
||||
"cmd" => format!("set http_proxy={http_proxy}\r\nset https_proxy={http_proxy}"),
|
||||
"powershell" => {
|
||||
format!("$env:HTTP_PROXY=\"{http_proxy}\"; $env:HTTPS_PROXY=\"{http_proxy}\"")
|
||||
@@ -98,11 +92,7 @@ pub async fn copy_clash_env() {
|
||||
}
|
||||
"fish" => format!("set -x http_proxy {http_proxy}; set -x https_proxy {http_proxy}"),
|
||||
_ => {
|
||||
logging!(
|
||||
error,
|
||||
Type::ProxyMode,
|
||||
"copy_clash_env: Invalid env type! {env_type}"
|
||||
);
|
||||
logging!(error, Type::ProxyMode, "copy_clash_env: Invalid env type! {env_type}");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -51,11 +51,7 @@ pub async fn clean_async() -> bool {
|
||||
use winapi::um::winuser::{GetSystemMetrics, SM_SHUTTINGDOWN};
|
||||
|
||||
// 检查系统代理是否开启
|
||||
let sys_proxy_enabled = Config::verge()
|
||||
.await
|
||||
.data_arc()
|
||||
.enable_system_proxy
|
||||
.unwrap_or(false);
|
||||
let sys_proxy_enabled = Config::verge().await.data_arc().enable_system_proxy.unwrap_or(false);
|
||||
|
||||
if !sys_proxy_enabled {
|
||||
logging!(info, Type::Window, "系统代理未启用,跳过重置");
|
||||
@@ -67,11 +63,7 @@ pub async fn clean_async() -> bool {
|
||||
|
||||
if is_shutting_down {
|
||||
// sysproxy-rs 操作注册表(避免.exe的dll错误)
|
||||
logging!(
|
||||
info,
|
||||
Type::Window,
|
||||
"检测到正在关机,syspro-rs操作注册表关闭系统代理"
|
||||
);
|
||||
logging!(info, Type::Window, "检测到正在关机,syspro-rs操作注册表关闭系统代理");
|
||||
|
||||
match Sysproxy::get_system_proxy() {
|
||||
Ok(mut sysproxy) => {
|
||||
@@ -99,12 +91,7 @@ pub async fn clean_async() -> bool {
|
||||
// 正常退出:使用 sysproxy.exe 重置代理
|
||||
logging!(info, Type::Window, "sysproxy.exe重置系统代理");
|
||||
|
||||
match timeout(
|
||||
Duration::from_secs(2),
|
||||
sysopt::Sysopt::global().reset_sysproxy(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
match timeout(Duration::from_secs(2), sysopt::Sysopt::global().reset_sysproxy()).await {
|
||||
Ok(Ok(_)) => {
|
||||
logging!(info, Type::Window, "系统代理已重置");
|
||||
true
|
||||
@@ -114,11 +101,7 @@ pub async fn clean_async() -> bool {
|
||||
true
|
||||
}
|
||||
Err(_) => {
|
||||
logging!(
|
||||
warn,
|
||||
Type::Window,
|
||||
"Warning: 重置系统代理超时,继续退出流程"
|
||||
);
|
||||
logging!(warn, Type::Window, "Warning: 重置系统代理超时,继续退出流程");
|
||||
true
|
||||
}
|
||||
}
|
||||
@@ -127,11 +110,7 @@ pub async fn clean_async() -> bool {
|
||||
// 非 Windows 平台:正常重置代理
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
{
|
||||
let sys_proxy_enabled = Config::verge()
|
||||
.await
|
||||
.data_arc()
|
||||
.enable_system_proxy
|
||||
.unwrap_or(false);
|
||||
let sys_proxy_enabled = Config::verge().await.data_arc().enable_system_proxy.unwrap_or(false);
|
||||
|
||||
if !sys_proxy_enabled {
|
||||
logging!(info, Type::Window, "系统代理未启用,跳过重置");
|
||||
@@ -140,12 +119,7 @@ pub async fn clean_async() -> bool {
|
||||
|
||||
logging!(info, Type::Window, "开始重置系统代理...");
|
||||
|
||||
match timeout(
|
||||
Duration::from_millis(1500),
|
||||
sysopt::Sysopt::global().reset_sysproxy(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
match timeout(Duration::from_millis(1500), sysopt::Sysopt::global().reset_sysproxy()).await {
|
||||
Ok(Ok(_)) => {
|
||||
logging!(info, Type::Window, "系统代理已重置");
|
||||
true
|
||||
@@ -165,20 +139,14 @@ pub async fn clean_async() -> bool {
|
||||
// 关闭 Tun 模式 + 停止核心服务
|
||||
let core_task = tokio::task::spawn(async {
|
||||
logging!(info, Type::System, "disable tun");
|
||||
let tun_enabled = Config::verge()
|
||||
.await
|
||||
.data_arc()
|
||||
.enable_tun_mode
|
||||
.unwrap_or(false);
|
||||
let tun_enabled = Config::verge().await.data_arc().enable_tun_mode.unwrap_or(false);
|
||||
if tun_enabled {
|
||||
let disable_tun = serde_json::json!({ "tun": { "enable": false } });
|
||||
|
||||
logging!(info, Type::System, "send disable tun request to mihomo");
|
||||
match timeout(
|
||||
Duration::from_millis(1000),
|
||||
handle::Handle::mihomo()
|
||||
.await
|
||||
.patch_base_config(&disable_tun),
|
||||
handle::Handle::mihomo().await.patch_base_config(&disable_tun),
|
||||
)
|
||||
.await
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user