mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-04-18 08:21:34 +08:00
refactor: replace AtomicI64 with Instant for app start time tracking and simplify uptime calculation
This commit is contained in:
parent
04fc9640c6
commit
9a1465ec4d
@ -6,22 +6,11 @@ use crate::{
|
|||||||
utils::logging::Type,
|
utils::logging::Type,
|
||||||
};
|
};
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use std::{
|
|
||||||
sync::atomic::{AtomicI64, Ordering},
|
|
||||||
time::{SystemTime, UNIX_EPOCH},
|
|
||||||
};
|
|
||||||
use tauri_plugin_clipboard_manager::ClipboardExt;
|
use tauri_plugin_clipboard_manager::ClipboardExt;
|
||||||
|
use tokio::time::Instant;
|
||||||
|
|
||||||
// 存储应用启动时间的全局变量
|
// 存储应用启动时间的全局变量
|
||||||
static APP_START_TIME: Lazy<AtomicI64> = Lazy::new(|| {
|
static APP_START_TIME: Lazy<Instant> = Lazy::new(Instant::now);
|
||||||
// 获取当前系统时间,转换为毫秒级时间戳
|
|
||||||
let now = SystemTime::now()
|
|
||||||
.duration_since(UNIX_EPOCH)
|
|
||||||
.unwrap_or_default()
|
|
||||||
.as_millis() as i64;
|
|
||||||
|
|
||||||
AtomicI64::new(now)
|
|
||||||
});
|
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn export_diagnostic_info() -> CmdResult<()> {
|
pub async fn export_diagnostic_info() -> CmdResult<()> {
|
||||||
@ -51,14 +40,8 @@ pub async fn get_running_mode() -> Result<String, String> {
|
|||||||
|
|
||||||
/// 获取应用的运行时间(毫秒)
|
/// 获取应用的运行时间(毫秒)
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn get_app_uptime() -> CmdResult<i64> {
|
pub fn get_app_uptime() -> CmdResult<u128> {
|
||||||
let start_time = APP_START_TIME.load(Ordering::Relaxed);
|
Ok(APP_START_TIME.elapsed().as_millis())
|
||||||
let now = SystemTime::now()
|
|
||||||
.duration_since(UNIX_EPOCH)
|
|
||||||
.unwrap_or_default()
|
|
||||||
.as_millis() as i64;
|
|
||||||
|
|
||||||
Ok(now - start_time)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 检查应用是否以管理员身份运行
|
/// 检查应用是否以管理员身份运行
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user