diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 207db6e6..7cb1cf3d 100755 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -245,4 +245,4 @@ iter_on_empty_collections = "deny" # fallible_impl_from = "deny" // 过于激进,暂时不开启 equatable_if_let = "deny" collection_is_never_read = "deny" -branches_sharing_code = "deny" \ No newline at end of file +branches_sharing_code = "deny" diff --git a/src-tauri/src/cmd/system.rs b/src-tauri/src/cmd/system.rs index 2ef6cf72..2486c52d 100644 --- a/src-tauri/src/cmd/system.rs +++ b/src-tauri/src/cmd/system.rs @@ -6,22 +6,11 @@ use crate::{ utils::logging::Type, }; use once_cell::sync::Lazy; -use std::{ - sync::atomic::{AtomicI64, Ordering}, - time::{SystemTime, UNIX_EPOCH}, -}; use tauri_plugin_clipboard_manager::ClipboardExt; +use tokio::time::Instant; // 存储应用启动时间的全局变量 -static APP_START_TIME: Lazy = Lazy::new(|| { - // 获取当前系统时间,转换为毫秒级时间戳 - let now = SystemTime::now() - .duration_since(UNIX_EPOCH) - .unwrap_or_default() - .as_millis() as i64; - - AtomicI64::new(now) -}); +static APP_START_TIME: Lazy = Lazy::new(Instant::now); #[tauri::command] pub async fn export_diagnostic_info() -> CmdResult<()> { @@ -51,14 +40,8 @@ pub async fn get_running_mode() -> Result { /// 获取应用的运行时间(毫秒) #[tauri::command] -pub fn get_app_uptime() -> CmdResult { - let start_time = APP_START_TIME.load(Ordering::Relaxed); - let now = SystemTime::now() - .duration_since(UNIX_EPOCH) - .unwrap_or_default() - .as_millis() as i64; - - Ok(now - start_time) +pub fn get_app_uptime() -> CmdResult { + Ok(APP_START_TIME.elapsed().as_millis()) } /// 检查应用是否以管理员身份运行