mirror of
https://github.com/Stremio/stremio-shell-ng.git
synced 2026-01-11 22:40:32 +00:00
refactor: use OnWindowFocus derive instead of raw event handler
This commit is contained in:
parent
8511d37102
commit
65b7978abd
3 changed files with 5 additions and 36 deletions
5
Cargo.lock
generated
5
Cargo.lock
generated
|
|
@ -819,9 +819,8 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "native-windows-gui"
|
name = "native-windows-gui"
|
||||||
version = "1.0.13"
|
version = "1.0.12"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "git+https://github.com/Stremio/native-windows-gui#87f2b7d594ef8236271e6fe5501e595404d8be4c"
|
||||||
checksum = "4f7003a669f68deb6b7c57d74fff4f8e533c44a3f0b297492440ef4ff5a28454"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
once_cell = "1.19"
|
once_cell = "1.19"
|
||||||
native-windows-gui = { version = "1", features = [
|
native-windows-gui = { git = "https://github.com/Stremio/native-windows-gui", features = [
|
||||||
"high-dpi",
|
"high-dpi",
|
||||||
"notice",
|
"notice",
|
||||||
"tray-notification",
|
"tray-notification",
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,7 @@ use std::{
|
||||||
thread, time,
|
thread, time,
|
||||||
};
|
};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use winapi::um::{
|
use winapi::um::{winbase::CREATE_BREAKAWAY_FROM_JOB, winuser::WS_EX_TOPMOST};
|
||||||
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},
|
||||||
|
|
@ -56,6 +53,7 @@ pub struct MainWindow {
|
||||||
OnMinMaxInfo: [Self::on_min_max(SELF, EVT_DATA)],
|
OnMinMaxInfo: [Self::on_min_max(SELF, EVT_DATA)],
|
||||||
OnWindowMinimize: [Self::transmit_window_state_change],
|
OnWindowMinimize: [Self::transmit_window_state_change],
|
||||||
OnWindowMaximize: [Self::transmit_window_state_change],
|
OnWindowMaximize: [Self::transmit_window_state_change],
|
||||||
|
OnWindowFocus: [Self::transmit_window_state_change],
|
||||||
)]
|
)]
|
||||||
pub window: nwg::Window,
|
pub window: nwg::Window,
|
||||||
#[nwg_partial(parent: window)]
|
#[nwg_partial(parent: window)]
|
||||||
|
|
@ -138,8 +136,6 @@ 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()
|
||||||
|
|
@ -350,32 +346,6 @@ 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);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue