refactor: streamline macOS-specific code by consolidating conditional imports and logic in sysopt, tray, lightweight, and mihomo modules

This commit is contained in:
Tunglies
2025-06-11 00:19:06 +08:00
parent 25cfd162f6
commit 5cf3e1a817
5 changed files with 81 additions and 50 deletions

View File

@@ -3,9 +3,11 @@ use crate::{
core::{handle, timer::Timer},
log_err, logging, logging_error,
utils::logging::Type,
AppHandleManager,
};
#[cfg(target_os = "macos")]
use crate::AppHandleManager;
use anyhow::{Context, Result};
use delay_timer::prelude::TaskBuilder;
use once_cell::sync::OnceCell;
@@ -112,6 +114,7 @@ pub fn exit_lightweight_mode() {
exit_lock.0 = false;
}
#[cfg(target_os = "macos")]
pub fn add_light_weight_timer() {
logging_error!(Type::Lightweight, setup_light_weight_timer());
}

View File

@@ -3,7 +3,9 @@ use mihomo_api;
use once_cell::sync::Lazy;
use parking_lot::{Mutex, RwLock};
use std::time::{Duration, Instant};
use tauri::http::{HeaderMap, HeaderValue};
use tauri::http::HeaderMap;
#[cfg(target_os = "macos")]
use tauri::http::HeaderValue;
// 缓存的最大有效期5秒
const CACHE_TTL: Duration = Duration::from_secs(5);
@@ -105,6 +107,7 @@ impl MihomoManager {
}
// 提供默认值的版本避免在connection_info为None时panic
#[cfg(target_os = "macos")]
fn get_clash_client_info_or_default() -> (String, HeaderMap) {
Self::get_clash_client_info().unwrap_or_else(|| {
let mut headers = HeaderMap::new();