diff --git a/Cargo.lock b/Cargo.lock index 5a8e5b0..ab2982a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -107,6 +107,16 @@ dependencies = [ "syn", ] +[[package]] +name = "crossbeam-utils" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" +dependencies = [ + "cfg-if", + "lazy_static", +] + [[package]] name = "embed-resource" version = "1.6.3" @@ -127,12 +137,50 @@ dependencies = [ "num-traits 0.1.43", ] +[[package]] +name = "flume" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24c3fd473b3a903a62609e413ed7538f99e10b665ecb502b5e481a95283f8ab4" +dependencies = [ + "futures-core", + "futures-sink", + "nanorand", + "pin-project", + "spin", +] + [[package]] name = "fuchsia-cprng" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" +[[package]] +name = "futures-core" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d1c26957f23603395cd326b0ffe64124b818f4449552f960d815cfba83a53d" + +[[package]] +name = "futures-sink" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36ea153c13024fe480590b3e3d4cad89a0cfacecc24577b68f86c6ced9c2bc11" + +[[package]] +name = "getrandom" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + [[package]] name = "heck" version = "0.3.3" @@ -184,6 +232,15 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fc7aa29613bd6a620df431842069224d8bc9011086b1db4c0e0cd47fa03ec9a" +[[package]] +name = "lock_api" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712a4d093c9976e24e7dbca41db895dabcbac38eb5f4045393d17a95bdfb1109" +dependencies = [ + "scopeguard", +] + [[package]] name = "log" version = "0.3.9" @@ -225,6 +282,15 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0419348c027fa7be448d2ae7ea0e4e04c2334c31dc4e74ab29f00a2a7ca69204" +[[package]] +name = "nanorand" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "729eb334247daa1803e0a094d0a5c55711b85571179f5ec6e53eccfdf7008958" +dependencies = [ + "getrandom", +] + [[package]] name = "native-windows-derive" version = "1.0.4" @@ -388,6 +454,26 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877630b3de15c0b64cc52f659345724fbf6bdad9bd9566699fc53688f3c34a34" +[[package]] +name = "pin-project" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576bc800220cc65dac09e99e97b08b358cfab6e17078de8dc5fee223bd2d0c08" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e8fe8163d14ce7f0cdac2e040116f22eac817edabff0be91e8aff7e9accf389" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "plotters" version = "0.3.1" @@ -523,6 +609,12 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + [[package]] name = "serde" version = "1.0.126" @@ -563,12 +655,23 @@ dependencies = [ "serde", ] +[[package]] +name = "spin" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "511254be0c5bcf062b019a6c89c01a664aa359ded62f78aa72c6fc137c0590e5" +dependencies = [ + "lock_api", +] + [[package]] name = "stremio-shell-ng" version = "0.1.0" dependencies = [ "bitflags", + "crossbeam-utils", "embed-resource", + "flume", "mpv", "native-windows-derive", "native-windows-gui", @@ -754,6 +857,12 @@ dependencies = [ "libc", ] +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + [[package]] name = "wasm-bindgen" version = "0.2.74" diff --git a/Cargo.toml b/Cargo.toml index 7552ff7..55fe8da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,8 @@ urlencoding = "2.1.0" bitflags = "1.2.1" win32job = "1" parse-display = "0.5.1" +crossbeam-utils = "0.8.5" +flume = "0.10.9" [build-dependencies] embed-resource = "1.3" diff --git a/src/stremio_app/app.rs b/src/stremio_app/app.rs index 5d42610..c704730 100644 --- a/src/stremio_app/app.rs +++ b/src/stremio_app/app.rs @@ -2,7 +2,6 @@ use native_windows_derive::NwgUi; use native_windows_gui as nwg; use serde_json; use std::cell::RefCell; -use std::sync::Arc; use std::thread; use winapi::um::winuser::WS_EX_TOPMOST; @@ -90,7 +89,7 @@ impl MainWindow { .as_ref() .expect("Cannont obtain communication channel for the Player"); let player_tx = player_tx.clone(); - let player_rx = Arc::clone(player_rx); + let player_rx = player_rx.clone(); let web_channel = self.webview.channel.borrow(); let (web_tx, web_rx) = web_channel @@ -98,19 +97,17 @@ impl MainWindow { .expect("Cannont obtain communication channel for the Web UI"); let web_tx_player = web_tx.clone(); let web_tx_web = web_tx.clone(); - let web_rx = Arc::clone(web_rx); + let web_rx = web_rx.clone(); // Read message from player thread::spawn(move || loop { - let rx = player_rx.lock().unwrap(); - rx.iter().map(|msg| web_tx_player.send(msg)).for_each(drop); + player_rx.iter().map(|msg| web_tx_player.send(msg)).for_each(drop); }); // thread let toggle_fullscreen_sender = self.toggle_fullscreen_notice.sender(); let quit_sender = self.quit_notice.sender(); let hide_splash_sender = self.hide_splash_notice.sender(); thread::spawn(move || loop { - let rx = web_rx.lock().unwrap(); - if let Some(msg) = rx + if let Some(msg) = web_rx .recv() .ok() .and_then(|s| serde_json::from_str::(&s).ok()) diff --git a/src/stremio_app/ipc.rs b/src/stremio_app/ipc.rs index a02191f..91cb511 100644 --- a/src/stremio_app/ipc.rs +++ b/src/stremio_app/ipc.rs @@ -1,10 +1,8 @@ use serde::{Deserialize, Serialize}; use serde_json::{self, json}; use std::cell::RefCell; -use std::sync::mpsc; -use std::sync::{Arc, Mutex}; -pub type Channel = RefCell, Arc>>)>>; +pub type Channel = RefCell, flume::Receiver)>>; #[derive(Serialize, Deserialize, Debug, Clone)] pub struct RPCRequest { diff --git a/src/stremio_app/stremio_player/player.rs b/src/stremio_app/stremio_player/player.rs index d9c7308..fd98556 100644 --- a/src/stremio_app/stremio_player/player.rs +++ b/src/stremio_app/stremio_player/player.rs @@ -2,8 +2,6 @@ use crate::stremio_app::ipc; use crate::stremio_app::RPCResponse; use native_windows_gui::{self as nwg, PartialUi}; use std::cell::RefCell; -use std::sync::mpsc; -use std::sync::{Arc, Mutex}; use std::thread; use crate::stremio_app::stremio_player::{ @@ -21,9 +19,9 @@ impl PartialUi for Player { data: &mut Self, parent: Option, ) -> Result<(), nwg::NwgError> { - let (tx, rx) = mpsc::channel::(); - let (tx1, rx1) = mpsc::channel::(); - data.channel = RefCell::new(Some((tx, Arc::new(Mutex::new(rx1))))); + let (tx, rx) = flume::unbounded(); + let (tx1, rx1) = flume::unbounded(); + data.channel = RefCell::new(Some((tx, rx1))); let hwnd = parent .expect("No parent window") .into() diff --git a/src/stremio_app/stremio_wevbiew/wevbiew.rs b/src/stremio_app/stremio_wevbiew/wevbiew.rs index 5c709f4..8166d93 100644 --- a/src/stremio_app/stremio_wevbiew/wevbiew.rs +++ b/src/stremio_app/stremio_wevbiew/wevbiew.rs @@ -7,7 +7,6 @@ use std::cell::RefCell; use std::collections::VecDeque; use std::mem; use std::rc::Rc; -use std::sync::mpsc; use std::sync::{Arc, Mutex}; use std::thread; use urlencoding::decode; @@ -47,10 +46,10 @@ impl PartialUi for WebView { data: &mut Self, parent: Option, ) -> Result<(), nwg::NwgError> { - let (tx, rx) = mpsc::channel::(); + let (tx, rx) = flume::unbounded(); let tx_drag_drop = tx.clone(); - let (tx_web, rx_web) = mpsc::channel::(); - data.channel = RefCell::new(Some((tx, Arc::new(Mutex::new(rx_web))))); + let (tx_web, rx_web) = flume::unbounded(); + data.channel = RefCell::new(Some((tx, rx_web))); let parent = parent.expect("No parent window").into();