mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-04-13 21:40:33 +08:00
* refactor: improve code quality with clippy fixes and standardized logging - Replace dangerous unwrap()/expect() calls with proper error handling - Standardize logging from log:: to logging\! macro with Type:: classifications - Fix app handle panics with graceful fallback patterns - Improve error resilience across 35+ modules without breaking functionality - Reduce clippy warnings from 300+ to 0 in main library code * chore: update Cargo.toml configuration * refactor: resolve all clippy warnings - Fix Arc clone warnings using explicit Arc::clone syntax across 9 files - Add #[allow(clippy::expect_used)] to test functions for appropriate expect usage - Remove no-effect statements from debug code cleanup - Apply clippy auto-fixes for dbg\! macro removals and path statements - Achieve zero clippy warnings on all targets with -D warnings flag * chore: update Cargo.toml clippy configuration * refactor: simplify macOS job configuration and improve caching * refactor: remove unnecessary async/await from service and proxy functions * refactor: streamline pnpm installation in CI configuration * refactor: simplify error handling and remove unnecessary else statements * refactor: replace async/await with synchronous locks for core management * refactor: add workflow_dispatch trigger to clippy job * refactor: convert async functions to synchronous for service management * refactor: convert async functions to synchronous for UWP tool invocation * fix: change wrong logging * refactor: convert proxy restoration functions to async * Revert "refactor: convert proxy restoration functions to async" This reverts commit b82f5d250b2af7151e4dfd7dd411630b34ed2c18. * refactor: update proxy restoration functions to return Result types * fix: handle errors during proxy restoration and update async function signatures * fix: handle errors during proxy restoration and update async function signatures * refactor: update restore_pac_proxy and restore_sys_proxy functions to async * fix: convert restore_pac_proxy and restore_sys_proxy functions to async * fix: await restore_sys_proxy calls in proxy restoration logic * fix: suppress clippy warnings for unused async functions in proxy restoration * fix: suppress clippy warnings for unused async functions in proxy restoration
88 lines
2.8 KiB
Rust
88 lines
2.8 KiB
Rust
extern crate warp;
|
|
|
|
use super::resolve;
|
|
use crate::{
|
|
config::{Config, IVerge, DEFAULT_PAC},
|
|
logging_error,
|
|
process::AsyncHandler,
|
|
utils::logging::Type,
|
|
};
|
|
use anyhow::{bail, Result};
|
|
use port_scanner::local_port_available;
|
|
use std::convert::Infallible;
|
|
use warp::Filter;
|
|
|
|
#[derive(serde::Deserialize, Debug)]
|
|
struct QueryParam {
|
|
param: String,
|
|
}
|
|
|
|
/// check whether there is already exists
|
|
pub async fn check_singleton() -> Result<()> {
|
|
let port = IVerge::get_singleton_port();
|
|
if !local_port_available(port) {
|
|
let argvs: Vec<String> = std::env::args().collect();
|
|
if argvs.len() > 1 {
|
|
#[cfg(not(target_os = "macos"))]
|
|
{
|
|
let param = argvs[1].as_str();
|
|
if param.starts_with("clash:") {
|
|
let _ = reqwest::get(format!(
|
|
"http://127.0.0.1:{port}/commands/scheme?param={param}"
|
|
))
|
|
.await;
|
|
}
|
|
}
|
|
} else {
|
|
let _ = reqwest::get(format!("http://127.0.0.1:{port}/commands/visible")).await;
|
|
}
|
|
log::error!("failed to setup singleton listen server");
|
|
bail!("app exists");
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
/// The embed server only be used to implement singleton process
|
|
/// maybe it can be used as pac server later
|
|
pub fn embed_server() {
|
|
let port = IVerge::get_singleton_port();
|
|
|
|
AsyncHandler::spawn(move || async move {
|
|
let visible = warp::path!("commands" / "visible").map(|| {
|
|
resolve::create_window(false);
|
|
warp::reply::with_status("ok".to_string(), warp::http::StatusCode::OK)
|
|
});
|
|
|
|
let pac = warp::path!("commands" / "pac").map(|| {
|
|
let content = Config::verge()
|
|
.latest_ref()
|
|
.pac_file_content
|
|
.clone()
|
|
.unwrap_or(DEFAULT_PAC.to_string());
|
|
let port = Config::verge()
|
|
.latest_ref()
|
|
.verge_mixed_port
|
|
.unwrap_or(Config::clash().latest_ref().get_mixed_port());
|
|
let content = content.replace("%mixed-port%", &format!("{port}"));
|
|
warp::http::Response::builder()
|
|
.header("Content-Type", "application/x-ns-proxy-autoconfig")
|
|
.body(content)
|
|
.unwrap_or_default()
|
|
});
|
|
async fn scheme_handler(query: QueryParam) -> Result<String, Infallible> {
|
|
logging_error!(
|
|
Type::Setup,
|
|
true,
|
|
resolve::resolve_scheme(query.param).await
|
|
);
|
|
Ok("ok".to_string())
|
|
}
|
|
|
|
let scheme = warp::path!("commands" / "scheme")
|
|
.and(warp::query::<QueryParam>())
|
|
.and_then(scheme_handler);
|
|
let commands = visible.or(scheme).or(pac);
|
|
warp::serve(commands).run(([127, 0, 0, 1], port)).await;
|
|
});
|
|
}
|