Revert hot-reloading regressions (#1296)

* Revert "Force recreating windows on config change (#1284)"

This reverts commit 29fa1587c3.

* Revert "Avoid recreating windows when only duration changes (#1236)"

This reverts commit b6b7bc8453.
This commit is contained in:
ElKowar 2025-03-25 20:08:09 +01:00 committed by GitHub
parent 5b4cc3e7a8
commit a9aa0f9689
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 46 additions and 80 deletions

View file

@ -217,10 +217,7 @@ impl<B: DisplayBackend> App<B> {
.filter(|(win_id, ..)| win_id.is_empty() || win_id == id) .filter(|(win_id, ..)| win_id.is_empty() || win_id == id)
.map(|(_, n, v)| (n.clone(), v.clone())) .map(|(_, n, v)| (n.clone(), v.clone()))
.collect(); .collect();
self.open_window( self.open_window(&WindowArguments::new_from_args(id.to_string(), config_name.clone(), window_args)?)
&WindowArguments::new_from_args(id.to_string(), config_name.clone(), window_args)?,
false,
)
} }
}) })
.filter_map(Result::err); .filter_map(Result::err);
@ -245,8 +242,7 @@ impl<B: DisplayBackend> App<B> {
let result = if should_toggle && is_open { let result = if should_toggle && is_open {
self.close_window(&instance_id) self.close_window(&instance_id)
} else { } else {
self.open_window( self.open_window(&WindowArguments {
&WindowArguments {
instance_id, instance_id,
window_name, window_name,
pos, pos,
@ -255,9 +251,7 @@ impl<B: DisplayBackend> App<B> {
anchor, anchor,
duration, duration,
args: args.unwrap_or_default().into_iter().collect(), args: args.unwrap_or_default().into_iter().collect(),
}, })
false,
)
}; };
sender.respond_with_result(result)?; sender.respond_with_result(result)?;
@ -391,29 +385,19 @@ impl<B: DisplayBackend> App<B> {
Ok(()) Ok(())
} }
fn open_window(&mut self, window_args: &WindowArguments, dirty: bool) -> Result<()> { fn open_window(&mut self, window_args: &WindowArguments) -> Result<()> {
let instance_id = &window_args.instance_id; let instance_id = &window_args.instance_id;
self.failed_windows.remove(instance_id); self.failed_windows.remove(instance_id);
log::info!("Opening window {} as '{}'", window_args.window_name, instance_id); log::info!("Opening window {} as '{}'", window_args.window_name, instance_id);
// if an instance of this is already running and arguments haven't change, only update duration // if an instance of this is already running, close it
let reuse_window = if !dirty && self.open_windows.contains_key(instance_id) { if self.open_windows.contains_key(instance_id) {
if self.instance_id_to_args.get(instance_id).is_some_and(|args| window_args.can_reuse_window_with_args(args)) {
true
} else {
self.close_window(instance_id)?; self.close_window(instance_id)?;
false
} }
} else {
false
};
self.instance_id_to_args.insert(instance_id.to_string(), window_args.clone()); self.instance_id_to_args.insert(instance_id.to_string(), window_args.clone());
let open_result: Result<_> = (|| { let open_result: Result<_> = (|| {
if reuse_window {
return Ok(());
}
let window_name: &str = &window_args.window_name; let window_name: &str = &window_args.window_name;
let window_def = self.eww_config.get_window(window_name)?.clone(); let window_def = self.eww_config.get_window(window_name)?.clone();
@ -470,21 +454,7 @@ impl<B: DisplayBackend> App<B> {
} }
})); }));
self.open_windows.insert(instance_id.to_string(), eww_window); let duration = window_args.duration;
Ok(())
})();
self.update_window_duration(instance_id, window_args.duration);
if let Err(err) = open_result {
self.failed_windows.insert(instance_id.to_string());
Err(err).with_context(|| format!("failed to open window `{}`", instance_id))
} else {
Ok(())
}
}
fn update_window_duration(&mut self, instance_id: &str, duration: Option<std::time::Duration>) {
if let Some(duration) = duration { if let Some(duration) = duration {
let app_evt_sender = self.app_evt_send.clone(); let app_evt_sender = self.app_evt_send.clone();
@ -510,10 +480,17 @@ impl<B: DisplayBackend> App<B> {
if let Some(old_abort_send) = self.window_close_timer_abort_senders.insert(instance_id.to_string(), abort_send) { if let Some(old_abort_send) = self.window_close_timer_abort_senders.insert(instance_id.to_string(), abort_send) {
_ = old_abort_send.send(()); _ = old_abort_send.send(());
} }
} else {
if let Some(old_abort_send) = self.window_close_timer_abort_senders.remove(instance_id) {
_ = old_abort_send.send(());
} }
self.open_windows.insert(instance_id.to_string(), eww_window);
Ok(())
})();
if let Err(err) = open_result {
self.failed_windows.insert(instance_id.to_string());
Err(err).with_context(|| format!("failed to open window `{}`", instance_id))
} else {
Ok(())
} }
} }
@ -536,7 +513,7 @@ impl<B: DisplayBackend> App<B> {
let window_arguments = self.instance_id_to_args.get(instance_id).with_context(|| { let window_arguments = self.instance_id_to_args.get(instance_id).with_context(|| {
format!("Cannot reopen window, initial parameters were not saved correctly for {instance_id}") format!("Cannot reopen window, initial parameters were not saved correctly for {instance_id}")
})?; })?;
self.open_window(&window_arguments.clone(), true)?; self.open_window(&window_arguments.clone())?;
} }
Ok(()) Ok(())
} }

View file

@ -87,15 +87,4 @@ impl WindowArguments {
Ok(local_variables) Ok(local_variables)
} }
// Compares all values except `duration`, since it's not used by the window itself
pub fn can_reuse_window_with_args(&self, other: &Self) -> bool {
self.window_name == other.window_name
&& self.instance_id == other.instance_id
&& self.anchor == other.anchor
&& self.args == other.args
&& self.monitor == other.monitor
&& self.pos == other.pos
&& self.size == other.size
}
} }