mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 17:15:38 +08:00
refactor: update MihomoManager to handle traffic WebSocket URL and authorization
This commit is contained in:
@@ -2,7 +2,15 @@ use crate::config::Config;
|
||||
use mihomo_api;
|
||||
use once_cell::sync::{Lazy, OnceCell};
|
||||
use std::sync::Mutex;
|
||||
use tauri::http::HeaderMap;
|
||||
use tauri::http::{HeaderMap, HeaderValue};
|
||||
#[cfg(target_os = "macos")]
|
||||
use tokio_tungstenite::tungstenite::http;
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq)]
|
||||
pub struct Rate {
|
||||
pub up: u64,
|
||||
pub down: u64,
|
||||
}
|
||||
|
||||
pub struct MihomoManager {
|
||||
mihomo: Mutex<OnceCell<mihomo_api::MihomoManager>>,
|
||||
@@ -46,4 +54,17 @@ impl MihomoManager {
|
||||
|
||||
Some((server, headers))
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
pub fn get_traffic_ws_url() -> (String, HeaderValue) {
|
||||
let (url, headers) = MihomoManager::get_clash_client_info().unwrap();
|
||||
let ws_url = url.replace("http://", "ws://") + "/traffic";
|
||||
let auth = headers
|
||||
.get("Authorization")
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.to_string();
|
||||
let token = http::header::HeaderValue::from_str(&auth).unwrap();
|
||||
return (ws_url, token);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user