mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-05-07 10:14:35 +00:00
1f2517c731
This PR fundamentally restructures the EasyTier GUI, introducing support for service mode and remote mode, transforming it from a simple desktop application into a powerful network management terminal. This change allows users to persistently run the EasyTier core as a background service or remotely manage multiple EasyTier instances, greatly improving deployment flexibility and manageability.
98 lines
3.1 KiB
TypeScript
98 lines
3.1 KiB
TypeScript
import { invoke } from '@tauri-apps/api/core'
|
|
import { Api, type NetworkTypes } from 'easytier-frontend-lib'
|
|
import { GetNetworkMetasResponse } from 'node_modules/easytier-frontend-lib/dist/modules/api'
|
|
|
|
|
|
type NetworkConfig = NetworkTypes.NetworkConfig
|
|
type ValidateConfigResponse = Api.ValidateConfigResponse
|
|
type ListNetworkInstanceIdResponse = Api.ListNetworkInstanceIdResponse
|
|
interface ServiceOptions {
|
|
config_dir: string
|
|
rpc_portal: string
|
|
file_log_level: string
|
|
file_log_dir: string
|
|
}
|
|
|
|
export type ServiceStatus = "Running" | "Stopped" | "NotInstalled"
|
|
|
|
export async function parseNetworkConfig(cfg: NetworkConfig) {
|
|
return invoke<string>('parse_network_config', { cfg })
|
|
}
|
|
|
|
export async function generateNetworkConfig(tomlConfig: string) {
|
|
return invoke<NetworkConfig>('generate_network_config', { tomlConfig })
|
|
}
|
|
|
|
export async function runNetworkInstance(cfg: NetworkConfig, save: boolean) {
|
|
return invoke('run_network_instance', { cfg, save })
|
|
}
|
|
|
|
export async function collectNetworkInfo(instanceId: string) {
|
|
return await invoke<Api.CollectNetworkInfoResponse>('collect_network_info', { instanceId })
|
|
}
|
|
|
|
export async function setLoggingLevel(level: string) {
|
|
return await invoke('set_logging_level', { level })
|
|
}
|
|
|
|
export async function setTunFd(fd: number) {
|
|
return await invoke('set_tun_fd', { fd })
|
|
}
|
|
|
|
export async function getEasytierVersion() {
|
|
return await invoke<string>('easytier_version')
|
|
}
|
|
|
|
export async function listNetworkInstanceIds() {
|
|
return await invoke<ListNetworkInstanceIdResponse>('list_network_instance_ids')
|
|
}
|
|
|
|
export async function deleteNetworkInstance(instanceId: string) {
|
|
return await invoke('remove_network_instance', { instanceId })
|
|
}
|
|
|
|
export async function updateNetworkConfigState(instanceId: string, disabled: boolean) {
|
|
return await invoke('update_network_config_state', { instanceId, disabled })
|
|
}
|
|
|
|
export async function saveNetworkConfig(cfg: NetworkConfig) {
|
|
return await invoke('save_network_config', { cfg })
|
|
}
|
|
|
|
export async function validateConfig(cfg: NetworkConfig) {
|
|
return await invoke<ValidateConfigResponse>('validate_config', { cfg })
|
|
}
|
|
|
|
export async function getConfig(instanceId: string) {
|
|
return await invoke<NetworkConfig>('get_config', { instanceId })
|
|
}
|
|
|
|
export async function sendConfigs() {
|
|
let networkList: NetworkConfig[] = JSON.parse(localStorage.getItem('networkList') || '[]');
|
|
return await invoke('load_configs', { configs: networkList, enabledNetworks: [] })
|
|
}
|
|
|
|
export async function getNetworkMetas(instanceIds: string[]) {
|
|
return await invoke<GetNetworkMetasResponse>('get_network_metas', { instanceIds })
|
|
}
|
|
|
|
export async function initService(opts?: ServiceOptions) {
|
|
return await invoke('init_service', { opts })
|
|
}
|
|
|
|
export async function setServiceStatus(enable: boolean) {
|
|
return await invoke('set_service_status', { enable })
|
|
}
|
|
|
|
export async function getServiceStatus() {
|
|
return await invoke<ServiceStatus>('get_service_status')
|
|
}
|
|
|
|
export async function initRpcConnection(url?: string) {
|
|
return await invoke('init_rpc_connection', { url })
|
|
}
|
|
|
|
export async function isClientRunning() {
|
|
return await invoke<boolean>('is_client_running')
|
|
}
|