mirror of
https://github.com/Stremio/stremio-shell-ng.git
synced 2026-05-12 13:20:52 +00:00
refactor(app): use WM_SETFOCUS event instead to send ipc win-state-change
Some checks failed
Continuous integration / test (push) Has been cancelled
Some checks failed
Continuous integration / test (push) Has been cancelled
This commit is contained in:
parent
972a6fe0a0
commit
20dbac018a
1 changed files with 32 additions and 2 deletions
|
|
@ -13,7 +13,10 @@ use std::{
|
||||||
thread, time,
|
thread, time,
|
||||||
};
|
};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use winapi::um::{winbase::CREATE_BREAKAWAY_FROM_JOB, winuser::WS_EX_TOPMOST};
|
use winapi::um::{
|
||||||
|
winbase::CREATE_BREAKAWAY_FROM_JOB,
|
||||||
|
winuser::{WM_SETFOCUS, WS_EX_TOPMOST},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::stremio_app::{
|
use crate::stremio_app::{
|
||||||
constants::{APP_NAME, UPDATE_ENDPOINT, UPDATE_INTERVAL, WINDOW_MIN_HEIGHT, WINDOW_MIN_WIDTH},
|
constants::{APP_NAME, UPDATE_ENDPOINT, UPDATE_INTERVAL, WINDOW_MIN_HEIGHT, WINDOW_MIN_WIDTH},
|
||||||
|
|
@ -135,6 +138,8 @@ impl MainWindow {
|
||||||
self.window.set_visible(!self.start_hidden);
|
self.window.set_visible(!self.start_hidden);
|
||||||
self.tray.tray_show_hide.set_checked(!self.start_hidden);
|
self.tray.tray_show_hide.set_checked(!self.start_hidden);
|
||||||
|
|
||||||
|
self.handle_on_win_focus();
|
||||||
|
|
||||||
let player_channel = self.player.channel.borrow();
|
let player_channel = self.player.channel.borrow();
|
||||||
let (player_tx, player_rx) = player_channel
|
let (player_tx, player_rx) = player_channel
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
|
@ -345,6 +350,32 @@ impl MainWindow {
|
||||||
} // recv
|
} // recv
|
||||||
}); // thread
|
}); // thread
|
||||||
}
|
}
|
||||||
|
fn handle_on_win_focus(&self) {
|
||||||
|
if let (Some(hwnd), Ok(web_channel), Ok(style)) = (
|
||||||
|
self.window.handle.hwnd(),
|
||||||
|
self.webview.channel.try_borrow(),
|
||||||
|
self.saved_window_style.try_borrow(),
|
||||||
|
) {
|
||||||
|
let state = style.clone().get_window_state(hwnd);
|
||||||
|
drop(style);
|
||||||
|
let (web_tx, _) = web_channel
|
||||||
|
.as_ref()
|
||||||
|
.expect("Cannont obtain communication channel for the Web UI");
|
||||||
|
let web_tx_app = web_tx.clone();
|
||||||
|
|
||||||
|
let handler_id = 0x10001;
|
||||||
|
let handle = self.window.handle;
|
||||||
|
nwg::bind_raw_event_handler(&handle, handler_id, move |_hwnd, msg, _w, _l| {
|
||||||
|
if msg == WM_SETFOCUS {
|
||||||
|
web_tx_app.send(RPCResponse::state_change(state)).ok();
|
||||||
|
}
|
||||||
|
None
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
} else {
|
||||||
|
eprintln!("Cannot obtain window handle or communication channel");
|
||||||
|
}
|
||||||
|
}
|
||||||
fn on_min_max(&self, data: &nwg::EventData) {
|
fn on_min_max(&self, data: &nwg::EventData) {
|
||||||
let data = data.on_min_max();
|
let data = data.on_min_max();
|
||||||
data.set_min_size(WINDOW_MIN_WIDTH, WINDOW_MIN_HEIGHT);
|
data.set_min_size(WINDOW_MIN_WIDTH, WINDOW_MIN_HEIGHT);
|
||||||
|
|
@ -353,7 +384,6 @@ impl MainWindow {
|
||||||
if !self.splash_screen.visible() {
|
if !self.splash_screen.visible() {
|
||||||
self.webview.fit_to_window(self.window.handle.hwnd());
|
self.webview.fit_to_window(self.window.handle.hwnd());
|
||||||
}
|
}
|
||||||
self.transmit_window_state_change();
|
|
||||||
}
|
}
|
||||||
fn on_toggle_fullscreen_notice(&self) {
|
fn on_toggle_fullscreen_notice(&self) {
|
||||||
if let Some(hwnd) = self.window.handle.hwnd() {
|
if let Some(hwnd) = self.window.handle.hwnd() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue