diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index c74913f..9e97da1 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -1,7 +1,14 @@ -use crate::config::{AppConfig, AppConfigState}; +use crate::config::{AppConfig, AppConfigState, ProxyKind}; use tauri::State; use tauri::{AppHandle, WebviewWindow}; +#[derive(serde::Serialize)] +#[serde(rename_all = "camelCase")] +pub struct SelectOption { + pub label: String, + pub value: String, +} + #[tauri::command] pub fn set_window_title( app_handle: AppHandle, @@ -33,3 +40,24 @@ pub fn save_app_config( .set(config) .map_err(|e| format!("更新应用配置状态失败: {e}")) } + +#[tauri::command] +pub fn list_proxy_kind_options() -> Vec { + vec![ + SelectOption { + label: "HTTP".to_string(), + value: proxy_kind_value(&ProxyKind::Http).to_string(), + }, + SelectOption { + label: "SOCKS5".to_string(), + value: proxy_kind_value(&ProxyKind::Socks5).to_string(), + }, + ] +} + +fn proxy_kind_value(kind: &ProxyKind) -> &'static str { + match kind { + ProxyKind::Http => "Http", + ProxyKind::Socks5 => "Socks5", + } +} diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 8407c05..66c95a5 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -18,7 +18,8 @@ pub fn run() { .invoke_handler(tauri::generate_handler![ commands::set_window_title, commands::load_app_config, - commands::save_app_config + commands::save_app_config, + commands::list_proxy_kind_options ]) .run(tauri::generate_context!()) .expect("error while running tauri application");