From 52fef9fd4f8cee31c2c0471dd5061a27a0d8be1a Mon Sep 17 00:00:00 2001 From: m1m1sha <18262227804@163.com> Date: Wed, 8 May 2024 21:02:14 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=88=20perf:=20=E4=B8=BB=E6=9C=BA?= =?UTF-8?q?=E5=90=8D=E6=8F=90=E7=A4=BA=E6=98=BE=E7=A4=BA=E6=9C=AC=E6=9C=BA?= =?UTF-8?q?=E4=B8=BB=E6=9C=BA=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 1 + easytier-gui/locales/cn.yml | 2 +- easytier-gui/locales/en.yml | 2 +- easytier-gui/src-tauri/Cargo.toml | 8 ++++++-- easytier-gui/src-tauri/src/main.rs | 8 +++++++- easytier-gui/src/auto-imports.d.ts | 3 +++ easytier-gui/src/components/Config.vue | 10 +++++++++- easytier-gui/src/composables/network.ts | 4 ++++ 8 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5bb95a4..91b2dfa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1349,6 +1349,7 @@ dependencies = [ "chrono", "dashmap", "easytier", + "gethostname", "once_cell", "privilege", "serde", diff --git a/easytier-gui/locales/cn.yml b/easytier-gui/locales/cn.yml index aa2ce02..63cb2bb 100644 --- a/easytier-gui/locales/cn.yml +++ b/easytier-gui/locales/cn.yml @@ -32,7 +32,7 @@ settings: 设置 exchange_language: Switch to English exit: 退出 chips_placeholder: 例如: {0}, 按回车添加 -hostname_placeholder: 留空默认为设备名称 +hostname_placeholder: '留空默认为主机名: {0}' off_text: 点击关闭 on_text: 点击开启 show_config: 显示配置 diff --git a/easytier-gui/locales/en.yml b/easytier-gui/locales/en.yml index 7221c0e..b19c362 100644 --- a/easytier-gui/locales/en.yml +++ b/easytier-gui/locales/en.yml @@ -33,7 +33,7 @@ exchange_language: 切换中文 exit: Exit chips_placeholder: 'e.g: {0}, press Enter to add' -hostname_placeholder: Leave blank and default to device name +hostname_placeholder: 'Leave blank and default to host name: {0}' off_text: Press to disable on_text: Press to enable show_config: Show Config diff --git a/easytier-gui/src-tauri/Cargo.toml b/easytier-gui/src-tauri/Cargo.toml index c98b231..bf702f8 100644 --- a/easytier-gui/src-tauri/Cargo.toml +++ b/easytier-gui/src-tauri/Cargo.toml @@ -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"] diff --git a/easytier-gui/src-tauri/src/main.rs b/easytier-gui/src-tauri/src/main.rs index 6124ee5..6ce7ce3 100644 --- a/easytier-gui/src-tauri/src/main.rs +++ b/easytier-gui/src-tauri/src/main.rs @@ -283,6 +283,11 @@ fn collect_network_infos() -> Result { Ok(serde_json::to_string(&ret).map_err(|e| e.to_string())?) } +#[tauri::command] +fn get_os_hostname() -> Result { + 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 { diff --git a/easytier-gui/src/auto-imports.d.ts b/easytier-gui/src/auto-imports.d.ts index 9fbc786..d337cfb 100644 --- a/easytier-gui/src/auto-imports.d.ts +++ b/easytier-gui/src/auto-imports.d.ts @@ -20,6 +20,7 @@ declare global { const getActivePinia: typeof import('pinia')['getActivePinia'] const getCurrentInstance: typeof import('vue')['getCurrentInstance'] const getCurrentScope: typeof import('vue')['getCurrentScope'] + const getOsHostname: typeof import('./composables/network')['getOsHostname'] const h: typeof import('vue')['h'] const inject: typeof import('vue')['inject'] const isProxy: typeof import('vue')['isProxy'] @@ -108,6 +109,7 @@ declare module 'vue' { readonly getActivePinia: UnwrapRef readonly getCurrentInstance: UnwrapRef readonly getCurrentScope: UnwrapRef + readonly getOsHostname: UnwrapRef readonly h: UnwrapRef readonly inject: UnwrapRef readonly isProxy: UnwrapRef @@ -189,6 +191,7 @@ declare module '@vue/runtime-core' { readonly getActivePinia: UnwrapRef readonly getCurrentInstance: UnwrapRef readonly getCurrentScope: UnwrapRef + readonly getOsHostname: UnwrapRef readonly h: UnwrapRef readonly inject: UnwrapRef readonly isProxy: UnwrapRef diff --git a/easytier-gui/src/components/Config.vue b/easytier-gui/src/components/Config.vue index 0a65ca3..aac1b77 100644 --- a/easytier-gui/src/components/Config.vue +++ b/easytier-gui/src/components/Config.vue @@ -1,6 +1,7 @@