🎈 perf: 主机名提示显示本机主机名

This commit is contained in:
m1m1sha
2024-05-08 21:02:14 +08:00
parent e6ad308cd5
commit 52fef9fd4f
8 changed files with 32 additions and 6 deletions

View File

@@ -11,7 +11,11 @@ edition = "2021"
tauri-build = { version = "1", features = [] }
[dependencies]
tauri = { version = "1", features = [ "process-exit", "system-tray", "shell-open"] }
tauri = { version = "1", features = [
"process-exit",
"system-tray",
"shell-open",
] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
@@ -24,7 +28,7 @@ once_cell = "1.18.0"
dashmap = "5.5.3"
privilege = "0.3"
gethostname = "0.4.3"
[features]
# This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!!
custom-protocol = ["tauri/custom-protocol"]

View File

@@ -283,6 +283,11 @@ fn collect_network_infos() -> Result<String, String> {
Ok(serde_json::to_string(&ret).map_err(|e| e.to_string())?)
}
#[tauri::command]
fn get_os_hostname() -> Result<String, String> {
Ok(gethostname::gethostname().to_string_lossy().to_string())
}
fn toggle_window_visibility(window: &Window) {
if window.is_visible().unwrap() {
window.hide().unwrap();
@@ -320,7 +325,8 @@ fn main() {
parse_network_config,
run_network_instance,
retain_network_instance,
collect_network_infos
collect_network_infos,
get_os_hostname
])
.system_tray(SystemTray::new().with_menu(tray_menu))
.on_system_tray_event(|app, event| match event {