fix(stackbar): avoid drops from variable updates

This commit ensures that when we call methods to change
Container.stackbar we are not unintentionally invoking a Drop which
kills a stackbar window that already exists.

Checks have been added to make sure that we not change the value of the
stackbar variable if it is already an Option::Some.

re #746 re #792
This commit is contained in:
LGUG2Z
2024-04-29 13:52:00 -07:00
parent 95990d682b
commit 611fa34567
2 changed files with 25 additions and 16 deletions
+23 -16
View File
@@ -159,27 +159,34 @@ impl Container {
} }
pub fn set_stackbar_mode(&mut self, mode: StackbarMode) { pub fn set_stackbar_mode(&mut self, mode: StackbarMode) {
self.stackbar = match mode { match mode {
StackbarMode::Always => Stackbar::create().ok(), StackbarMode::Always => {
StackbarMode::Never => None, if self.stackbar.is_none() {
StackbarMode::OnStack => { self.stackbar = Stackbar::create().ok();
if self.windows().len() > 1 && self.stackbar().is_none() {
Stackbar::create().ok()
} else {
None
} }
} }
}; StackbarMode::Never => {
} if self.stackbar.is_some() {
self.stackbar = None
}
}
StackbarMode::OnStack => {
if self.windows().len() > 1 && self.stackbar().is_none() {
self.stackbar = Stackbar::create().ok();
}
pub fn renew_stackbar(&mut self) { if self.windows().len() == 1 && self.stackbar.is_some() {
match &self.stackbar { self.stackbar = None;
None => {}
Some(stackbar) => {
if !WindowsApi::is_window(stackbar.hwnd()) {
self.stackbar = Stackbar::create().ok()
} }
} }
} }
} }
pub fn renew_stackbar(&mut self) {
if let Some(stackbar) = &self.stackbar {
if !WindowsApi::is_window(stackbar.hwnd()) {
self.stackbar = Stackbar::create().ok()
}
}
}
} }
+2
View File
@@ -74,6 +74,7 @@ pub struct Stackbar {
impl Drop for Stackbar { impl Drop for Stackbar {
fn drop(&mut self) { fn drop(&mut self) {
if !self.is_cloned { if !self.is_cloned {
tracing::debug!("dropping and calling close_window on stackbar");
let _ = WindowsApi::close_window(self.hwnd()); let _ = WindowsApi::close_window(self.hwnd());
} }
} }
@@ -87,6 +88,7 @@ impl Clone for Stackbar {
} }
} }
} }
impl Stackbar { impl Stackbar {
unsafe extern "system" fn window_proc( unsafe extern "system" fn window_proc(
hwnd: HWND, hwnd: HWND,