feat: 添加代理类型选项列表功能,支持 HTTP 和 SOCKS5

This commit is contained in:
Vixalie
2026-03-29 22:19:49 +08:00
parent 7655a8d441
commit e726dfce11
2 changed files with 31 additions and 2 deletions

View File

@@ -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<SelectOption> {
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",
}
}

View File

@@ -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");