chore: update

This commit is contained in:
huzibaca 2024-12-31 11:11:29 +08:00
parent ad335ba005
commit 6b349eda45
3 changed files with 19 additions and 26 deletions

View File

@ -5,6 +5,12 @@ use serde::{Deserialize, Serialize};
use serde_yaml::Mapping; use serde_yaml::Mapping;
use std::collections::HashMap; use std::collections::HashMap;
#[derive(Debug, Clone, Default, PartialEq)]
pub struct Rate {
pub up: u64,
pub down: u64,
}
/// PUT /configs /// PUT /configs
/// path 是绝对路径 /// path 是绝对路径
pub async fn put_configs(path: &str) -> Result<()> { pub async fn put_configs(path: &str) -> Result<()> {

View File

@ -1,6 +1,7 @@
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
#[cfg(target_os = "macos")]
pub mod speed_rate; pub mod speed_rate;
use crate::core::clash_api::Rate;
use crate::utils::dirs; use crate::utils::dirs;
use crate::{ use crate::{
cmds, cmds,
@ -15,7 +16,6 @@ use futures::StreamExt;
use parking_lot::Mutex; use parking_lot::Mutex;
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
use parking_lot::RwLock; use parking_lot::RwLock;
use speed_rate::Rate;
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
pub use speed_rate::{SpeedRate, Traffic}; pub use speed_rate::{SpeedRate, Traffic};
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]

View File

@ -1,31 +1,20 @@
#[cfg(target_os = "macos")] use crate::core::clash_api::{get_traffic_ws_url, Rate};
use { use crate::utils::help::format_bytes_speed;
crate::core::clash_api::get_traffic_ws_url, use anyhow::Result;
crate::utils::help::format_bytes_speed, use futures::Stream;
anyhow::Result, use image::{ImageBuffer, Rgba};
futures::Stream, use imageproc::drawing::draw_text_mut;
image::{ImageBuffer, Rgba}, use parking_lot::Mutex;
imageproc::drawing::draw_text_mut, use rusttype::{Font, Scale};
parking_lot::Mutex, use std::io::Cursor;
rusttype::{Font, Scale}, use std::sync::Arc;
std::io::Cursor, use tokio_tungstenite::tungstenite::Message;
std::sync::Arc,
tokio_tungstenite::tungstenite::Message,
};
#[derive(Debug, Clone, Default, PartialEq)]
pub struct Rate {
pub up: u64,
pub down: u64,
}
#[cfg(target_os = "macos")]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct SpeedRate { pub struct SpeedRate {
rate: Arc<Mutex<(Rate, Rate)>>, rate: Arc<Mutex<(Rate, Rate)>>,
} }
#[cfg(target_os = "macos")]
impl SpeedRate { impl SpeedRate {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
@ -142,14 +131,12 @@ impl SpeedRate {
} }
} }
#[cfg(target_os = "macos")]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Traffic { pub struct Traffic {
pub up: u64, pub up: u64,
pub down: u64, pub down: u64,
} }
#[cfg(target_os = "macos")]
impl Traffic { impl Traffic {
pub async fn get_traffic_stream() -> Result<impl Stream<Item = Result<Traffic, anyhow::Error>>> pub async fn get_traffic_stream() -> Result<impl Stream<Item = Result<Traffic, anyhow::Error>>>
{ {