mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 00:35:38 +08:00
feat: integrate tauri-plugin-clipboard-manager and add system info commands (#5593)
This commit is contained in:
@@ -6,6 +6,7 @@ rust-version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
tauri = { workspace = true }
|
||||
tauri-plugin-clipboard-manager = { workspace = true }
|
||||
parking_lot = { workspace = true }
|
||||
sysinfo = { version = "0.37.2", features = ["network", "system"] }
|
||||
|
||||
|
||||
39
crates/tauri-plugin-clash-verge-sysinfo/src/commands.rs
Normal file
39
crates/tauri-plugin-clash-verge-sysinfo/src/commands.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
use parking_lot::RwLock;
|
||||
use tauri::{AppHandle, Runtime, State, command};
|
||||
use tauri_plugin_clipboard_manager::{ClipboardExt as _, Error};
|
||||
|
||||
use crate::Platform;
|
||||
|
||||
// TODO 迁移,让新的结构体允许通过 tauri command 正确使用 structure.field 方式获取信息
|
||||
#[command]
|
||||
pub fn get_system_info(state: State<'_, RwLock<Platform>>) -> Result<String, Error> {
|
||||
Ok(state.inner().read().to_string())
|
||||
}
|
||||
|
||||
/// 获取应用的运行时间(毫秒)
|
||||
#[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 app_is_admin(state: State<'_, RwLock<Platform>>) -> Result<bool, Error> {
|
||||
Ok(state.inner().read().appinfo.app_is_admin)
|
||||
}
|
||||
|
||||
#[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)
|
||||
}
|
||||
@@ -3,6 +3,8 @@ use std::{
|
||||
time::Instant,
|
||||
};
|
||||
|
||||
pub mod commands;
|
||||
|
||||
#[cfg(windows)]
|
||||
use deelevate::{PrivilegeLevel, Token};
|
||||
use parking_lot::RwLock;
|
||||
@@ -130,11 +132,24 @@ pub fn set_app_core_mode<R: Runtime>(app: &tauri::AppHandle<R>, mode: impl Into<
|
||||
spec.appinfo.app_core_mode = mode.into();
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_current_app_handle_admin<R: Runtime>(app: &tauri::AppHandle<R>) -> bool {
|
||||
let platform_spec = app.state::<RwLock<Platform>>();
|
||||
let spec = platform_spec.read();
|
||||
spec.appinfo.app_is_admin
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
Builder::new("clash_verge_sysinfo")
|
||||
Builder::<R>::new("clash_verge_sysinfo")
|
||||
// TODO 现在 crate 还不是真正的 tauri 插件,必须由主 lib 自行注册
|
||||
// TODO 从 clash-verge 中迁移获取系统信息的 commnand 并实现优雅 structure.field 访问
|
||||
// .invoke_handler(tauri::generate_handler![greet])
|
||||
// .invoke_handler(tauri::generate_handler![
|
||||
// commands::get_system_info,
|
||||
// commands::get_app_uptime,
|
||||
// commands::app_is_admin,
|
||||
// commands::export_diagnostic_info,
|
||||
// ])
|
||||
.setup(move |app, _api| {
|
||||
let app_version = app.package_info().version.to_string();
|
||||
let is_admin = is_binary_admin();
|
||||
|
||||
Reference in New Issue
Block a user