mirror of
https://github.com/Stremio/stremio-shell-ng.git
synced 2026-03-11 21:27:06 +00:00
IPC response message function
This commit is contained in:
parent
e4a262c6d9
commit
4054020d40
3 changed files with 20 additions and 34 deletions
|
|
@ -156,16 +156,11 @@ impl MainWindow {
|
|||
thread::spawn(move || loop {
|
||||
let rx = player_rx.lock().unwrap();
|
||||
if let Ok(msg) = rx.recv() {
|
||||
let resp = RPCResponse {
|
||||
id: 1,
|
||||
object: "transport".to_string(),
|
||||
response_type: 1,
|
||||
args: serde_json::from_str(&msg).ok(),
|
||||
..Default::default()
|
||||
};
|
||||
let resp_json =
|
||||
serde_json::to_string(&resp).expect("Cannot serialize the response");
|
||||
web_tx_player.send(resp_json).ok();
|
||||
web_tx_player
|
||||
.send(RPCResponse::response_message(
|
||||
serde_json::from_str(&msg).ok(),
|
||||
))
|
||||
.ok();
|
||||
} // recv
|
||||
}); // thread
|
||||
|
||||
|
|
|
|||
|
|
@ -37,30 +37,26 @@ pub struct RPCResponse {
|
|||
}
|
||||
|
||||
impl RPCResponse {
|
||||
pub fn visibility_change(visible: bool, visibility: u32, is_full_screen: bool) -> String {
|
||||
pub fn response_message(msg: Option<serde_json::Value>) -> String {
|
||||
let resp = RPCResponse {
|
||||
id: 1,
|
||||
object: "transport".to_string(),
|
||||
response_type: 1,
|
||||
args: Some(json!(["win-visibility-changed" ,{
|
||||
"visible": visible,
|
||||
"visibility": visibility,
|
||||
"isFullscreen": is_full_screen
|
||||
}])),
|
||||
args: msg,
|
||||
..Default::default()
|
||||
};
|
||||
serde_json::to_string(&resp).expect("Cannot build response")
|
||||
}
|
||||
pub fn visibility_change(visible: bool, visibility: u32, is_full_screen: bool) -> String {
|
||||
Self::response_message(Some(json!(["win-visibility-changed" ,{
|
||||
"visible": visible,
|
||||
"visibility": visibility,
|
||||
"isFullscreen": is_full_screen
|
||||
}])))
|
||||
}
|
||||
pub fn state_change(state: u32) -> String {
|
||||
let resp = RPCResponse {
|
||||
id: 1,
|
||||
object: "transport".to_string(),
|
||||
response_type: 1,
|
||||
args: Some(json!(["win-state-changed" ,{
|
||||
"state": state,
|
||||
}])),
|
||||
..Default::default()
|
||||
};
|
||||
serde_json::to_string(&resp).expect("Cannot build response")
|
||||
Self::response_message(Some(json!(["win-state-changed" ,{
|
||||
"state": state,
|
||||
}])))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use crate::stremio_app::ipc;
|
||||
use native_windows_gui::{self as nwg, PartialUi};
|
||||
use once_cell::unsync::OnceCell;
|
||||
use serde_json::json;
|
||||
|
|
@ -13,7 +14,6 @@ use urlencoding::decode;
|
|||
use webview2::Controller;
|
||||
use winapi::shared::windef::HWND__;
|
||||
use winapi::um::winuser::*;
|
||||
use crate::stremio_app::ipc;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct WebView {
|
||||
|
|
@ -88,7 +88,7 @@ impl PartialUi for WebView {
|
|||
if let Some(endpoint) = endpoint.get() {
|
||||
if webview
|
||||
.navigate(endpoint.as_str()).is_err() {
|
||||
tx_web.clone().send(format!(r#"{{"id":1,"args":["app-error","Cannot load WEB UI at '{}'"]}}"#, &endpoint)).ok();
|
||||
tx_web.clone().send(ipc::RPCResponse::response_message(Some(json!(["app-error", format!("Cannot load WEB UI at '{}'", &endpoint)])))).ok();
|
||||
};
|
||||
}
|
||||
webview
|
||||
|
|
@ -110,12 +110,7 @@ impl PartialUi for WebView {
|
|||
}).ok();
|
||||
webview.add_new_window_requested(move |_w, msg| {
|
||||
if let Some(file) = msg.get_uri().ok().and_then(|str| {decode(str.as_str()).ok().map(Cow::into_owned)}) {
|
||||
let data = json!({
|
||||
"object": "transport",
|
||||
"type": 1,
|
||||
"args": ["dragdrop" ,[file]]
|
||||
});
|
||||
tx_drag_drop.send(data.to_string()).ok();
|
||||
tx_drag_drop.send(ipc::RPCResponse::response_message(Some(json!(["dragdrop" ,[file]])))).ok();
|
||||
msg.put_handled(true).ok();
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Reference in a new issue