Merge pull request #17 from Stremio/fix/visibility-events-window-show-hide
Some checks failed
Continuous integration / test (push) Has been cancelled

fix(app): send visibility events when window is shown or hidden
This commit is contained in:
Владимир Борисов 2025-02-24 16:38:46 +02:00 committed by GitHub
commit 4e789f79a4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -74,19 +74,25 @@ pub struct MainWindow {
} }
impl MainWindow { impl MainWindow {
fn transmit_window_full_screen_change(&self, full_screen: bool, prevent_close: bool) { fn transmit_window_visibility_change(&self) {
let web_channel = self.webview.channel.borrow(); if let (Ok(web_channel), Ok(style)) = (
let (web_tx, _) = web_channel self.webview.channel.try_borrow(),
.as_ref() self.saved_window_style.try_borrow(),
.expect("Cannont obtain communication channel for the Web UI"); ) {
let web_tx_app = web_tx.clone(); let (web_tx, _) = web_channel
web_tx_app .as_ref()
.send(RPCResponse::visibility_change( .expect("Cannont obtain communication channel for the Web UI");
self.window.visible(), let web_tx_app = web_tx.clone();
prevent_close as u32, web_tx_app
full_screen, .send(RPCResponse::visibility_change(
)) self.window.visible(),
.ok(); style.full_screen as u32,
style.full_screen,
))
.ok();
} else {
eprintln!("Cannot obtain communication channel or window style");
}
} }
fn transmit_window_state_change(&self) { fn transmit_window_state_change(&self) {
if let (Some(hwnd), Ok(web_channel), Ok(style)) = ( if let (Some(hwnd), Ok(web_channel), Ok(style)) = (
@ -344,7 +350,7 @@ impl MainWindow {
self.tray self.tray
.tray_topmost .tray_topmost
.set_checked((saved_style.ex_style as u32 & WS_EX_TOPMOST) == WS_EX_TOPMOST); .set_checked((saved_style.ex_style as u32 & WS_EX_TOPMOST) == WS_EX_TOPMOST);
self.transmit_window_full_screen_change(saved_style.full_screen, true); self.transmit_window_visibility_change();
} }
} }
} }
@ -382,12 +388,14 @@ impl MainWindow {
} }
self.tray.tray_show_hide.set_checked(self.window.visible()); self.tray.tray_show_hide.set_checked(self.window.visible());
self.transmit_window_state_change(); self.transmit_window_state_change();
self.transmit_window_visibility_change();
} }
fn on_show_hide(&self) { fn on_show_hide(&self) {
if self.window.visible() { if self.window.visible() {
self.window.set_visible(false); self.window.set_visible(false);
self.tray.tray_show_hide.set_checked(self.window.visible()); self.tray.tray_show_hide.set_checked(self.window.visible());
self.transmit_window_state_change(); self.transmit_window_state_change();
self.transmit_window_visibility_change();
} else { } else {
self.on_show(); self.on_show();
} }
@ -398,6 +406,6 @@ impl MainWindow {
} }
self.window.set_visible(false); self.window.set_visible(false);
self.tray.tray_show_hide.set_checked(self.window.visible()); self.tray.tray_show_hide.set_checked(self.window.visible());
self.transmit_window_full_screen_change(false, false); self.transmit_window_visibility_change();
} }
} }