feat: 添加代理类型选项列表功能,支持 HTTP 和 SOCKS5
This commit is contained in:
@@ -1,7 +1,14 @@
|
|||||||
use crate::config::{AppConfig, AppConfigState};
|
use crate::config::{AppConfig, AppConfigState, ProxyKind};
|
||||||
use tauri::State;
|
use tauri::State;
|
||||||
use tauri::{AppHandle, WebviewWindow};
|
use tauri::{AppHandle, WebviewWindow};
|
||||||
|
|
||||||
|
#[derive(serde::Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct SelectOption {
|
||||||
|
pub label: String,
|
||||||
|
pub value: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn set_window_title(
|
pub fn set_window_title(
|
||||||
app_handle: AppHandle,
|
app_handle: AppHandle,
|
||||||
@@ -33,3 +40,24 @@ pub fn save_app_config(
|
|||||||
.set(config)
|
.set(config)
|
||||||
.map_err(|e| format!("更新应用配置状态失败: {e}"))
|
.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",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ pub fn run() {
|
|||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
commands::set_window_title,
|
commands::set_window_title,
|
||||||
commands::load_app_config,
|
commands::load_app_config,
|
||||||
commands::save_app_config
|
commands::save_app_config,
|
||||||
|
commands::list_proxy_kind_options
|
||||||
])
|
])
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
|
|||||||
Reference in New Issue
Block a user