feat: added perserve flag to the update command which preserves the new updates

This commit is contained in:
Byson94
2025-09-18 20:17:44 +05:30
parent 10a7f8a1da
commit 9ddfad0fbe
3 changed files with 31 additions and 8 deletions

View File

@@ -5,6 +5,12 @@ All notable changes to `ewwii` are documented here.
This changelog follows the [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) format,
and this project adheres to [Semantic Versioning](https://semver.org/).
## [0.1.4] - [UNRELEASED]
### Added
- `--preserve` flag to the `update` command which preserves the new updates.
## [0.1.3] - 2025-09-17
### Changed

View File

@@ -79,6 +79,7 @@ pub enum DaemonCommand {
ListActiveWindows(DaemonResponseSender),
TriggerUpdateUI {
inject_vars: Option<HashMap<String, String>>,
should_preserve_state: bool,
sender: DaemonResponseSender,
},
CallRhaiFns {
@@ -309,8 +310,8 @@ impl<B: DisplayBackend> App<B> {
let output = format!("{:#?}", &self);
sender.send_success(output)?
}
DaemonCommand::TriggerUpdateUI { inject_vars, sender } => {
let output = match self.trigger_ui_update_with(inject_vars) {
DaemonCommand::TriggerUpdateUI { inject_vars, should_preserve_state, sender } => {
let output = match self.trigger_ui_update_with(inject_vars, should_preserve_state) {
Ok(_) => String::new(),
Err(e) => e.to_string(),
};
@@ -676,10 +677,15 @@ impl<B: DisplayBackend> App<B> {
pub fn trigger_ui_update_with(
&self,
inject_vars: Option<HashMap<String, String>>,
should_preserve_state: bool,
) -> Result<()> {
let compiled_ast = self.ewwii_config.get_owned_compiled_ast();
let config_path = self.paths.get_rhai_path();
if !config_path.exists() {
bail!("The configuration file `{}` does not exist", config_path.display());
}
let mut reeval_parser = ParseConfig::new();
let rhai_code = reeval_parser.code_from_file(&config_path)?;
@@ -695,12 +701,18 @@ impl<B: DisplayBackend> App<B> {
if let Some(vars) = inject_vars {
for (name, val) in vars {
scope.set_value(name, Dynamic::from(val));
}
}
scope.set_value(name.clone(), Dynamic::from(val.clone()));
if !config_path.exists() {
bail!("The configuration file `{}` does not exist", config_path.display());
// Preserving the new state.
// ---
// This is esstentially storing the inject variables
// in the poll/listen variable store (or the `pl_handler_store` in self)
if should_preserve_state {
if let Some(maybe_store) = &self.pl_handler_store {
maybe_store.write().unwrap().insert(name.clone(), val);
}
}
}
}
let new_root_widget =

View File

@@ -197,6 +197,10 @@ pub enum ActionWithServer {
/// Only variables used by the widget tree will affect the UI.
#[arg(long = "inject", short, value_parser = parse_inject_var_map)]
inject_vars: Option<HashMap<String, String>>,
/// Preserve the new updates. Only meaningful if used with inject.
#[arg(long = "preserve", short = 'p')]
should_preserve_state: bool,
},
/// Call rhai functions. (NOTE: All poll/listen will default to their initial value)
@@ -267,9 +271,10 @@ impl ActionWithServer {
self,
) -> (app::DaemonCommand, Option<daemon_response::DaemonResponseReceiver>) {
let command = match self {
ActionWithServer::TriggerUpdateUI { inject_vars } => {
ActionWithServer::TriggerUpdateUI { inject_vars, should_preserve_state } => {
return with_response_channel(|sender| app::DaemonCommand::TriggerUpdateUI {
inject_vars,
should_preserve_state,
sender,
})
}