fix: dynamically modify pac content (#5468)

* fix: dynamically modify pac content

* docs: update Changelog.md
This commit is contained in:
oomeow
2025-11-16 18:53:43 +08:00
committed by GitHub
parent e1fc9547d8
commit b0089d162b
2 changed files with 33 additions and 30 deletions

View File

@@ -6,6 +6,7 @@
- macOS service 启动项显示名称(试验性修改) - macOS service 启动项显示名称(试验性修改)
- macOS 非预期 Tproxy 端口设置 - macOS 非预期 Tproxy 端口设置
- 流量图缩放异常 - 流量图缩放异常
- PAC 自动代理脚本内容无法动态调整
<details> <details>
<summary><strong> ✨ 新增功能 </strong></summary> <summary><strong> ✨ 新增功能 </strong></summary>

View File

@@ -73,7 +73,6 @@ 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 {
@@ -87,6 +86,7 @@ pub fn embed_server() {
)) ))
}); });
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,13 +100,13 @@ 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 pac = warp::path!("commands" / "pac").map(move || {
let processed_content = pac_content.replace("%mixed-port%", &format!("{pac_port}")); let processed_content = pac_content.replace("%mixed-port%", &format!("{pac_port}"));
Ok::<_, warp::Rejection>(
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 // Use map instead of and_then to avoid Send issues
@@ -123,6 +123,8 @@ pub fn embed_server() {
}); });
let commands = visible.or(scheme).or(pac); 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