refactor: replace AtomicI64 with Instant for app start time tracking and simplify uptime calculation

This commit is contained in:
Tunglies
2025-11-06 12:56:00 +08:00
Unverified
parent 04fc9640c6
commit 9a1465ec4d
2 changed files with 5 additions and 22 deletions

View File

@@ -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"
branches_sharing_code = "deny"

View File

@@ -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<AtomicI64> = 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<Instant> = Lazy::new(Instant::now);
#[tauri::command]
pub async fn export_diagnostic_info() -> CmdResult<()> {
@@ -51,14 +40,8 @@ pub async fn get_running_mode() -> Result<String, String> {
/// 获取应用的运行时间(毫秒)
#[tauri::command]
pub fn get_app_uptime() -> CmdResult<i64> {
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<u128> {
Ok(APP_START_TIME.elapsed().as_millis())
}
/// 检查应用是否以管理员身份运行