feat: add backend config change listener to update frontend state

This commit is contained in:
wonfen
2025-05-04 13:28:08 +08:00
parent 23b0493d0b
commit ff5a2c6ca4
3 changed files with 31 additions and 0 deletions

View File

@@ -146,6 +146,9 @@ pub async fn patch_profiles_config(profiles: IProfiles) -> CmdResult<bool> {
// 更新profiles配置
logging!(info, Type::Cmd, true, "正在更新配置草稿");
let current_value = profiles.current.clone();
let _ = Config::profiles().draft().patch_config(profiles);
// 更新配置并进行验证
@@ -156,6 +159,14 @@ pub async fn patch_profiles_config(profiles: IProfiles) -> CmdResult<bool> {
let _ = Tray::global().update_tooltip();
Config::profiles().apply();
wrap_err!(Config::profiles().data().save_file())?;
if let Some(window) = handle::Handle::global().get_window() {
if let Some(current) = &current_value {
logging!(info, Type::Cmd, true, "向前端发送配置变更事件: {}", current);
let _ = window.emit("profile-changed", current.clone());
}
}
Ok(true)
}
Ok((false, error_msg)) => {