mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 00:35:38 +08:00
fix: dynamically modify pac content (#5468)
* fix: dynamically modify pac content * docs: update Changelog.md
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
- macOS service 启动项显示名称(试验性修改)
|
- macOS service 启动项显示名称(试验性修改)
|
||||||
- macOS 非预期 Tproxy 端口设置
|
- macOS 非预期 Tproxy 端口设置
|
||||||
- 流量图缩放异常
|
- 流量图缩放异常
|
||||||
|
- PAC 自动代理脚本内容无法动态调整
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary><strong> ✨ 新增功能 </strong></summary>
|
<summary><strong> ✨ 新增功能 </strong></summary>
|
||||||
|
|||||||
@@ -73,20 +73,20 @@ pub fn embed_server() {
|
|||||||
.expect("failed to set shutdown signal for embedded server");
|
.expect("failed to set shutdown signal for embedded server");
|
||||||
let port = IVerge::get_singleton_port();
|
let port = IVerge::get_singleton_port();
|
||||||
|
|
||||||
AsyncHandler::spawn(move || async move {
|
let visible = warp::path!("commands" / "visible").and_then(|| async {
|
||||||
let visible = warp::path!("commands" / "visible").and_then(|| async {
|
logging!(info, Type::Window, "检测到从单例模式恢复应用窗口");
|
||||||
logging!(info, Type::Window, "检测到从单例模式恢复应用窗口");
|
if !lightweight::exit_lightweight_mode().await {
|
||||||
if !lightweight::exit_lightweight_mode().await {
|
WindowManager::show_main_window().await;
|
||||||
WindowManager::show_main_window().await;
|
} else {
|
||||||
} else {
|
logging!(error, Type::Window, "轻量模式退出失败,无法恢复应用窗口");
|
||||||
logging!(error, Type::Window, "轻量模式退出失败,无法恢复应用窗口");
|
};
|
||||||
};
|
Ok::<_, warp::Rejection>(warp::reply::with_status::<std::string::String>(
|
||||||
Ok::<_, warp::Rejection>(warp::reply::with_status::<std::string::String>(
|
"ok".to_string(),
|
||||||
"ok".to_string(),
|
warp::http::StatusCode::OK,
|
||||||
warp::http::StatusCode::OK,
|
))
|
||||||
))
|
});
|
||||||
});
|
|
||||||
|
|
||||||
|
let pac = warp::path!("commands" / "pac").and_then(|| async move {
|
||||||
let verge_config = Config::verge().await;
|
let verge_config = Config::verge().await;
|
||||||
let clash_config = Config::clash().await;
|
let clash_config = Config::clash().await;
|
||||||
|
|
||||||
@@ -100,29 +100,31 @@ pub fn embed_server() {
|
|||||||
.data_arc()
|
.data_arc()
|
||||||
.verge_mixed_port
|
.verge_mixed_port
|
||||||
.unwrap_or_else(|| clash_config.data_arc().get_mixed_port());
|
.unwrap_or_else(|| clash_config.data_arc().get_mixed_port());
|
||||||
|
let processed_content = pac_content.replace("%mixed-port%", &format!("{pac_port}"));
|
||||||
let pac = warp::path!("commands" / "pac").map(move || {
|
Ok::<_, warp::Rejection>(
|
||||||
let processed_content = pac_content.replace("%mixed-port%", &format!("{pac_port}"));
|
|
||||||
warp::http::Response::builder()
|
warp::http::Response::builder()
|
||||||
.header("Content-Type", "application/x-ns-proxy-autoconfig")
|
.header("Content-Type", "application/x-ns-proxy-autoconfig")
|
||||||
.body(processed_content)
|
.body(processed_content)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
// Use map instead of and_then to avoid Send issues
|
||||||
|
let scheme = warp::path!("commands" / "scheme")
|
||||||
|
.and(warp::query::<QueryParam>())
|
||||||
|
.and_then(|query: QueryParam| async move {
|
||||||
|
AsyncHandler::spawn(|| async move {
|
||||||
|
logging_error!(Type::Setup, resolve::resolve_scheme(&query.param).await);
|
||||||
|
});
|
||||||
|
Ok::<_, warp::Rejection>(warp::reply::with_status::<std::string::String>(
|
||||||
|
"ok".to_string(),
|
||||||
|
warp::http::StatusCode::OK,
|
||||||
|
))
|
||||||
});
|
});
|
||||||
|
|
||||||
// Use map instead of and_then to avoid Send issues
|
let commands = visible.or(scheme).or(pac);
|
||||||
let scheme = warp::path!("commands" / "scheme")
|
|
||||||
.and(warp::query::<QueryParam>())
|
|
||||||
.and_then(|query: QueryParam| async move {
|
|
||||||
AsyncHandler::spawn(|| async move {
|
|
||||||
logging_error!(Type::Setup, resolve::resolve_scheme(&query.param).await);
|
|
||||||
});
|
|
||||||
Ok::<_, warp::Rejection>(warp::reply::with_status::<std::string::String>(
|
|
||||||
"ok".to_string(),
|
|
||||||
warp::http::StatusCode::OK,
|
|
||||||
))
|
|
||||||
});
|
|
||||||
|
|
||||||
let commands = visible.or(scheme).or(pac);
|
AsyncHandler::spawn(move || async move {
|
||||||
warp::serve(commands)
|
warp::serve(commands)
|
||||||
.bind(([127, 0, 0, 1], port))
|
.bind(([127, 0, 0, 1], port))
|
||||||
.await
|
.await
|
||||||
|
|||||||
Reference in New Issue
Block a user