mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-04 22:52:23 +08:00
style: adjust rustfmt max_width to 120
This commit is contained in:
@@ -28,8 +28,7 @@ pub fn get_startup_dir() -> Result<PathBuf> {
|
||||
/// 获取当前可执行文件路径
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn get_exe_path() -> Result<PathBuf> {
|
||||
let exe_path =
|
||||
std::env::current_exe().map_err(|e| anyhow!("无法获取当前可执行文件路径: {}", e))?;
|
||||
let exe_path = std::env::current_exe().map_err(|e| anyhow!("无法获取当前可执行文件路径: {}", e))?;
|
||||
|
||||
Ok(exe_path)
|
||||
}
|
||||
|
||||
@@ -60,11 +60,7 @@ pub fn app_home_dir() -> Result<PathBuf> {
|
||||
match app_handle.path().data_dir() {
|
||||
Ok(dir) => Ok(dir.join(APP_ID)),
|
||||
Err(e) => {
|
||||
logging!(
|
||||
error,
|
||||
Type::File,
|
||||
"Failed to get the app home directory: {e}"
|
||||
);
|
||||
logging!(error, Type::File, "Failed to get the app home directory: {e}");
|
||||
Err(anyhow::anyhow!("Failed to get the app homedirectory"))
|
||||
}
|
||||
}
|
||||
@@ -78,11 +74,7 @@ pub fn app_resources_dir() -> Result<PathBuf> {
|
||||
match app_handle.path().resource_dir() {
|
||||
Ok(dir) => Ok(dir.join("resources")),
|
||||
Err(e) => {
|
||||
logging!(
|
||||
error,
|
||||
Type::File,
|
||||
"Failed to get the resource directory: {e}"
|
||||
);
|
||||
logging!(error, Type::File, "Failed to get the resource directory: {e}");
|
||||
Err(anyhow::anyhow!("Failed to get the resource directory"))
|
||||
}
|
||||
}
|
||||
@@ -110,15 +102,11 @@ pub fn find_target_icons(target: &str) -> Result<Option<String>> {
|
||||
let ext_matches = path
|
||||
.extension()
|
||||
.and_then(|e| e.to_str())
|
||||
.is_some_and(|ext| {
|
||||
ext.eq_ignore_ascii_case("ico") || ext.eq_ignore_ascii_case("png")
|
||||
});
|
||||
.is_some_and(|ext| ext.eq_ignore_ascii_case("ico") || ext.eq_ignore_ascii_case("png"));
|
||||
prefix_matches && ext_matches
|
||||
});
|
||||
|
||||
icon_path
|
||||
.map(|path| path_to_str(&path).map(|s| s.into()))
|
||||
.transpose()
|
||||
icon_path.map(|path| path_to_str(&path).map(|s| s.into())).transpose()
|
||||
}
|
||||
|
||||
/// logs dir
|
||||
@@ -179,9 +167,7 @@ pub fn service_log_dir() -> Result<PathBuf> {
|
||||
pub fn clash_latest_log() -> Result<PathBuf> {
|
||||
match *CoreManager::global().get_running_mode() {
|
||||
RunningMode::Service => Ok(service_log_dir()?.join("service_latest.log")),
|
||||
RunningMode::Sidecar | RunningMode::NotRunning => {
|
||||
Ok(sidecar_log_dir()?.join("sidecar_latest.log"))
|
||||
}
|
||||
RunningMode::Sidecar | RunningMode::NotRunning => Ok(sidecar_log_dir()?.join("sidecar_latest.log")),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,12 +193,10 @@ pub fn get_encryption_key() -> Result<Vec<u8>> {
|
||||
|
||||
// Ensure directory exists
|
||||
if let Some(parent) = key_path.parent() {
|
||||
fs::create_dir_all(parent)
|
||||
.map_err(|e| anyhow::anyhow!("Failed to create key directory: {}", e))?;
|
||||
fs::create_dir_all(parent).map_err(|e| anyhow::anyhow!("Failed to create key directory: {}", e))?;
|
||||
}
|
||||
// Save key
|
||||
fs::write(&key_path, &key)
|
||||
.map_err(|e| anyhow::anyhow!("Failed to save encryption key: {}", e))?;
|
||||
fs::write(&key_path, &key).map_err(|e| anyhow::anyhow!("Failed to save encryption key: {}", e))?;
|
||||
Ok(key)
|
||||
}
|
||||
}
|
||||
@@ -228,11 +212,7 @@ pub fn ensure_mihomo_safe_dir() -> Option<PathBuf> {
|
||||
if home_config.exists() || fs::create_dir_all(&home_config).is_ok() {
|
||||
Some(home_config)
|
||||
} else {
|
||||
logging!(
|
||||
error,
|
||||
Type::File,
|
||||
"Failed to create safe directory: {home_config:?}"
|
||||
);
|
||||
logging!(error, Type::File, "Failed to create safe directory: {home_config:?}");
|
||||
None
|
||||
}
|
||||
})
|
||||
|
||||
@@ -35,19 +35,14 @@ pub async fn read_mapping(path: &PathBuf) -> Result<Mapping> {
|
||||
|
||||
Ok(val
|
||||
.as_mapping()
|
||||
.ok_or_else(|| {
|
||||
anyhow!("failed to transform to yaml mapping \"{}\"", path.display())
|
||||
})?
|
||||
.ok_or_else(|| anyhow!("failed to transform to yaml mapping \"{}\"", path.display()))?
|
||||
.to_owned())
|
||||
}
|
||||
Err(err) => {
|
||||
let error_msg = format!("YAML syntax error in {}: {}", path.display(), err);
|
||||
logging!(error, Type::Config, "{}", error_msg);
|
||||
|
||||
crate::core::handle::Handle::notice_message(
|
||||
"config_validate::yaml_syntax_error",
|
||||
&error_msg,
|
||||
);
|
||||
crate::core::handle::Handle::notice_message("config_validate::yaml_syntax_error", &error_msg);
|
||||
|
||||
bail!("YAML syntax error: {}", err)
|
||||
}
|
||||
@@ -61,11 +56,7 @@ pub async fn read_seq_map(path: &PathBuf) -> Result<SeqMap> {
|
||||
|
||||
/// save the data to the file
|
||||
/// can set `prefix` string to add some comments
|
||||
pub async fn save_yaml<T: Serialize + Sync>(
|
||||
path: &PathBuf,
|
||||
data: &T,
|
||||
prefix: Option<&str>,
|
||||
) -> Result<()> {
|
||||
pub async fn save_yaml<T: Serialize + Sync>(path: &PathBuf, data: &T, prefix: Option<&str>) -> Result<()> {
|
||||
let data_str = with_encryption(|| async { serde_yaml_ng::to_string(data) }).await?;
|
||||
|
||||
let yaml_str = match prefix {
|
||||
@@ -82,10 +73,9 @@ pub async fn save_yaml<T: Serialize + Sync>(
|
||||
}
|
||||
|
||||
const ALPHABET: [char; 62] = [
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
|
||||
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B',
|
||||
'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
|
||||
'V', 'W', 'X', 'Y', 'Z',
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
||||
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
|
||||
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
||||
];
|
||||
|
||||
/// generate the uid
|
||||
|
||||
@@ -50,11 +50,9 @@ fn resolve_supported_language(language: &str) -> Option<String> {
|
||||
|
||||
let supported = supported_languages_internal();
|
||||
|
||||
candidates.into_iter().find(|candidate| {
|
||||
supported
|
||||
.iter()
|
||||
.any(|&lang| lang.eq_ignore_ascii_case(candidate))
|
||||
})
|
||||
candidates
|
||||
.into_iter()
|
||||
.find(|candidate| supported.iter().any(|&lang| lang.eq_ignore_ascii_case(candidate)))
|
||||
}
|
||||
|
||||
fn system_language() -> String {
|
||||
@@ -72,8 +70,7 @@ pub fn get_supported_languages() -> Vec<String> {
|
||||
}
|
||||
|
||||
pub fn set_locale(language: &str) {
|
||||
let lang =
|
||||
resolve_supported_language(language).unwrap_or_else(|| fallback_language().to_string());
|
||||
let lang = resolve_supported_language(language).unwrap_or_else(|| fallback_language().to_string());
|
||||
rust_i18n::set_locale(&lang);
|
||||
}
|
||||
|
||||
|
||||
@@ -223,14 +223,8 @@ async fn init_dns_config() -> Result<()> {
|
||||
("enable".into(), Value::Bool(true)),
|
||||
("listen".into(), Value::String(":53".into())),
|
||||
("enhanced-mode".into(), Value::String("fake-ip".into())),
|
||||
(
|
||||
"fake-ip-range".into(),
|
||||
Value::String("198.18.0.1/16".into()),
|
||||
),
|
||||
(
|
||||
"fake-ip-filter-mode".into(),
|
||||
Value::String("blacklist".into()),
|
||||
),
|
||||
("fake-ip-range".into(), Value::String("198.18.0.1/16".into())),
|
||||
("fake-ip-filter-mode".into(), Value::String("blacklist".into())),
|
||||
("prefer-h3".into(), Value::Bool(false)),
|
||||
("respect-rules".into(), Value::Bool(false)),
|
||||
("use-hosts".into(), Value::Bool(false)),
|
||||
@@ -310,10 +304,7 @@ async fn init_dns_config() -> Result<()> {
|
||||
// 获取默认DNS和host配置
|
||||
let default_dns_config = serde_yaml_ng::Mapping::from_iter([
|
||||
("dns".into(), Value::Mapping(dns_config)),
|
||||
(
|
||||
"hosts".into(),
|
||||
Value::Mapping(serde_yaml_ng::Mapping::new()),
|
||||
),
|
||||
("hosts".into(), Value::Mapping(serde_yaml_ng::Mapping::new())),
|
||||
]);
|
||||
|
||||
// 检查DNS配置文件是否存在
|
||||
@@ -322,12 +313,7 @@ async fn init_dns_config() -> Result<()> {
|
||||
|
||||
if !dns_path.exists() {
|
||||
logging!(info, Type::Setup, "Creating default DNS config file");
|
||||
help::save_yaml(
|
||||
&dns_path,
|
||||
&default_dns_config,
|
||||
Some("# Clash Verge DNS Config"),
|
||||
)
|
||||
.await?;
|
||||
help::save_yaml(&dns_path, &default_dns_config, Some("# Clash Verge DNS Config")).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -343,9 +329,9 @@ async fn ensure_directories() -> Result<()> {
|
||||
|
||||
for (name, dir) in directories {
|
||||
if !dir.exists() {
|
||||
fs::create_dir_all(&dir).await.map_err(|e| {
|
||||
anyhow::anyhow!("Failed to create {} directory {:?}: {}", name, dir, e)
|
||||
})?;
|
||||
fs::create_dir_all(&dir)
|
||||
.await
|
||||
.map_err(|e| anyhow::anyhow!("Failed to create {} directory {:?}: {}", name, dir, e))?;
|
||||
logging!(info, Type::Setup, "Created {} directory: {:?}", name, dir);
|
||||
}
|
||||
}
|
||||
@@ -535,10 +521,7 @@ pub async fn startup_script() -> Result<()> {
|
||||
} else if script_path.ends_with(".ps1") || script_path.ends_with(".bat") {
|
||||
"powershell"
|
||||
} else {
|
||||
return Err(anyhow::anyhow!(
|
||||
"unsupported script extension: {}",
|
||||
script_path
|
||||
));
|
||||
return Err(anyhow::anyhow!("unsupported script extension: {}", script_path));
|
||||
};
|
||||
|
||||
let script_dir = PathBuf::from(script_path.as_str());
|
||||
|
||||
@@ -79,15 +79,9 @@ struct SessionEnv {
|
||||
|
||||
impl SessionEnv {
|
||||
fn gather() -> Self {
|
||||
let desktop_env = env::var("XDG_CURRENT_DESKTOP")
|
||||
.unwrap_or_default()
|
||||
.to_uppercase();
|
||||
let session_desktop = env::var("XDG_SESSION_DESKTOP")
|
||||
.unwrap_or_default()
|
||||
.to_uppercase();
|
||||
let desktop_session = env::var("DESKTOP_SESSION")
|
||||
.unwrap_or_default()
|
||||
.to_uppercase();
|
||||
let desktop_env = env::var("XDG_CURRENT_DESKTOP").unwrap_or_default().to_uppercase();
|
||||
let session_desktop = env::var("XDG_SESSION_DESKTOP").unwrap_or_default().to_uppercase();
|
||||
let desktop_session = env::var("DESKTOP_SESSION").unwrap_or_default().to_uppercase();
|
||||
|
||||
let is_kde_plasma = desktop_env.contains("KDE")
|
||||
|| session_desktop.contains("KDE")
|
||||
@@ -95,9 +89,8 @@ impl SessionEnv {
|
||||
|| desktop_env.contains("PLASMA")
|
||||
|| session_desktop.contains("PLASMA")
|
||||
|| desktop_session.contains("PLASMA");
|
||||
let is_hyprland = desktop_env.contains("HYPR")
|
||||
|| session_desktop.contains("HYPR")
|
||||
|| desktop_session.contains("HYPR");
|
||||
let is_hyprland =
|
||||
desktop_env.contains("HYPR") || session_desktop.contains("HYPR") || desktop_session.contains("HYPR");
|
||||
let is_wayland = env::var("XDG_SESSION_TYPE")
|
||||
.map(|value| value.eq_ignore_ascii_case("wayland"))
|
||||
.unwrap_or(false)
|
||||
@@ -128,13 +121,14 @@ struct DmabufOverrides {
|
||||
|
||||
impl DmabufOverrides {
|
||||
fn gather() -> Self {
|
||||
let user_preference = env::var("CLASH_VERGE_DMABUF").ok().and_then(|value| {
|
||||
match value.trim().to_ascii_lowercase().as_str() {
|
||||
"1" | "true" | "enable" | "on" => Some(true),
|
||||
"0" | "false" | "disable" | "off" => Some(false),
|
||||
_ => None,
|
||||
}
|
||||
});
|
||||
let user_preference =
|
||||
env::var("CLASH_VERGE_DMABUF")
|
||||
.ok()
|
||||
.and_then(|value| match value.trim().to_ascii_lowercase().as_str() {
|
||||
"1" | "true" | "enable" | "on" => Some(true),
|
||||
"0" | "false" | "disable" | "off" => Some(false),
|
||||
_ => None,
|
||||
});
|
||||
let dmabuf_override = env::var("WEBKIT_DISABLE_DMABUF_RENDERER").ok();
|
||||
|
||||
Self {
|
||||
@@ -185,13 +179,11 @@ impl DmabufDecision {
|
||||
match overrides.user_preference {
|
||||
Some(true) => {
|
||||
decision.enable_dmabuf = true;
|
||||
decision.message =
|
||||
Some("CLASH_VERGE_DMABUF=1: 强制启用 WebKit DMABUF 渲染。".into());
|
||||
decision.message = Some("CLASH_VERGE_DMABUF=1: 强制启用 WebKit DMABUF 渲染。".into());
|
||||
}
|
||||
Some(false) => {
|
||||
decision.enable_dmabuf = false;
|
||||
decision.message =
|
||||
Some("CLASH_VERGE_DMABUF=0: 强制禁用 WebKit DMABUF 渲染。".into());
|
||||
decision.message = Some("CLASH_VERGE_DMABUF=0: 强制禁用 WebKit DMABUF 渲染。".into());
|
||||
if session.is_wayland && !session.prefer_native_wayland {
|
||||
decision.force_x11_backend = true;
|
||||
}
|
||||
@@ -200,10 +192,8 @@ impl DmabufDecision {
|
||||
if overrides.has_env_override() {
|
||||
if overrides.dmabuf_override.as_deref() == Some("1") {
|
||||
decision.enable_dmabuf = false;
|
||||
decision.message = Some(
|
||||
"检测到 WEBKIT_DISABLE_DMABUF_RENDERER=1,沿用用户的软件渲染配置。"
|
||||
.into(),
|
||||
);
|
||||
decision.message =
|
||||
Some("检测到 WEBKIT_DISABLE_DMABUF_RENDERER=1,沿用用户的软件渲染配置。".into());
|
||||
if session.is_wayland && !session.prefer_native_wayland {
|
||||
decision.force_x11_backend = true;
|
||||
}
|
||||
@@ -230,14 +220,18 @@ impl DmabufDecision {
|
||||
})
|
||||
.unwrap_or_else(|| String::from("NVIDIA Open Kernel Module"));
|
||||
let message = match reason {
|
||||
NvidiaDmabufDisableReason::PrimaryOpenKernelModule => format!(
|
||||
"Wayland 会话检测到 {}:禁用 WebKit DMABUF 渲染以规避协议错误。",
|
||||
summary
|
||||
),
|
||||
NvidiaDmabufDisableReason::MissingBootVga => format!(
|
||||
"Wayland 会话检测到 {},但缺少 boot_vga 信息:预防性禁用 WebKit DMABUF。",
|
||||
summary
|
||||
),
|
||||
NvidiaDmabufDisableReason::PrimaryOpenKernelModule => {
|
||||
format!(
|
||||
"Wayland 会话检测到 {}:禁用 WebKit DMABUF 渲染以规避协议错误。",
|
||||
summary
|
||||
)
|
||||
}
|
||||
NvidiaDmabufDisableReason::MissingBootVga => {
|
||||
format!(
|
||||
"Wayland 会话检测到 {},但缺少 boot_vga 信息:预防性禁用 WebKit DMABUF。",
|
||||
summary
|
||||
)
|
||||
}
|
||||
NvidiaDmabufDisableReason::PreferNativeWayland => format!(
|
||||
"Wayland ({}) + {}:检测到 NVIDIA Open Kernel Module 在辅 GPU 上运行,预防性禁用 WebKit DMABUF。",
|
||||
session.compositor_label, summary
|
||||
@@ -266,12 +260,9 @@ impl DmabufDecision {
|
||||
);
|
||||
}
|
||||
} else if session.is_wayland {
|
||||
decision.message = Some(
|
||||
"Wayland 会话未匹配受支持的合成器:禁用 WebKit DMABUF 渲染。".into(),
|
||||
);
|
||||
decision.message = Some("Wayland 会话未匹配受支持的合成器:禁用 WebKit DMABUF 渲染。".into());
|
||||
} else {
|
||||
decision.message =
|
||||
Some("禁用 WebKit DMABUF 渲染以获得更稳定的输出。".into());
|
||||
decision.message = Some("禁用 WebKit DMABUF 渲染以获得更稳定的输出。".into());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -433,13 +424,7 @@ fn read_nvidia_driver_summary() -> Option<String> {
|
||||
.map(|line| line.trim().to_string())
|
||||
.filter(|line| !line.is_empty()),
|
||||
Err(err) => {
|
||||
logging!(
|
||||
info,
|
||||
Type::Setup,
|
||||
"读取 {} 失败:{}",
|
||||
NVIDIA_VERSION_PATH,
|
||||
err
|
||||
);
|
||||
logging!(info, Type::Setup, "读取 {} 失败:{}", NVIDIA_VERSION_PATH, err);
|
||||
None
|
||||
}
|
||||
}
|
||||
@@ -639,10 +624,7 @@ fn flush_section(
|
||||
|
||||
if let Some(&index) = seen.get(scheme) {
|
||||
let existing_line = &mut processed[index];
|
||||
let existing_prefix: String = existing_line
|
||||
.chars()
|
||||
.take_while(|c| c.is_whitespace())
|
||||
.collect();
|
||||
let existing_prefix: String = existing_line.chars().take_while(|c| c.is_whitespace()).collect();
|
||||
let Some((_, existing_raw_value)) = existing_line.trim().split_once('=') else {
|
||||
processed.push(line);
|
||||
continue;
|
||||
@@ -695,10 +677,7 @@ fn flush_section(
|
||||
*changed = true;
|
||||
}
|
||||
|
||||
let prefix = line
|
||||
.chars()
|
||||
.take_while(|c| c.is_whitespace())
|
||||
.collect::<String>();
|
||||
let prefix = line.chars().take_while(|c| c.is_whitespace()).collect::<String>();
|
||||
let mut new_line = format!("{prefix}x-scheme-handler/{scheme}=");
|
||||
new_line.push_str(&values.join(";"));
|
||||
new_line.push(';');
|
||||
@@ -716,10 +695,7 @@ fn flush_section(
|
||||
processed.push(line);
|
||||
}
|
||||
|
||||
let ensure_all = matches!(
|
||||
kind,
|
||||
SectionKind::DefaultApplications | SectionKind::AddedAssociations
|
||||
);
|
||||
let ensure_all = matches!(kind, SectionKind::DefaultApplications | SectionKind::AddedAssociations);
|
||||
|
||||
if ensure_all {
|
||||
for &scheme in schemes {
|
||||
|
||||
@@ -20,11 +20,7 @@ pub struct HttpResponse {
|
||||
|
||||
impl HttpResponse {
|
||||
pub const fn new(status: StatusCode, headers: HeaderMap, body: String) -> Self {
|
||||
Self {
|
||||
status,
|
||||
headers,
|
||||
body,
|
||||
}
|
||||
Self { status, headers, body }
|
||||
}
|
||||
|
||||
pub const fn status(&self) -> StatusCode {
|
||||
@@ -208,10 +204,7 @@ impl NetworkManager {
|
||||
{
|
||||
let auth_str = format!("{}:{}", parsed.username(), pass);
|
||||
let encoded = general_purpose::STANDARD.encode(auth_str);
|
||||
extra_headers.insert(
|
||||
"Authorization",
|
||||
HeaderValue::from_str(&format!("Basic {}", encoded))?,
|
||||
);
|
||||
extra_headers.insert("Authorization", HeaderValue::from_str(&format!("Basic {}", encoded))?);
|
||||
}
|
||||
|
||||
let clean_url = {
|
||||
@@ -235,8 +228,7 @@ impl NetworkManager {
|
||||
let response = match request_builder.send().await {
|
||||
Ok(resp) => resp,
|
||||
Err(e) => {
|
||||
self.record_connection_error(&format!("Request failed: {}", e))
|
||||
.await;
|
||||
self.record_connection_error(&format!("Request failed: {}", e)).await;
|
||||
return Err(anyhow::anyhow!("Request failed: {}", e));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -17,13 +17,7 @@ pub enum NotificationEvent<'a> {
|
||||
|
||||
fn notify(title: &str, body: &str) {
|
||||
let app_handle = handle::Handle::app_handle();
|
||||
app_handle
|
||||
.notification()
|
||||
.builder()
|
||||
.title(title)
|
||||
.body(body)
|
||||
.show()
|
||||
.ok();
|
||||
app_handle.notification().builder().title(title).body(body).show().ok();
|
||||
}
|
||||
|
||||
pub async fn notify_event<'a>(event: NotificationEvent<'a>) {
|
||||
|
||||
@@ -9,12 +9,7 @@ pub async fn set_public_dns(dns_server: String) {
|
||||
let resource_dir = match dirs::app_resources_dir() {
|
||||
Ok(dir) => dir,
|
||||
Err(e) => {
|
||||
logging!(
|
||||
error,
|
||||
Type::Config,
|
||||
"Failed to get resource directory: {}",
|
||||
e
|
||||
);
|
||||
logging!(error, Type::Config, "Failed to get resource directory: {}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
@@ -55,12 +50,7 @@ pub async fn restore_public_dns() {
|
||||
let resource_dir = match dirs::app_resources_dir() {
|
||||
Ok(dir) => dir,
|
||||
Err(e) => {
|
||||
logging!(
|
||||
error,
|
||||
Type::Config,
|
||||
"Failed to get resource directory: {}",
|
||||
e
|
||||
);
|
||||
logging!(error, Type::Config, "Failed to get resource directory: {}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -56,12 +56,7 @@ pub fn resolve_setup_sync() {
|
||||
|
||||
pub fn resolve_setup_async() {
|
||||
AsyncHandler::spawn(|| async {
|
||||
logging!(
|
||||
info,
|
||||
Type::ClashVergeRev,
|
||||
"Version: {}",
|
||||
env!("CARGO_PKG_VERSION")
|
||||
);
|
||||
logging!(info, Type::ClashVergeRev, "Version: {}", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
futures::join!(init_work_config(), init_resources(), init_startup_script());
|
||||
|
||||
@@ -185,10 +180,7 @@ pub(super) async fn init_core_manager() {
|
||||
}
|
||||
|
||||
pub(super) async fn init_system_proxy() {
|
||||
logging_error!(
|
||||
Type::Setup,
|
||||
sysopt::Sysopt::global().update_sysproxy().await
|
||||
);
|
||||
logging_error!(Type::Setup, sysopt::Sysopt::global().update_sysproxy().await);
|
||||
}
|
||||
|
||||
pub(super) async fn init_system_proxy_guard() {
|
||||
@@ -200,11 +192,7 @@ pub(super) async fn refresh_tray_menu() {
|
||||
}
|
||||
|
||||
pub(super) async fn init_window() {
|
||||
let is_silent_start = Config::verge()
|
||||
.await
|
||||
.data_arc()
|
||||
.enable_silent_start
|
||||
.unwrap_or(false);
|
||||
let is_silent_start = Config::verge().await.data_arc().enable_silent_start.unwrap_or(false);
|
||||
#[cfg(target_os = "macos")]
|
||||
if is_silent_start {
|
||||
use crate::core::handle::Handle;
|
||||
|
||||
@@ -30,50 +30,39 @@ pub(super) async fn resolve_scheme(param: &str) -> Result<()> {
|
||||
}
|
||||
};
|
||||
|
||||
let (url_param, name) =
|
||||
if link_parsed.scheme() == "clash" || link_parsed.scheme() == "clash-verge" {
|
||||
let name_owned: Option<String> = link_parsed
|
||||
.query_pairs()
|
||||
.find(|(key, _)| key == "name")
|
||||
.map(|(_, value)| value.into_owned().into());
|
||||
let (url_param, name) = if link_parsed.scheme() == "clash" || link_parsed.scheme() == "clash-verge" {
|
||||
let name_owned: Option<String> = link_parsed
|
||||
.query_pairs()
|
||||
.find(|(key, _)| key == "name")
|
||||
.map(|(_, value)| value.into_owned().into());
|
||||
|
||||
let url_param = if let Some(query) = link_parsed.query() {
|
||||
let prefix = "url=";
|
||||
if let Some(pos) = query.find(prefix) {
|
||||
let raw_url = &query[pos + prefix.len()..];
|
||||
Some(percent_decode_str(raw_url).decode_utf8_lossy().to_string())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
let url_param = if let Some(query) = link_parsed.query() {
|
||||
let prefix = "url=";
|
||||
if let Some(pos) = query.find(prefix) {
|
||||
let raw_url = &query[pos + prefix.len()..];
|
||||
Some(percent_decode_str(raw_url).decode_utf8_lossy().to_string())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
(url_param, name_owned)
|
||||
}
|
||||
} else {
|
||||
(None, None)
|
||||
None
|
||||
};
|
||||
(url_param, name_owned)
|
||||
} else {
|
||||
(None, None)
|
||||
};
|
||||
|
||||
let url = if let Some(ref url) = url_param {
|
||||
url
|
||||
} else {
|
||||
logging!(
|
||||
error,
|
||||
Type::Config,
|
||||
"missing url parameter in deep link: {}",
|
||||
param_str
|
||||
);
|
||||
logging!(error, Type::Config, "missing url parameter in deep link: {}", param_str);
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let mut item = match PrfItem::from_url(url, name.as_ref(), None, None).await {
|
||||
Ok(item) => item,
|
||||
Err(e) => {
|
||||
logging!(
|
||||
error,
|
||||
Type::Config,
|
||||
"failed to parse profile from url: {:?}",
|
||||
e
|
||||
);
|
||||
logging!(error, Type::Config, "failed to parse profile from url: {:?}", e);
|
||||
handle::Handle::notice_message("import_sub_url::error", e.to_string());
|
||||
return Ok(());
|
||||
}
|
||||
@@ -94,12 +83,7 @@ pub(super) async fn resolve_scheme(param: &str) -> Result<()> {
|
||||
handle::Handle::notify_profile_changed(uid);
|
||||
}
|
||||
Err(e) => {
|
||||
logging!(
|
||||
error,
|
||||
Type::Config,
|
||||
"failed to import subscription url: {:?}",
|
||||
e
|
||||
);
|
||||
logging!(error, Type::Config, "failed to import subscription url: {:?}", e);
|
||||
Config::profiles().await.discard();
|
||||
handle::Handle::notice_message("import_sub_url::error", e.to_string());
|
||||
return Ok(());
|
||||
|
||||
@@ -52,11 +52,7 @@ pub async fn build_new_window() -> Result<WebviewWindow, String> {
|
||||
LIGHT_BACKGROUND_COLOR
|
||||
};
|
||||
|
||||
let initial_script = build_window_initial_script(
|
||||
initial_theme_mode,
|
||||
DARK_BACKGROUND_HEX,
|
||||
LIGHT_BACKGROUND_HEX,
|
||||
);
|
||||
let initial_script = build_window_initial_script(initial_theme_mode, DARK_BACKGROUND_HEX, LIGHT_BACKGROUND_HEX);
|
||||
|
||||
let mut builder = tauri::WebviewWindowBuilder::new(
|
||||
app_handle,
|
||||
@@ -81,10 +77,7 @@ pub async fn build_new_window() -> Result<WebviewWindow, String> {
|
||||
|
||||
match builder.build() {
|
||||
Ok(window) => {
|
||||
logging_error!(
|
||||
Type::Window,
|
||||
window.set_background_color(Some(background_color))
|
||||
);
|
||||
logging_error!(Type::Window, window.set_background_color(Some(background_color)));
|
||||
logging_error!(Type::Window, window.eval(INITIAL_LOADING_OVERLAY));
|
||||
Ok(window)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
pub fn build_window_initial_script(
|
||||
initial_theme_mode: &str,
|
||||
dark_background: &str,
|
||||
light_background: &str,
|
||||
) -> String {
|
||||
pub fn build_window_initial_script(initial_theme_mode: &str, dark_background: &str, light_background: &str) -> String {
|
||||
let theme_mode = match initial_theme_mode {
|
||||
"dark" => "dark",
|
||||
"light" => "light",
|
||||
|
||||
@@ -28,9 +28,7 @@ static SHUTDOWN_SENDER: OnceCell<Mutex<Option<oneshot::Sender<()>>>> = OnceCell:
|
||||
pub async fn check_singleton() -> Result<()> {
|
||||
let port = IVerge::get_singleton_port();
|
||||
if !local_port_available(port) {
|
||||
let client = ClientBuilder::new()
|
||||
.timeout(Duration::from_millis(500))
|
||||
.build()?;
|
||||
let client = ClientBuilder::new().timeout(Duration::from_millis(500)).build()?;
|
||||
// 需要确保 Send
|
||||
#[allow(clippy::needless_collect)]
|
||||
let argvs: Vec<std::string::String> = std::env::args().collect();
|
||||
@@ -40,9 +38,7 @@ pub async fn check_singleton() -> Result<()> {
|
||||
let param = argvs[1].as_str();
|
||||
if param.starts_with("clash:") {
|
||||
client
|
||||
.get(format!(
|
||||
"http://127.0.0.1:{port}/commands/scheme?param={param}"
|
||||
))
|
||||
.get(format!("http://127.0.0.1:{port}/commands/scheme?param={param}"))
|
||||
.send()
|
||||
.await?;
|
||||
}
|
||||
@@ -53,11 +49,7 @@ pub async fn check_singleton() -> Result<()> {
|
||||
.send()
|
||||
.await?;
|
||||
}
|
||||
logging!(
|
||||
error,
|
||||
Type::Window,
|
||||
"failed to setup singleton listen server"
|
||||
);
|
||||
logging!(error, Type::Window, "failed to setup singleton listen server");
|
||||
bail!("app exists");
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -55,11 +55,7 @@ fn get_window_operation_debounce() -> &'static Mutex<Instant> {
|
||||
|
||||
fn should_handle_window_operation() -> bool {
|
||||
if WINDOW_OPERATION_IN_PROGRESS.load(Ordering::Acquire) {
|
||||
logging!(
|
||||
warn,
|
||||
Type::Window,
|
||||
"Warning: [防抖] 窗口操作已在进行中,跳过重复调用"
|
||||
);
|
||||
logging!(warn, Type::Window, "Warning: [防抖] 窗口操作已在进行中,跳过重复调用");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -328,12 +324,7 @@ impl WindowManager {
|
||||
/// 创建新窗口,防抖避免重复调用
|
||||
pub fn create_window(is_show: bool) -> Pin<Box<dyn Future<Output = bool> + Send>> {
|
||||
Box::pin(async move {
|
||||
logging!(
|
||||
info,
|
||||
Type::Window,
|
||||
"开始创建/显示主窗口, is_show={}",
|
||||
is_show
|
||||
);
|
||||
logging!(info, Type::Window, "开始创建/显示主窗口, is_show={}", is_show);
|
||||
|
||||
if !is_show {
|
||||
return false;
|
||||
@@ -383,8 +374,6 @@ impl WindowManager {
|
||||
let is_focused = Self::is_main_window_focused();
|
||||
let is_minimized = Self::is_main_window_minimized();
|
||||
|
||||
format!(
|
||||
"窗口状态: {state:?} | 可见: {is_visible} | 有焦点: {is_focused} | 最小化: {is_minimized}"
|
||||
)
|
||||
format!("窗口状态: {state:?} | 可见: {is_visible} | 有焦点: {is_focused} | 最小化: {is_minimized}")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user