mirror of
https://github.com/EasyTier/EasyTier.git
synced 2025-11-01 12:32:40 +08:00
🎈 perf: 主机名提示显示本机主机名
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -1349,6 +1349,7 @@ dependencies = [
|
|||||||
"chrono",
|
"chrono",
|
||||||
"dashmap",
|
"dashmap",
|
||||||
"easytier",
|
"easytier",
|
||||||
|
"gethostname",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"privilege",
|
"privilege",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ settings: 设置
|
|||||||
exchange_language: Switch to English
|
exchange_language: Switch to English
|
||||||
exit: 退出
|
exit: 退出
|
||||||
chips_placeholder: 例如: {0}, 按回车添加
|
chips_placeholder: 例如: {0}, 按回车添加
|
||||||
hostname_placeholder: 留空默认为设备名称
|
hostname_placeholder: '留空默认为主机名: {0}'
|
||||||
off_text: 点击关闭
|
off_text: 点击关闭
|
||||||
on_text: 点击开启
|
on_text: 点击开启
|
||||||
show_config: 显示配置
|
show_config: 显示配置
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ exchange_language: 切换中文
|
|||||||
exit: Exit
|
exit: Exit
|
||||||
|
|
||||||
chips_placeholder: 'e.g: {0}, press Enter to add'
|
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
|
off_text: Press to disable
|
||||||
on_text: Press to enable
|
on_text: Press to enable
|
||||||
show_config: Show Config
|
show_config: Show Config
|
||||||
|
|||||||
@@ -11,7 +11,11 @@ edition = "2021"
|
|||||||
tauri-build = { version = "1", features = [] }
|
tauri-build = { version = "1", features = [] }
|
||||||
|
|
||||||
[dependencies]
|
[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 = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
|
|
||||||
@@ -24,7 +28,7 @@ once_cell = "1.18.0"
|
|||||||
dashmap = "5.5.3"
|
dashmap = "5.5.3"
|
||||||
|
|
||||||
privilege = "0.3"
|
privilege = "0.3"
|
||||||
|
gethostname = "0.4.3"
|
||||||
[features]
|
[features]
|
||||||
# This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!!
|
# This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!!
|
||||||
custom-protocol = ["tauri/custom-protocol"]
|
custom-protocol = ["tauri/custom-protocol"]
|
||||||
|
|||||||
@@ -283,6 +283,11 @@ fn collect_network_infos() -> Result<String, String> {
|
|||||||
Ok(serde_json::to_string(&ret).map_err(|e| e.to_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) {
|
fn toggle_window_visibility(window: &Window) {
|
||||||
if window.is_visible().unwrap() {
|
if window.is_visible().unwrap() {
|
||||||
window.hide().unwrap();
|
window.hide().unwrap();
|
||||||
@@ -320,7 +325,8 @@ fn main() {
|
|||||||
parse_network_config,
|
parse_network_config,
|
||||||
run_network_instance,
|
run_network_instance,
|
||||||
retain_network_instance,
|
retain_network_instance,
|
||||||
collect_network_infos
|
collect_network_infos,
|
||||||
|
get_os_hostname
|
||||||
])
|
])
|
||||||
.system_tray(SystemTray::new().with_menu(tray_menu))
|
.system_tray(SystemTray::new().with_menu(tray_menu))
|
||||||
.on_system_tray_event(|app, event| match event {
|
.on_system_tray_event(|app, event| match event {
|
||||||
|
|||||||
3
easytier-gui/src/auto-imports.d.ts
vendored
3
easytier-gui/src/auto-imports.d.ts
vendored
@@ -20,6 +20,7 @@ declare global {
|
|||||||
const getActivePinia: typeof import('pinia')['getActivePinia']
|
const getActivePinia: typeof import('pinia')['getActivePinia']
|
||||||
const getCurrentInstance: typeof import('vue')['getCurrentInstance']
|
const getCurrentInstance: typeof import('vue')['getCurrentInstance']
|
||||||
const getCurrentScope: typeof import('vue')['getCurrentScope']
|
const getCurrentScope: typeof import('vue')['getCurrentScope']
|
||||||
|
const getOsHostname: typeof import('./composables/network')['getOsHostname']
|
||||||
const h: typeof import('vue')['h']
|
const h: typeof import('vue')['h']
|
||||||
const inject: typeof import('vue')['inject']
|
const inject: typeof import('vue')['inject']
|
||||||
const isProxy: typeof import('vue')['isProxy']
|
const isProxy: typeof import('vue')['isProxy']
|
||||||
@@ -108,6 +109,7 @@ declare module 'vue' {
|
|||||||
readonly getActivePinia: UnwrapRef<typeof import('pinia')['getActivePinia']>
|
readonly getActivePinia: UnwrapRef<typeof import('pinia')['getActivePinia']>
|
||||||
readonly getCurrentInstance: UnwrapRef<typeof import('vue')['getCurrentInstance']>
|
readonly getCurrentInstance: UnwrapRef<typeof import('vue')['getCurrentInstance']>
|
||||||
readonly getCurrentScope: UnwrapRef<typeof import('vue')['getCurrentScope']>
|
readonly getCurrentScope: UnwrapRef<typeof import('vue')['getCurrentScope']>
|
||||||
|
readonly getOsHostname: UnwrapRef<typeof import('./composables/network')['getOsHostname']>
|
||||||
readonly h: UnwrapRef<typeof import('vue')['h']>
|
readonly h: UnwrapRef<typeof import('vue')['h']>
|
||||||
readonly inject: UnwrapRef<typeof import('vue')['inject']>
|
readonly inject: UnwrapRef<typeof import('vue')['inject']>
|
||||||
readonly isProxy: UnwrapRef<typeof import('vue')['isProxy']>
|
readonly isProxy: UnwrapRef<typeof import('vue')['isProxy']>
|
||||||
@@ -189,6 +191,7 @@ declare module '@vue/runtime-core' {
|
|||||||
readonly getActivePinia: UnwrapRef<typeof import('pinia')['getActivePinia']>
|
readonly getActivePinia: UnwrapRef<typeof import('pinia')['getActivePinia']>
|
||||||
readonly getCurrentInstance: UnwrapRef<typeof import('vue')['getCurrentInstance']>
|
readonly getCurrentInstance: UnwrapRef<typeof import('vue')['getCurrentInstance']>
|
||||||
readonly getCurrentScope: UnwrapRef<typeof import('vue')['getCurrentScope']>
|
readonly getCurrentScope: UnwrapRef<typeof import('vue')['getCurrentScope']>
|
||||||
|
readonly getOsHostname: UnwrapRef<typeof import('./composables/network')['getOsHostname']>
|
||||||
readonly h: UnwrapRef<typeof import('vue')['h']>
|
readonly h: UnwrapRef<typeof import('vue')['h']>
|
||||||
readonly inject: UnwrapRef<typeof import('vue')['inject']>
|
readonly inject: UnwrapRef<typeof import('vue')['inject']>
|
||||||
readonly isProxy: UnwrapRef<typeof import('vue')['isProxy']>
|
readonly isProxy: UnwrapRef<typeof import('vue')['isProxy']>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import InputGroup from 'primevue/inputgroup'
|
import InputGroup from 'primevue/inputgroup'
|
||||||
import InputGroupAddon from 'primevue/inputgroupaddon'
|
import InputGroupAddon from 'primevue/inputgroupaddon'
|
||||||
|
import { getOsHostname } from '~/composables/network'
|
||||||
import { i18n } from '~/modules/i18n'
|
import { i18n } from '~/modules/i18n'
|
||||||
import { NetworkingMethod } from '~/types/network'
|
import { NetworkingMethod } from '~/types/network'
|
||||||
|
|
||||||
@@ -44,6 +45,12 @@ function validateHostname() {
|
|||||||
curNetwork.value.hostname = name
|
curNetwork.value.hostname = name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const osHostname = ref<string>('')
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
osHostname.value = await getOsHostname()
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -167,7 +174,8 @@ function validateHostname() {
|
|||||||
<div class="flex flex-column gap-2 basis-5/12 grow">
|
<div class="flex flex-column gap-2 basis-5/12 grow">
|
||||||
<label for="hostname">{{ $t('hostname') }}</label>
|
<label for="hostname">{{ $t('hostname') }}</label>
|
||||||
<InputText
|
<InputText
|
||||||
id="hostname" v-model="curNetwork.hostname" aria-describedby="hostname-help" :format="true" @blur="validateHostname"
|
id="hostname" v-model="curNetwork.hostname" aria-describedby="hostname-help" :format="true"
|
||||||
|
:placeholder="$t('hostname_placeholder', [osHostname])" @blur="validateHostname"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -20,3 +20,7 @@ export async function collectNetworkInfos() {
|
|||||||
const ret: string = await invoke('collect_network_infos', {})
|
const ret: string = await invoke('collect_network_infos', {})
|
||||||
return JSON.parse(ret)
|
return JSON.parse(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getOsHostname(): Promise<string> {
|
||||||
|
return await invoke('get_os_hostname')
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user