mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
Revert "feat: update Cargo.toml for 2024 edition and optimize release profiles (#4681)"
This reverts commit 31e3104c7f.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#[cfg(target_os = "windows")]
|
||||
use anyhow::{Result, anyhow};
|
||||
use anyhow::{anyhow, Result};
|
||||
#[cfg(target_os = "windows")]
|
||||
use log::info;
|
||||
|
||||
|
||||
@@ -151,11 +151,12 @@ pub fn find_target_icons(target: &str) -> Result<Option<String>> {
|
||||
let entry = entry?;
|
||||
let path = entry.path();
|
||||
|
||||
if let Some(file_name) = path.file_name().and_then(|n| n.to_str())
|
||||
&& file_name.starts_with(target)
|
||||
&& (file_name.ends_with(".ico") || file_name.ends_with(".png"))
|
||||
{
|
||||
matching_files.push(path);
|
||||
if let Some(file_name) = path.file_name().and_then(|n| n.to_str()) {
|
||||
if file_name.starts_with(target)
|
||||
&& (file_name.ends_with(".ico") || file_name.ends_with(".png"))
|
||||
{
|
||||
matching_files.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::{enhance::seq::SeqMap, logging, utils::logging::Type};
|
||||
use anyhow::{Context, Result, anyhow, bail};
|
||||
use anyhow::{anyhow, bail, Context, Result};
|
||||
use nanoid::nanoid;
|
||||
use serde::{Serialize, de::DeserializeOwned};
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
use serde_yaml_ng::Mapping;
|
||||
use std::{path::PathBuf, str::FromStr};
|
||||
|
||||
@@ -154,6 +154,10 @@ macro_rules! ret_err {
|
||||
#[macro_export]
|
||||
macro_rules! t {
|
||||
($en:expr, $zh:expr, $use_zh:expr) => {
|
||||
if $use_zh { $zh } else { $en }
|
||||
if $use_zh {
|
||||
$zh
|
||||
} else {
|
||||
$en
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,14 +15,14 @@ fn get_locales_dir() -> Option<PathBuf> {
|
||||
pub fn get_supported_languages() -> Vec<String> {
|
||||
let mut languages = Vec::new();
|
||||
|
||||
if let Some(locales_dir) = get_locales_dir()
|
||||
&& let Ok(entries) = fs::read_dir(locales_dir)
|
||||
{
|
||||
for entry in entries.flatten() {
|
||||
if let Some(file_name) = entry.file_name().to_str()
|
||||
&& let Some(lang) = file_name.strip_suffix(".json")
|
||||
{
|
||||
languages.push(lang.to_string());
|
||||
if let Some(locales_dir) = get_locales_dir() {
|
||||
if let Ok(entries) = fs::read_dir(locales_dir) {
|
||||
for entry in entries.flatten() {
|
||||
if let Some(file_name) = entry.file_name().to_str() {
|
||||
if let Some(lang) = file_name.strip_suffix(".json") {
|
||||
languages.push(lang.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,10 +39,10 @@ static TRANSLATIONS: Lazy<HashMap<String, Value>> = Lazy::new(|| {
|
||||
if let Some(locales_dir) = get_locales_dir() {
|
||||
for lang in get_supported_languages() {
|
||||
let file_path = locales_dir.join(format!("{lang}.json"));
|
||||
if let Ok(content) = fs::read_to_string(file_path)
|
||||
&& let Ok(json) = serde_json::from_str(&content)
|
||||
{
|
||||
translations.insert(lang.to_string(), json);
|
||||
if let Ok(content) = fs::read_to_string(file_path) {
|
||||
if let Ok(json) = serde_json::from_str(&content) {
|
||||
translations.insert(lang.to_string(), json);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,13 +76,14 @@ pub async fn t(key: &str) -> String {
|
||||
return text.to_string();
|
||||
}
|
||||
|
||||
if current_lang != DEFAULT_LANGUAGE
|
||||
&& let Some(text) = TRANSLATIONS
|
||||
if current_lang != DEFAULT_LANGUAGE {
|
||||
if let Some(text) = TRANSLATIONS
|
||||
.get(DEFAULT_LANGUAGE)
|
||||
.and_then(|trans| trans.get(&key))
|
||||
.and_then(|val| val.as_str())
|
||||
{
|
||||
return text.to_string();
|
||||
{
|
||||
return text.to_string();
|
||||
}
|
||||
}
|
||||
|
||||
key
|
||||
|
||||
@@ -296,52 +296,52 @@ async fn ensure_directories() -> Result<()> {
|
||||
|
||||
/// 初始化配置文件
|
||||
async fn initialize_config_files() -> Result<()> {
|
||||
if let Ok(path) = dirs::clash_path()
|
||||
&& !path.exists()
|
||||
{
|
||||
let template = IClashTemp::template().0;
|
||||
help::save_yaml(&path, &template, Some("# Clash Verge"))
|
||||
.await
|
||||
.map_err(|e| anyhow::anyhow!("Failed to create clash config: {}", e))?;
|
||||
logging!(
|
||||
info,
|
||||
Type::Setup,
|
||||
true,
|
||||
"Created clash config at {:?}",
|
||||
path
|
||||
);
|
||||
if let Ok(path) = dirs::clash_path() {
|
||||
if !path.exists() {
|
||||
let template = IClashTemp::template().0;
|
||||
help::save_yaml(&path, &template, Some("# Clash Verge"))
|
||||
.await
|
||||
.map_err(|e| anyhow::anyhow!("Failed to create clash config: {}", e))?;
|
||||
logging!(
|
||||
info,
|
||||
Type::Setup,
|
||||
true,
|
||||
"Created clash config at {:?}",
|
||||
path
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(path) = dirs::verge_path()
|
||||
&& !path.exists()
|
||||
{
|
||||
let template = IVerge::template();
|
||||
help::save_yaml(&path, &template, Some("# Clash Verge"))
|
||||
.await
|
||||
.map_err(|e| anyhow::anyhow!("Failed to create verge config: {}", e))?;
|
||||
logging!(
|
||||
info,
|
||||
Type::Setup,
|
||||
true,
|
||||
"Created verge config at {:?}",
|
||||
path
|
||||
);
|
||||
if let Ok(path) = dirs::verge_path() {
|
||||
if !path.exists() {
|
||||
let template = IVerge::template();
|
||||
help::save_yaml(&path, &template, Some("# Clash Verge"))
|
||||
.await
|
||||
.map_err(|e| anyhow::anyhow!("Failed to create verge config: {}", e))?;
|
||||
logging!(
|
||||
info,
|
||||
Type::Setup,
|
||||
true,
|
||||
"Created verge config at {:?}",
|
||||
path
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(path) = dirs::profiles_path()
|
||||
&& !path.exists()
|
||||
{
|
||||
let template = IProfiles::template();
|
||||
help::save_yaml(&path, &template, Some("# Clash Verge"))
|
||||
.await
|
||||
.map_err(|e| anyhow::anyhow!("Failed to create profiles config: {}", e))?;
|
||||
logging!(
|
||||
info,
|
||||
Type::Setup,
|
||||
true,
|
||||
"Created profiles config at {:?}",
|
||||
path
|
||||
);
|
||||
if let Ok(path) = dirs::profiles_path() {
|
||||
if !path.exists() {
|
||||
let template = IProfiles::template();
|
||||
help::save_yaml(&path, &template, Some("# Clash Verge"))
|
||||
.await
|
||||
.map_err(|e| anyhow::anyhow!("Failed to create profiles config: {}", e))?;
|
||||
logging!(
|
||||
info,
|
||||
Type::Setup,
|
||||
true,
|
||||
"Created profiles config at {:?}",
|
||||
path
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 验证并修正verge配置
|
||||
@@ -459,7 +459,7 @@ pub async fn init_resources() -> Result<()> {
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn init_scheme() -> Result<()> {
|
||||
use tauri::utils::platform::current_exe;
|
||||
use winreg::{RegKey, enums::*};
|
||||
use winreg::{enums::*, RegKey};
|
||||
|
||||
let app_exe = current_exe()?;
|
||||
let app_exe = dunce::canonicalize(app_exe)?;
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
use anyhow::Result;
|
||||
use base64::{Engine as _, engine::general_purpose};
|
||||
use base64::{engine::general_purpose, Engine as _};
|
||||
use isahc::prelude::*;
|
||||
use isahc::{HttpClient, config::SslOption};
|
||||
use isahc::{
|
||||
config::RedirectPolicy,
|
||||
http::{
|
||||
StatusCode, Uri,
|
||||
header::{HeaderMap, HeaderValue, USER_AGENT},
|
||||
StatusCode, Uri,
|
||||
},
|
||||
};
|
||||
use isahc::{config::SslOption, HttpClient};
|
||||
use std::time::{Duration, Instant};
|
||||
use sysproxy::Sysproxy;
|
||||
use tauri::Url;
|
||||
@@ -88,11 +88,10 @@ impl NetworkManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
if let Some((time, _)) = &*last_error_guard
|
||||
&& time.elapsed() < Duration::from_secs(30)
|
||||
&& count > 2
|
||||
{
|
||||
return true;
|
||||
if let Some((time, _)) = &*last_error_guard {
|
||||
if time.elapsed() < Duration::from_secs(30) && count > 2 {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
@@ -114,8 +113,7 @@ impl NetworkManager {
|
||||
) -> Result<HttpClient> {
|
||||
let proxy_uri_clone = proxy_uri.clone();
|
||||
let headers_clone = default_headers.clone();
|
||||
|
||||
{
|
||||
let client = {
|
||||
let mut builder = HttpClient::builder();
|
||||
|
||||
builder = match proxy_uri_clone {
|
||||
@@ -138,7 +136,9 @@ impl NetworkManager {
|
||||
builder = builder.redirect_policy(RedirectPolicy::Follow);
|
||||
|
||||
Ok(builder.build()?)
|
||||
}
|
||||
};
|
||||
|
||||
client
|
||||
}
|
||||
|
||||
pub async fn create_request(
|
||||
@@ -200,15 +200,15 @@ impl NetworkManager {
|
||||
let parsed = Url::parse(url)?;
|
||||
let mut extra_headers = HeaderMap::new();
|
||||
|
||||
if !parsed.username().is_empty()
|
||||
&& let Some(pass) = parsed.password()
|
||||
{
|
||||
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))?,
|
||||
);
|
||||
if !parsed.username().is_empty() {
|
||||
if let Some(pass) = parsed.password() {
|
||||
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))?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let clean_url = {
|
||||
|
||||
@@ -3,7 +3,7 @@ use tauri::AppHandle;
|
||||
|
||||
use crate::{
|
||||
config::Config,
|
||||
core::{CoreManager, Timer, handle, hotkey::Hotkey, sysopt, tray::Tray},
|
||||
core::{handle, hotkey::Hotkey, sysopt, tray::Tray, CoreManager, Timer},
|
||||
logging, logging_error,
|
||||
module::lightweight::auto_lightweight_mode_init,
|
||||
process::AsyncHandler,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use anyhow::{Result, bail};
|
||||
use anyhow::{bail, Result};
|
||||
use percent_encoding::percent_decode_str;
|
||||
use tauri::Url;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use once_cell::sync::OnceCell;
|
||||
use parking_lot::RwLock;
|
||||
use std::sync::{
|
||||
Arc,
|
||||
atomic::{AtomicBool, Ordering},
|
||||
Arc,
|
||||
};
|
||||
use tokio::sync::Notify;
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ use crate::{
|
||||
utils::{
|
||||
logging::Type,
|
||||
resolve::{
|
||||
ui::{UiReadyStage, get_ui_ready, update_ui_ready_stage, wait_for_ui_ready},
|
||||
ui::{get_ui_ready, update_ui_ready_stage, wait_for_ui_ready, UiReadyStage},
|
||||
window_script::{INITIAL_LOADING_OVERLAY, WINDOW_INITIAL_SCRIPT},
|
||||
},
|
||||
},
|
||||
@@ -34,22 +34,22 @@ fn get_window_creating_lock() -> &'static Mutex<(bool, Instant)> {
|
||||
|
||||
/// 检查是否已存在窗口,如果存在则显示并返回 true
|
||||
fn check_existing_window(is_show: bool) -> Option<bool> {
|
||||
if let Some(app_handle) = handle::Handle::global().app_handle()
|
||||
&& let Some(window) = app_handle.get_webview_window("main")
|
||||
{
|
||||
logging!(info, Type::Window, true, "主窗口已存在,将显示现有窗口");
|
||||
if is_show {
|
||||
if window.is_minimized().unwrap_or(false) {
|
||||
logging!(info, Type::Window, true, "窗口已最小化,正在取消最小化");
|
||||
let _ = window.unminimize();
|
||||
}
|
||||
let _ = window.show();
|
||||
let _ = window.set_focus();
|
||||
if let Some(app_handle) = handle::Handle::global().app_handle() {
|
||||
if let Some(window) = app_handle.get_webview_window("main") {
|
||||
logging!(info, Type::Window, true, "主窗口已存在,将显示现有窗口");
|
||||
if is_show {
|
||||
if window.is_minimized().unwrap_or(false) {
|
||||
logging!(info, Type::Window, true, "窗口已最小化,正在取消最小化");
|
||||
let _ = window.unminimize();
|
||||
}
|
||||
let _ = window.show();
|
||||
let _ = window.set_focus();
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
handle::Handle::global().set_activation_policy_regular();
|
||||
#[cfg(target_os = "macos")]
|
||||
handle::Handle::global().set_activation_policy_regular();
|
||||
}
|
||||
return Some(true);
|
||||
}
|
||||
return Some(true);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use super::resolve;
|
||||
use crate::{
|
||||
config::{Config, DEFAULT_PAC, IVerge},
|
||||
config::{Config, IVerge, DEFAULT_PAC},
|
||||
logging_error,
|
||||
process::AsyncHandler,
|
||||
utils::logging::Type,
|
||||
};
|
||||
use anyhow::{Result, bail};
|
||||
use anyhow::{bail, Result};
|
||||
use port_scanner::local_port_available;
|
||||
use warp::Filter;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user