mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
refactor: remove redundant logic
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
use super::CmdResult;
|
||||
use crate::{core::handle, module::mihomo::MihomoManager};
|
||||
use crate::module::mihomo::MihomoManager;
|
||||
use once_cell::sync::Lazy;
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
static LAST_REFRESH_TIME: Lazy<Mutex<Option<Instant>>> = Lazy::new(|| Mutex::new(None));
|
||||
static LAST_EVENT_TIME: Lazy<Mutex<Option<Instant>>> = Lazy::new(|| Mutex::new(None));
|
||||
static IS_REFRESHING: AtomicBool = AtomicBool::new(false);
|
||||
const REFRESH_INTERVAL: Duration = Duration::from_secs(3);
|
||||
const EVENT_INTERVAL: Duration = Duration::from_secs(1);
|
||||
const REFRESH_INTERVAL: Duration = Duration::from_secs(5);
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_proxies() -> CmdResult<serde_json::Value> {
|
||||
@@ -51,31 +49,7 @@ pub async fn get_providers_proxies() -> CmdResult<serde_json::Value> {
|
||||
let manager = MihomoManager::global();
|
||||
match manager.refresh_providers_proxies().await {
|
||||
Ok(_) => {
|
||||
log::debug!(target: "app", "providers_proxies后台刷新成功");
|
||||
|
||||
let should_send_event = {
|
||||
let mut last_event = LAST_EVENT_TIME.lock();
|
||||
match *last_event {
|
||||
Some(last_time) => {
|
||||
if last_time.elapsed() > EVENT_INTERVAL {
|
||||
*last_event = Some(Instant::now());
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
None => {
|
||||
*last_event = Some(Instant::now());
|
||||
true
|
||||
}
|
||||
}
|
||||
};
|
||||
if should_send_event {
|
||||
handle::Handle::refresh_providers_proxies();
|
||||
log::debug!(target: "app", "已发送providers_proxies刷新事件");
|
||||
} else {
|
||||
log::debug!(target: "app", "跳过providers_proxies事件发送(频率限制)");
|
||||
}
|
||||
log::debug!(target: "app", "providers_proxies静默后台刷新成功");
|
||||
}
|
||||
Err(e) => {
|
||||
log::warn!(target: "app", "providers_proxies后台刷新失败: {}", e);
|
||||
|
||||
Reference in New Issue
Block a user