修复web端下的git配置和语言设置
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use axum::{extract::Extension, Json};
|
||||
use serde::Deserialize;
|
||||
use tauri::Manager;
|
||||
|
||||
use crate::app_error::AppCommandError;
|
||||
@@ -12,6 +13,20 @@ const SYSTEM_PROXY_SETTINGS_KEY: &str = "system_proxy_settings";
|
||||
const SYSTEM_LANGUAGE_SETTINGS_KEY: &str = "system_language_settings";
|
||||
const LANGUAGE_SETTINGS_UPDATED_EVENT: &str = "app://language-settings-updated";
|
||||
|
||||
// Wrapper structs to match Tauri's named parameter convention.
|
||||
// Frontend sends `{ settings: <T> }` which Tauri `invoke()` unwraps automatically,
|
||||
// but in web mode the entire JSON body arrives as-is.
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct UpdateProxySettingsParams {
|
||||
pub settings: SystemProxySettings,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct UpdateLanguageSettingsParams {
|
||||
pub settings: SystemLanguageSettings,
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Read handlers
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -39,8 +54,9 @@ pub async fn get_system_language_settings(
|
||||
|
||||
pub async fn update_system_proxy_settings(
|
||||
Extension(app): Extension<tauri::AppHandle>,
|
||||
Json(settings): Json<SystemProxySettings>,
|
||||
Json(params): Json<UpdateProxySettingsParams>,
|
||||
) -> Result<Json<SystemProxySettings>, AppCommandError> {
|
||||
let settings = params.settings;
|
||||
let db = app.state::<AppDatabase>();
|
||||
|
||||
// TODO: call normalize_proxy_settings once it is made pub(crate) in
|
||||
@@ -64,8 +80,9 @@ pub async fn update_system_proxy_settings(
|
||||
|
||||
pub async fn update_system_language_settings(
|
||||
Extension(app): Extension<tauri::AppHandle>,
|
||||
Json(settings): Json<SystemLanguageSettings>,
|
||||
Json(params): Json<UpdateLanguageSettingsParams>,
|
||||
) -> Result<Json<SystemLanguageSettings>, AppCommandError> {
|
||||
let settings = params.settings;
|
||||
let db = app.state::<AppDatabase>();
|
||||
|
||||
let serialized = serde_json::to_string(&settings).map_err(|e| {
|
||||
|
||||
@@ -41,6 +41,16 @@ pub struct SaveAccountTokenParams {
|
||||
pub token: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct UpdateGitSettingsParams {
|
||||
pub settings: GitSettings,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct UpdateGitHubAccountsParams {
|
||||
pub settings: GitHubAccountsSettings,
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Git detection
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -84,8 +94,9 @@ pub async fn get_git_settings(
|
||||
|
||||
pub async fn update_git_settings(
|
||||
Extension(app): Extension<tauri::AppHandle>,
|
||||
Json(settings): Json<GitSettings>,
|
||||
Json(params): Json<UpdateGitSettingsParams>,
|
||||
) -> Result<Json<GitSettings>, AppCommandError> {
|
||||
let settings = params.settings;
|
||||
let db = app.state::<AppDatabase>();
|
||||
let serialized = serde_json::to_string(&settings).map_err(|e| {
|
||||
AppCommandError::invalid_input("Failed to serialize git settings")
|
||||
@@ -125,8 +136,9 @@ pub async fn get_github_accounts(
|
||||
|
||||
pub async fn update_github_accounts(
|
||||
Extension(app): Extension<tauri::AppHandle>,
|
||||
Json(settings): Json<GitHubAccountsSettings>,
|
||||
Json(params): Json<UpdateGitHubAccountsParams>,
|
||||
) -> Result<Json<GitHubAccountsSettings>, AppCommandError> {
|
||||
let settings = params.settings;
|
||||
let db = app.state::<AppDatabase>();
|
||||
let serialized = serde_json::to_string(&settings).map_err(|e| {
|
||||
AppCommandError::invalid_input("Failed to serialize GitHub accounts")
|
||||
|
||||
Reference in New Issue
Block a user