mirror of
https://github.com/Stremio/stremio-shell-ng.git
synced 2026-01-11 22:40:32 +00:00
Merge pull request #23 from Stremio/fix/app-win-state-changed-on-paint
Some checks are pending
Continuous integration / test (push) Waiting to run
Some checks are pending
Continuous integration / test (push) Waiting to run
fix(app): send ipc win-state-changed on focus
This commit is contained in:
commit
3f00da2d8d
1 changed files with 46 additions and 3 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},
|
||||||
|
|
@ -46,10 +49,22 @@ pub struct MainWindow {
|
||||||
#[nwg_resource(source_embed: Some(&data.embed), source_embed_str: Some("MAINICON"))]
|
#[nwg_resource(source_embed: Some(&data.embed), source_embed_str: Some("MAINICON"))]
|
||||||
pub window_icon: nwg::Icon,
|
pub window_icon: nwg::Icon,
|
||||||
#[nwg_control(icon: Some(&data.window_icon), title: APP_NAME, flags: "MAIN_WINDOW")]
|
#[nwg_control(icon: Some(&data.window_icon), title: APP_NAME, flags: "MAIN_WINDOW")]
|
||||||
#[nwg_events( OnWindowClose: [Self::on_quit(SELF, EVT_DATA)], OnInit: [Self::on_init], OnPaint: [Self::on_paint], OnMinMaxInfo: [Self::on_min_max(SELF, EVT_DATA)], OnWindowMinimize: [Self::transmit_window_state_change], OnWindowMaximize: [Self::transmit_window_state_change] )]
|
#[nwg_events(
|
||||||
|
OnWindowClose: [Self::on_quit(SELF, EVT_DATA)],
|
||||||
|
OnInit: [Self::on_init],
|
||||||
|
OnPaint: [Self::on_paint],
|
||||||
|
OnMinMaxInfo: [Self::on_min_max(SELF, EVT_DATA)],
|
||||||
|
OnWindowMinimize: [Self::transmit_window_state_change],
|
||||||
|
OnWindowMaximize: [Self::transmit_window_state_change],
|
||||||
|
)]
|
||||||
pub window: nwg::Window,
|
pub window: nwg::Window,
|
||||||
#[nwg_partial(parent: window)]
|
#[nwg_partial(parent: window)]
|
||||||
#[nwg_events((tray, MousePressLeftUp): [Self::on_show], (tray_exit, OnMenuItemSelected): [nwg::stop_thread_dispatch()], (tray_show_hide, OnMenuItemSelected): [Self::on_show_hide], (tray_topmost, OnMenuItemSelected): [Self::on_toggle_topmost]) ]
|
#[nwg_events(
|
||||||
|
(tray, MousePressLeftUp): [Self::on_show],
|
||||||
|
(tray_exit, OnMenuItemSelected): [nwg::stop_thread_dispatch()],
|
||||||
|
(tray_show_hide, OnMenuItemSelected): [Self::on_show_hide],
|
||||||
|
(tray_topmost, OnMenuItemSelected): [Self::on_toggle_topmost],
|
||||||
|
)]
|
||||||
pub tray: SystemTray,
|
pub tray: SystemTray,
|
||||||
#[nwg_partial(parent: window)]
|
#[nwg_partial(parent: window)]
|
||||||
pub splash_screen: SplashImage,
|
pub splash_screen: SplashImage,
|
||||||
|
|
@ -123,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()
|
||||||
|
|
@ -333,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);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue