This commit is contained in:
fengchuanhn@gmail.com
2026-05-17 21:13:45 +08:00
parent c18176ba60
commit 9dfeaa9e18
10 changed files with 695 additions and 17 deletions

View File

@@ -1,9 +1,18 @@
use std::collections::HashMap;
use serde::Serialize;
use tauri::State;
use crate::app_config::AppConfig;
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ConfigEntryDetail {
pub name: String,
pub value: String,
pub source: String,
}
#[tauri::command]
pub async fn get_app_config(
app_config: State<'_, AppConfig>,
@@ -17,3 +26,69 @@ pub async fn get_app_config_last_message(
) -> Result<String, String> {
Ok(app_config.last_message().await)
}
/// 仅服务端下发的配置(不含本地覆盖)。
#[tauri::command]
pub async fn get_server_app_config(
app_config: State<'_, AppConfig>,
) -> Result<HashMap<String, String>, String> {
Ok(app_config.server_entries().await)
}
/// 合并配置明细:标明每项来自 local 或 server本地同名已覆盖的不重复列出 server 项)。
#[tauri::command]
pub async fn get_app_config_detail(
app_config: State<'_, AppConfig>,
) -> Result<Vec<ConfigEntryDetail>, String> {
let server = app_config.server_entries().await;
let local = app_config.local_entries().await;
let mut items = Vec::new();
let mut names: Vec<String> = server
.keys()
.chain(local.keys())
.cloned()
.collect();
names.sort();
names.dedup();
for name in names {
if local.contains_key(&name) {
items.push(ConfigEntryDetail {
name: name.clone(),
value: local.get(&name).cloned().unwrap_or_default(),
source: "local".into(),
});
} else if let Some(v) = server.get(&name) {
items.push(ConfigEntryDetail {
name,
value: v.clone(),
source: "server".into(),
});
}
}
Ok(items)
}
#[tauri::command]
pub async fn list_local_app_config(
app_config: State<'_, AppConfig>,
) -> Result<Vec<crate::local_config::LocalConfigItem>, String> {
app_config.list_local_items().await
}
#[tauri::command]
pub async fn set_local_app_config(
app_config: State<'_, AppConfig>,
name: String,
value: String,
mark: Option<String>,
) -> Result<(), String> {
app_config.set_local(name, value, mark).await
}
#[tauri::command]
pub async fn delete_local_app_config(
app_config: State<'_, AppConfig>,
name: String,
) -> Result<(), String> {
app_config.delete_local(&name).await
}