mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
refactor: migrate clash client info retrieval to MihomoManager
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
use crate::config::Config;
|
||||
use anyhow::Result;
|
||||
use reqwest::header::HeaderMap;
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq)]
|
||||
pub struct Rate {
|
||||
@@ -8,26 +6,11 @@ pub struct Rate {
|
||||
pub down: u64,
|
||||
}
|
||||
|
||||
/// 根据clash info获取clash服务地址和请求头
|
||||
pub fn clash_client_info() -> Result<(String, HeaderMap)> {
|
||||
let client = { Config::clash().data().get_client_info() };
|
||||
|
||||
let server = format!("http://{}", client.server);
|
||||
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert("Content-Type", "application/json".parse()?);
|
||||
|
||||
if let Some(secret) = client.secret {
|
||||
let secret = format!("Bearer {}", secret).parse()?;
|
||||
headers.insert("Authorization", secret);
|
||||
}
|
||||
|
||||
Ok((server, headers))
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub fn get_traffic_ws_url() -> Result<String> {
|
||||
let (url, _) = clash_client_info()?;
|
||||
use crate::module::mihomo::MihomoManager;
|
||||
|
||||
let (url, _) = MihomoManager::get_clash_client_info().unwrap();
|
||||
let ws_url = url.replace("http://", "ws://") + "/traffic";
|
||||
Ok(ws_url)
|
||||
}
|
||||
Reference in New Issue
Block a user