mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 05:13:44 +08:00
chore: delete useless emebd server api
This commit is contained in:
parent
3c17fca369
commit
fd963a8e66
@ -8,7 +8,7 @@ use crate::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use tauri::tray::{MouseButton, MouseButtonState, TrayIconEvent};
|
use tauri::tray::{MouseButton, TrayIconEvent};
|
||||||
use tauri::{
|
use tauri::{
|
||||||
menu::{MenuEvent, MenuItem, PredefinedMenuItem, Submenu},
|
menu::{MenuEvent, MenuItem, PredefinedMenuItem, Submenu},
|
||||||
Wry,
|
Wry,
|
||||||
|
@ -4,49 +4,19 @@ use super::resolve;
|
|||||||
use crate::config::{Config, IVerge, DEFAULT_PAC};
|
use crate::config::{Config, IVerge, DEFAULT_PAC};
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use port_scanner::local_port_available;
|
use port_scanner::local_port_available;
|
||||||
use std::convert::Infallible;
|
|
||||||
use tauri::AppHandle;
|
use tauri::AppHandle;
|
||||||
use warp::http::StatusCode;
|
|
||||||
use warp::Filter;
|
use warp::Filter;
|
||||||
|
|
||||||
#[derive(serde::Deserialize, Debug)]
|
|
||||||
struct QueryParam {
|
|
||||||
param: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// check whether there is already exists
|
/// check whether there is already exists
|
||||||
pub async fn check_singleton() -> Result<()> {
|
pub async fn check_singleton() -> Result<()> {
|
||||||
let port = IVerge::get_singleton_port();
|
let port = IVerge::get_singleton_port();
|
||||||
|
|
||||||
if !local_port_available(port) {
|
if !local_port_available(port) {
|
||||||
let resp = reqwest::get(format!("http://127.0.0.1:{port}/commands/ping"))
|
reqwest::get(format!("http://127.0.0.1:{port}/commands/visible"))
|
||||||
.await?
|
.await?
|
||||||
.text()
|
.text()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if &resp == "ok" {
|
|
||||||
let argvs: Vec<String> = std::env::args().collect();
|
|
||||||
if argvs.len() > 1 {
|
|
||||||
let param = argvs[1].as_str();
|
|
||||||
if param.starts_with("clash:") {
|
|
||||||
reqwest::get(format!(
|
|
||||||
"http://127.0.0.1:{port}/commands/scheme?param={param}"
|
|
||||||
))
|
|
||||||
.await?
|
|
||||||
.text()
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
reqwest::get(format!("http://127.0.0.1:{port}/commands/visible"))
|
|
||||||
.await?
|
|
||||||
.text()
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
bail!("app exists");
|
|
||||||
}
|
|
||||||
|
|
||||||
log::error!("failed to setup singleton listen server");
|
log::error!("failed to setup singleton listen server");
|
||||||
Ok(())
|
bail!("app exists");
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -59,8 +29,6 @@ pub fn embed_server(app_handle: &AppHandle) {
|
|||||||
|
|
||||||
let handle = app_handle.clone();
|
let handle = app_handle.clone();
|
||||||
tauri::async_runtime::spawn(async move {
|
tauri::async_runtime::spawn(async move {
|
||||||
let ping = warp::path!("commands" / "ping").map(move || "ok");
|
|
||||||
|
|
||||||
let visible = warp::path!("commands" / "visible").map(move || {
|
let visible = warp::path!("commands" / "visible").map(move || {
|
||||||
resolve::create_window(&handle);
|
resolve::create_window(&handle);
|
||||||
"ok"
|
"ok"
|
||||||
@ -82,21 +50,8 @@ pub fn embed_server(app_handle: &AppHandle) {
|
|||||||
.body(content)
|
.body(content)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
});
|
});
|
||||||
let scheme = warp::path!("commands" / "scheme")
|
|
||||||
.and(warp::query::<QueryParam>())
|
|
||||||
.and_then(scheme_handler);
|
|
||||||
|
|
||||||
async fn scheme_handler(query: QueryParam) -> Result<impl warp::Reply, Infallible> {
|
let commands = visible.or(pac);
|
||||||
let result = resolve::resolve_scheme(query.param).await;
|
|
||||||
Ok(match result {
|
|
||||||
Ok(_) => warp::reply::with_status("Ok", StatusCode::OK),
|
|
||||||
Err(_) => {
|
|
||||||
warp::reply::with_status("Internal Error", StatusCode::INTERNAL_SERVER_ERROR)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
let commands = ping.or(visible).or(pac).or(scheme);
|
|
||||||
warp::serve(commands).run(([127, 0, 0, 1], port)).await;
|
warp::serve(commands).run(([127, 0, 0, 1], port)).await;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user