diff options
| author | Aram Drevekenin <aram@poor.dev> | 2024-08-19 19:02:52 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-19 19:02:52 +0200 |
| commit | cfbc0ff49036edeeb25e52eb67948de7dfe5590b (patch) | |
| tree | 284e2900b54f0d816ed7dd7cfdefc8485c61882e /zellij-server/src | |
| parent | docs(changelog): first run setup wizard (diff) | |
| download | sl0ppij-cfbc0ff49036edeeb25e52eb67948de7dfe5590b.tar.gz sl0ppij-cfbc0ff49036edeeb25e52eb67948de7dfe5590b.tar.xz sl0ppij-cfbc0ff49036edeeb25e52eb67948de7dfe5590b.zip | |
feat(ux): reload config at runtime (#3558)
* feat(ux): reload config at runtime
* style(fmt): rustfmt
Diffstat (limited to 'zellij-server/src')
| -rw-r--r-- | zellij-server/src/lib.rs | 75 |
1 files changed, 43 insertions, 32 deletions
diff --git a/zellij-server/src/lib.rs b/zellij-server/src/lib.rs index b9b23f6c..fe1b3ada 100644 --- a/zellij-server/src/lib.rs +++ b/zellij-server/src/lib.rs @@ -157,24 +157,29 @@ impl ErrorInstruction for ServerInstruction { #[derive(Debug, Clone, Default)] pub(crate) struct SessionConfiguration { runtime_config: HashMap<ClientId, Config>, // if present, overrides the saved_config - saved_config: HashMap<ClientId, Config>, // config guaranteed to have been saved to disk + saved_config: HashMap<ClientId, Config>, // the config as it is on disk (not guaranteed), + // when changed, this resets the runtime config to + // be identical to it and override any previous + // changes } impl SessionConfiguration { - pub fn new_saved_config(&mut self, client_id: ClientId, mut new_saved_config: Config) { + pub fn new_saved_config( + &mut self, + client_id: ClientId, + new_saved_config: Config, + ) -> Vec<(ClientId, Config)> { self.saved_config .insert(client_id, new_saved_config.clone()); - if let Some(runtime_config) = self.runtime_config.get_mut(&client_id) { - match new_saved_config.merge(runtime_config.clone()) { - Ok(_) => { - *runtime_config = new_saved_config; - }, - Err(e) => { - log::error!("Failed to update runtime config: {}", e); - }, + + let mut config_changes = vec![]; + for (client_id, current_runtime_config) in self.runtime_config.iter_mut() { + if *current_runtime_config != new_saved_config { + *current_runtime_config = new_saved_config.clone(); + config_changes.push((*client_id, new_saved_config.clone())) } } - // TODO: handle change by propagating to all the relevant places + config_changes } pub fn set_client_saved_configuration(&mut self, client_id: ClientId, client_config: Config) { self.saved_config.insert(client_id, client_config); @@ -255,6 +260,24 @@ impl SessionMetaData { self.current_input_modes.insert(client_id, input_mode); } } + pub fn propagate_configuration_changes(&mut self, config_changes: Vec<(ClientId, Config)>) { + for (client_id, new_config) in config_changes { + self.senders + .send_to_screen(ScreenInstruction::Reconfigure { + client_id, + keybinds: Some(new_config.keybinds.clone()), + default_mode: new_config.options.default_mode, + }) + .unwrap(); + self.senders + .send_to_plugin(PluginInstruction::Reconfigure { + client_id, + keybinds: Some(new_config.keybinds), + default_mode: new_config.options.default_mode, + }) + .unwrap(); + } + } } impl Drop for SessionMetaData { @@ -1032,38 +1055,26 @@ pub fn start_server(mut os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) { session_data .write() .unwrap() - .as_ref() + .as_mut() .unwrap() - .senders - .send_to_screen(ScreenInstruction::Reconfigure { - client_id, - keybinds: Some(new_config.keybinds.clone()), - default_mode: new_config.options.default_mode, - }) - .unwrap(); - session_data - .write() - .unwrap() - .as_ref() - .unwrap() - .senders - .send_to_plugin(PluginInstruction::Reconfigure { - client_id, - keybinds: Some(new_config.keybinds), - default_mode: new_config.options.default_mode, - }) - .unwrap(); + .propagate_configuration_changes(vec![(client_id, new_config)]); } } }, ServerInstruction::ConfigWrittenToDisk(client_id, new_config) => { - session_data + let changes = session_data .write() .unwrap() .as_mut() .unwrap() .session_configuration .new_saved_config(client_id, new_config); + session_data + .write() + .unwrap() + .as_mut() + .unwrap() + .propagate_configuration_changes(changes); }, ServerInstruction::FailedToWriteConfigToDisk(client_id, file_path) => { session_data |
