11
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user