From fe13fb0fa40df82dfa177bcf45e65db5eb2eafff Mon Sep 17 00:00:00 2001 From: "Timothy Z." Date: Wed, 22 Apr 2026 18:16:34 +0300 Subject: [PATCH] feat: add media keys support to player --- src/stremio_app/ipc.rs | 3 +++ src/stremio_app/stremio_wevbiew/wevbiew.rs | 25 ++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/stremio_app/ipc.rs b/src/stremio_app/ipc.rs index 22221f6..e5c2d55 100644 --- a/src/stremio_app/ipc.rs +++ b/src/stremio_app/ipc.rs @@ -105,4 +105,7 @@ impl RPCResponse { pub fn update_available() -> String { Self::response_message(Some(json!(["autoupdater-show-notif"]))) } + pub fn media_key(action: &str) -> String { + Self::response_message(Some(json!(["media-key", action]))) + } } diff --git a/src/stremio_app/stremio_wevbiew/wevbiew.rs b/src/stremio_app/stremio_wevbiew/wevbiew.rs index 07ff660..c0fe23f 100644 --- a/src/stremio_app/stremio_wevbiew/wevbiew.rs +++ b/src/stremio_app/stremio_wevbiew/wevbiew.rs @@ -14,7 +14,13 @@ use url::Url; use urlencoding::decode; use webview2::Controller; use winapi::shared::windef::HWND; -use winapi::um::winuser::{GetClientRect, VK_F7, WM_SETFOCUS}; +use winapi::um::winuser::{GetClientRect, VK_F7, WM_APPCOMMAND, WM_SETFOCUS}; + +const APPCOMMAND_MEDIA_NEXTTRACK: u32 = 11; +const APPCOMMAND_MEDIA_PREVIOUSTRACK: u32 = 12; +const APPCOMMAND_MEDIA_PLAY_PAUSE: u32 = 14; +const APPCOMMAND_MEDIA_PLAY: u32 = 46; +const APPCOMMAND_MEDIA_PAUSE: u32 = 47; use super::constants::{WARNING_URL, WHITELISTED_HOSTS}; @@ -61,6 +67,7 @@ impl PartialUi for WebView { println!("Building WebView"); let (tx, rx) = flume::unbounded(); let tx_drag_drop = tx.clone(); + let tx_media = tx.clone(); let (tx_web, rx_web) = flume::unbounded(); let tx_fs = tx_web.clone(); data.channel = RefCell::new(Some((tx, rx_web))); @@ -224,13 +231,27 @@ impl PartialUi for WebView { // handler ids equal or smaller than 0xFFFF are reserved by NWG let handler_id = 0x10000; let controller_clone = data.controller.clone(); - nwg::bind_raw_event_handler(&parent, handler_id, move |_hwnd, msg, _w, _l| { + nwg::bind_raw_event_handler(&parent, handler_id, move |_hwnd, msg, _w, l| { if msg == WM_SETFOCUS { controller_clone.get().and_then(|controller| { controller .move_focus(webview2::MoveFocusReason::Programmatic) .ok() }); + } else if msg == WM_APPCOMMAND { + let cmd = ((l >> 16) & 0xFFF) as u32; + let action = match cmd { + APPCOMMAND_MEDIA_PLAY_PAUSE | APPCOMMAND_MEDIA_PLAY | APPCOMMAND_MEDIA_PAUSE => { + Some("play-pause") + } + APPCOMMAND_MEDIA_NEXTTRACK => Some("next-track"), + APPCOMMAND_MEDIA_PREVIOUSTRACK => Some("previous-track"), + _ => None, + }; + if let Some(action) = action { + tx_media.send(ipc::RPCResponse::media_key(action)).ok(); + return Some(1); + } } None })