mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 17:15:38 +08:00
* feat: add tauri-plugin-mihomo
* refactor: invock mihomo api by use tauri-plugin-mihomo
* chore: todo
* chore: update
* chore: update
* chore: update
* chore: update
* fix: incorrect delay status and update pretty config
* chore: update
* chore: remove cache
* chore: update
* chore: update
* fix: app freezed when change group proxy
* chore: update
* chore: update
* chore: add rustfmt.toml to tauri-plugin-mihomo
* chore: happy clippy
* refactor: connect mihomo websocket
* chore: update
* chore: update
* fix: parse bigint to number
* chore: update
* Revert "fix: parse bigint to number"
This reverts commit 74c006522e.
* chore: use number instead of bigint
* chore: cleanup
* fix: rule data not refresh when switch profile
* chore: update
* chore: cleanup
* chore: update
* fix: traffic graph data display
* feat: add ipc connection pool
* chore: update
* chore: clippy
* fix: incorrect delay status
* fix: typo
* fix: empty proxies tray menu
* chore: clippy
* chore: import tauri-plugin-mihomo by using git repo
* chore: cleanup
* fix: mihomo api
* fix: incorrect delay status
* chore: update tauri-plugin-mihomo dep
chore: update
97 lines
2.5 KiB
Rust
97 lines
2.5 KiB
Rust
use super::CmdResult;
|
|
use crate::{
|
|
core::{CoreManager, handle},
|
|
logging,
|
|
module::sysinfo::PlatformSpecification,
|
|
utils::logging::Type,
|
|
};
|
|
use once_cell::sync::Lazy;
|
|
use std::{
|
|
sync::atomic::{AtomicI64, Ordering},
|
|
time::{SystemTime, UNIX_EPOCH},
|
|
};
|
|
use tauri_plugin_clipboard_manager::ClipboardExt;
|
|
|
|
// 存储应用启动时间的全局变量
|
|
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)
|
|
});
|
|
|
|
#[tauri::command]
|
|
pub async fn export_diagnostic_info() -> CmdResult<()> {
|
|
let sysinfo = PlatformSpecification::new_sync();
|
|
let info = format!("{sysinfo:?}");
|
|
|
|
let app_handle = handle::Handle::app_handle();
|
|
let cliboard = app_handle.clipboard();
|
|
if cliboard.write_text(info).is_err() {
|
|
logging!(error, Type::System, "Failed to write to clipboard");
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub async fn get_system_info() -> CmdResult<String> {
|
|
let sysinfo = PlatformSpecification::new_sync();
|
|
let info = format!("{sysinfo:?}");
|
|
Ok(info)
|
|
}
|
|
|
|
/// 获取当前内核运行模式
|
|
#[tauri::command]
|
|
pub async fn get_running_mode() -> Result<String, String> {
|
|
Ok(CoreManager::global().get_running_mode().to_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)
|
|
}
|
|
|
|
/// 检查应用是否以管理员身份运行
|
|
#[tauri::command]
|
|
#[cfg(target_os = "windows")]
|
|
pub fn is_admin() -> CmdResult<bool> {
|
|
use deelevate::{PrivilegeLevel, Token};
|
|
|
|
let result = Token::with_current_process()
|
|
.and_then(|token| token.privilege_level())
|
|
.map(|level| level != PrivilegeLevel::NotPrivileged)
|
|
.unwrap_or(false);
|
|
|
|
Ok(result)
|
|
}
|
|
|
|
/// 非Windows平台检测是否以管理员身份运行
|
|
#[tauri::command]
|
|
#[cfg(not(target_os = "windows"))]
|
|
pub fn is_admin() -> CmdResult<bool> {
|
|
#[cfg(target_os = "macos")]
|
|
{
|
|
Ok(unsafe { libc::geteuid() } == 0)
|
|
}
|
|
|
|
#[cfg(target_os = "linux")]
|
|
{
|
|
Ok(unsafe { libc::geteuid() } == 0)
|
|
}
|
|
|
|
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
|
|
{
|
|
Ok(false)
|
|
}
|
|
}
|