refactor: simplify function return types and remove unnecessary wraps

This commit is contained in:
Tunglies
2025-11-15 08:56:58 +08:00
parent 2b0ba4dc95
commit a6cb903fe6
16 changed files with 37 additions and 55 deletions
+4 -7
View File
@@ -3,6 +3,7 @@ use crate::cmd::StringifyErr as _;
use crate::core::{EventDrivenProxyManager, async_proxy_query::AsyncProxyQuery};
use crate::process::AsyncHandler;
use crate::{logging, utils::logging::Type};
use gethostname::gethostname;
use network_interface::NetworkInterface;
use serde_yaml_ng::Mapping;
@@ -61,11 +62,9 @@ pub async fn get_auto_proxy() -> CmdResult<Mapping> {
/// 获取系统主机名
#[tauri::command]
pub fn get_system_hostname() -> CmdResult<String> {
use gethostname::gethostname;
pub fn get_system_hostname() -> String {
// 获取系统主机名,处理可能的非UTF-8字符
let hostname = match gethostname().into_string() {
match gethostname().into_string() {
Ok(name) => name,
Err(os_string) => {
// 对于包含非UTF-8的主机名,使用调试格式化
@@ -73,9 +72,7 @@ pub fn get_system_hostname() -> CmdResult<String> {
// 去掉可能存在的引号
fallback.trim_matches('"').to_string()
}
};
Ok(hostname)
}
}
/// 获取网络接口列表