mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-08 02:52:07 +08:00
54 lines
1.6 KiB
Rust
54 lines
1.6 KiB
Rust
use parking_lot::RwLock;
|
|
use serde::Serialize;
|
|
use tauri::{AppHandle, Runtime, State, command};
|
|
use tauri_plugin_clipboard_manager::{ClipboardExt as _, Error};
|
|
|
|
use crate::Platform;
|
|
|
|
#[derive(Serialize)]
|
|
pub struct SystemInfo {
|
|
pub system_name: String,
|
|
pub system_version: String,
|
|
pub system_kernel_version: String,
|
|
pub system_arch: String,
|
|
pub app_version: String,
|
|
pub app_core_mode: String,
|
|
pub app_is_admin: bool,
|
|
}
|
|
|
|
impl From<Platform> for SystemInfo {
|
|
fn from(platform: Platform) -> Self {
|
|
Self {
|
|
system_name: platform.sysinfo.system_name,
|
|
system_version: platform.sysinfo.system_version,
|
|
system_kernel_version: platform.sysinfo.system_kernel_version,
|
|
system_arch: platform.sysinfo.system_arch,
|
|
app_version: platform.appinfo.app_version,
|
|
app_core_mode: platform.appinfo.app_core_mode,
|
|
app_is_admin: platform.appinfo.app_is_admin,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[command]
|
|
pub fn get_system_info(state: State<'_, RwLock<Platform>>) -> Result<SystemInfo, Error> {
|
|
let platform = state.inner().read();
|
|
Ok(SystemInfo::from(platform.clone()))
|
|
}
|
|
|
|
/// 获取应用的运行时间(毫秒)
|
|
#[command]
|
|
pub fn get_app_uptime(state: State<'_, RwLock<Platform>>) -> Result<u128, Error> {
|
|
Ok(state.inner().read().appinfo.app_startup_time.elapsed().as_millis())
|
|
}
|
|
|
|
#[command]
|
|
pub fn export_diagnostic_info<R: Runtime>(
|
|
app_handle: AppHandle<R>,
|
|
state: State<'_, RwLock<Platform>>,
|
|
) -> Result<(), Error> {
|
|
let info = state.inner().read().to_string();
|
|
let clipboard = app_handle.clipboard();
|
|
clipboard.write_text(info)
|
|
}
|