feat: add export diagnostic info functionality (#2856)

This commit is contained in:
Tunglies
2025-03-03 05:58:12 +08:00
committed by GitHub
parent 277390e597
commit aff504bddc
10 changed files with 87 additions and 2 deletions

View File

@@ -14,6 +14,7 @@ pub mod clash;
pub mod verge;
pub mod runtime;
pub mod save_profile;
pub mod system;
// Re-export all command functions for backwards compatibility
pub use profile::*;
@@ -25,4 +26,5 @@ pub use network::*;
pub use clash::*;
pub use verge::*;
pub use runtime::*;
pub use save_profile::*;
pub use save_profile::*;
pub use system::*;

View File

@@ -0,0 +1,17 @@
use super::CmdResult;
use crate::{core::handle, model::sysinfo::PlatformSpecification};
use tauri_plugin_clipboard_manager::ClipboardExt;
#[tauri::command]
pub async fn export_diagnostic_info() -> CmdResult<()> {
let sysinfo = PlatformSpecification::new();
let info = format!("{:?}", sysinfo);
let app_handle = handle::Handle::global().app_handle().unwrap();
let cliboard = app_handle.clipboard();
if let Err(_) = cliboard.write_text(info) {
log::error!(target: "app", "Failed to write to clipboard");
}
Ok(())
}

View File

@@ -4,6 +4,8 @@ mod core;
mod enhance;
mod feat;
mod utils;
mod model;
mod module;
use crate::core::hotkey;
use crate::utils::{resolve, resolve::resolve_scheme, server};
use config::Config;
@@ -191,6 +193,8 @@ pub fn run() {
cmd::list_webdav_backup,
cmd::delete_webdav_backup,
cmd::restore_webdav_backup,
// export diagnostic info for issue reporting
cmd::export_diagnostic_info,
]);
#[cfg(debug_assertions)]

View File

@@ -0,0 +1 @@
pub mod sysinfo;

View File

@@ -0,0 +1,18 @@
use std::fmt::{self, Debug, Formatter};
pub struct PlatformSpecification {
pub system_name: String,
pub system_version: String,
pub system_kernel_version: String,
pub system_arch: String,
}
impl Debug for PlatformSpecification {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(
f,
"System Name: {}\nSystem Version: {}\nSystem kernel Version: {}\nSystem Arch: {}",
self.system_name, self.system_version, self.system_kernel_version, self.system_arch
)
}
}

View File

@@ -0,0 +1 @@
pub mod sysinfo;

View File

@@ -0,0 +1,19 @@
use crate::model::sysinfo::PlatformSpecification;
use sysinfo::System;
impl PlatformSpecification {
pub fn new() -> Self {
let system_name = System::name().unwrap_or("Null".into());
let system_version = System::long_os_version().unwrap_or("Null".into());
let system_kernel_version = System::kernel_version().unwrap_or("Null".into());
let system_arch = std::env::consts::ARCH.to_string();
Self {
system_name,
system_version,
system_kernel_version,
system_arch
}
}
}