mirror of
https://github.com/Stremio/stremio-shell-ng.git
synced 2026-04-21 16:01:56 +00:00
Move IPC erlated stuff in separate file
This commit is contained in:
parent
263b97e78d
commit
d72219bc37
5 changed files with 63 additions and 53 deletions
54
src/stremio_app/ipc.rs
Normal file
54
src/stremio_app/ipc.rs
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
use std::cell::RefCell;
|
||||||
|
use std::sync::mpsc;
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serde_json::{self, json};
|
||||||
|
|
||||||
|
pub type Channel = RefCell<Option<(mpsc::Sender<String>, Arc<Mutex<mpsc::Receiver<String>>>)>>;
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
pub struct RPCRequest {
|
||||||
|
pub id: u64,
|
||||||
|
pub args: Option<Vec<serde_json::Value>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
pub struct RPCResponseDataTransport {
|
||||||
|
pub properties: Vec<Vec<String>>,
|
||||||
|
pub signals: Vec<String>,
|
||||||
|
pub methods: Vec<Vec<String>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
pub struct RPCResponseData {
|
||||||
|
pub transport: RPCResponseDataTransport,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Serialize, Deserialize, Debug, Clone)]
|
||||||
|
pub struct RPCResponse {
|
||||||
|
pub id: u64,
|
||||||
|
pub object: String,
|
||||||
|
#[serde(rename = "type")]
|
||||||
|
pub response_type: u32,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub data: Option<RPCResponseData>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub args: Option<serde_json::Value>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RPCResponse {
|
||||||
|
pub fn visibility_change(visible: bool, visibility: u32, is_full_screen: bool) -> 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
|
||||||
|
}])),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
serde_json::to_string(&resp).expect("Cannot build response")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,4 +5,6 @@ pub use stremio_wevbiew::WebView;
|
||||||
pub mod stremio_player;
|
pub mod stremio_player;
|
||||||
pub use stremio_player::Player;
|
pub use stremio_player::Player;
|
||||||
pub mod stremio_server;
|
pub mod stremio_server;
|
||||||
pub use stremio_server::StremioServer;
|
pub use stremio_server::StremioServer;
|
||||||
|
pub mod ipc;
|
||||||
|
pub use ipc::{Channel, RPCRequest, RPCResponse, RPCResponseData, RPCResponseDataTransport};
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
use native_windows_derive::NwgUi;
|
use native_windows_derive::NwgUi;
|
||||||
use native_windows_gui as nwg;
|
use native_windows_gui as nwg;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde_json;
|
||||||
use serde_json::{self, json};
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
@ -12,57 +11,10 @@ use winapi::um::winuser::{
|
||||||
WS_EX_WINDOWEDGE, WS_THICKFRAME,
|
WS_EX_WINDOWEDGE, WS_THICKFRAME,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::stremio_app::ipc::{RPCRequest, RPCResponse, RPCResponseData, RPCResponseDataTransport};
|
||||||
use crate::stremio_app::stremio_player::Player;
|
use crate::stremio_app::stremio_player::Player;
|
||||||
use crate::stremio_app::stremio_wevbiew::WebView;
|
use crate::stremio_app::stremio_wevbiew::WebView;
|
||||||
|
|
||||||
//////////////////////////////////////////
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
||||||
struct RPCRequest {
|
|
||||||
id: u64,
|
|
||||||
args: Option<Vec<serde_json::Value>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
||||||
struct RPCResponseDataTransport {
|
|
||||||
properties: Vec<Vec<String>>,
|
|
||||||
signals: Vec<String>,
|
|
||||||
methods: Vec<Vec<String>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
||||||
struct RPCResponseData {
|
|
||||||
transport: RPCResponseDataTransport,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default, Serialize, Deserialize, Debug, Clone)]
|
|
||||||
struct RPCResponse {
|
|
||||||
id: u64,
|
|
||||||
object: String,
|
|
||||||
#[serde(rename = "type")]
|
|
||||||
response_type: u32,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
data: Option<RPCResponseData>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
args: Option<serde_json::Value>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RPCResponse {
|
|
||||||
fn visibility_change(visible: bool, visibility: u32, is_full_screen: bool) -> 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
|
|
||||||
}])),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
serde_json::to_string(&resp).expect("Cannot build response")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//////////////////////////////////////////
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct WindowStyle {
|
pub struct WindowStyle {
|
||||||
pub full_screen: bool,
|
pub full_screen: bool,
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ use std::cell::RefCell;
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
use crate::stremio_app::ipc;
|
||||||
|
|
||||||
#[derive(Default, Serialize, Deserialize, Debug, Clone)]
|
#[derive(Default, Serialize, Deserialize, Debug, Clone)]
|
||||||
pub struct MpvEvent {
|
pub struct MpvEvent {
|
||||||
|
|
@ -48,7 +49,7 @@ impl MpvEvent {
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Player {
|
pub struct Player {
|
||||||
pub channel: RefCell<Option<(mpsc::Sender<String>, Arc<Mutex<mpsc::Receiver<String>>>)>>,
|
pub channel: ipc::Channel,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialUi for Player {
|
impl PartialUi for Player {
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,13 @@ use urlencoding::decode;
|
||||||
use webview2::Controller;
|
use webview2::Controller;
|
||||||
use winapi::shared::windef::HWND__;
|
use winapi::shared::windef::HWND__;
|
||||||
use winapi::um::winuser::*;
|
use winapi::um::winuser::*;
|
||||||
|
use crate::stremio_app::ipc;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct WebView {
|
pub struct WebView {
|
||||||
pub endpoint: Rc<OnceCell<String>>,
|
pub endpoint: Rc<OnceCell<String>>,
|
||||||
controller: Rc<OnceCell<Controller>>,
|
controller: Rc<OnceCell<Controller>>,
|
||||||
pub channel: RefCell<Option<(mpsc::Sender<String>, Arc<Mutex<mpsc::Receiver<String>>>)>>,
|
pub channel: ipc::Channel,
|
||||||
notice: nwg::Notice,
|
notice: nwg::Notice,
|
||||||
compute: RefCell<Option<thread::JoinHandle<()>>>,
|
compute: RefCell<Option<thread::JoinHandle<()>>>,
|
||||||
message_queue: Arc<Mutex<VecDeque<String>>>,
|
message_queue: Arc<Mutex<VecDeque<String>>>,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue