mirror of
https://github.com/Stremio/stremio-shell-ng.git
synced 2026-04-21 11:51:56 +00:00
Make clippy happy; use VecDeque in webview
This commit is contained in:
parent
3088d1a839
commit
95de5c757d
2 changed files with 9 additions and 10 deletions
|
|
@ -1,5 +1,4 @@
|
||||||
use native_windows_gui::{self as nwg, NativeUi};
|
use native_windows_gui::{self as nwg, NativeUi};
|
||||||
use std::ptr;
|
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
use winapi::um::wincon::GetConsoleWindow;
|
use winapi::um::wincon::GetConsoleWindow;
|
||||||
use winapi::um::winuser::{ShowWindow, SW_HIDE};
|
use winapi::um::winuser::{ShowWindow, SW_HIDE};
|
||||||
|
|
@ -21,7 +20,7 @@ struct Opt {
|
||||||
fn main() {
|
fn main() {
|
||||||
// Hide the terminal window
|
// Hide the terminal window
|
||||||
let window = unsafe { GetConsoleWindow() };
|
let window = unsafe { GetConsoleWindow() };
|
||||||
if window != ptr::null_mut() {
|
if !window.is_null() {
|
||||||
unsafe {
|
unsafe {
|
||||||
ShowWindow(window, SW_HIDE);
|
ShowWindow(window, SW_HIDE);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ use native_windows_gui::{self as nwg, PartialUi};
|
||||||
use once_cell::unsync::OnceCell;
|
use once_cell::unsync::OnceCell;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
use std::collections::VecDeque;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
|
|
@ -18,7 +19,7 @@ pub struct WebView {
|
||||||
pub channel: RefCell<Option<(mpsc::Sender<String>, Arc<Mutex<mpsc::Receiver<String>>>)>>,
|
pub channel: RefCell<Option<(mpsc::Sender<String>, Arc<Mutex<mpsc::Receiver<String>>>)>>,
|
||||||
notice: nwg::Notice,
|
notice: nwg::Notice,
|
||||||
compute: RefCell<Option<thread::JoinHandle<()>>>,
|
compute: RefCell<Option<thread::JoinHandle<()>>>,
|
||||||
message_queue: Arc<Mutex<Vec<String>>>,
|
message_queue: Arc<Mutex<VecDeque<String>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WebView {
|
impl WebView {
|
||||||
|
|
@ -82,9 +83,9 @@ impl PartialUi for WebView {
|
||||||
.get_webview()
|
.get_webview()
|
||||||
.expect("Cannot obtain webview from controller");
|
.expect("Cannot obtain webview from controller");
|
||||||
if let Some(endpoint) = endpoint.get() {
|
if let Some(endpoint) = endpoint.get() {
|
||||||
if let Err(_) = webview
|
if webview
|
||||||
.navigate(endpoint.as_str()) {
|
.navigate(endpoint.as_str()).is_err() {
|
||||||
tx_web.clone().send(format!(r#"{{"id":1,"args":["app-error","Cannot load WEB UI at '{}'"]}}"#, &endpoint).to_string()).ok();
|
tx_web.clone().send(format!(r#"{{"id":1,"args":["app-error","Cannot load WEB UI at '{}'"]}}"#, &endpoint)).ok();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
webview
|
webview
|
||||||
|
|
@ -137,7 +138,7 @@ impl PartialUi for WebView {
|
||||||
*data.compute.borrow_mut() = Some(thread::spawn(move || loop {
|
*data.compute.borrow_mut() = Some(thread::spawn(move || loop {
|
||||||
if let Ok(msg) = rx.recv() {
|
if let Ok(msg) = rx.recv() {
|
||||||
let mut message = message.lock().unwrap();
|
let mut message = message.lock().unwrap();
|
||||||
message.push(msg);
|
message.push_back(msg);
|
||||||
sender.notice();
|
sender.notice();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
@ -165,10 +166,9 @@ impl PartialUi for WebView {
|
||||||
if let Some(controller) = self.controller.get() {
|
if let Some(controller) = self.controller.get() {
|
||||||
let webview = controller.get_webview().expect("Cannot get vebview");
|
let webview = controller.get_webview().expect("Cannot get vebview");
|
||||||
let mut message_queue = message_queue.lock().unwrap();
|
let mut message_queue = message_queue.lock().unwrap();
|
||||||
for msg in message_queue.iter() {
|
for msg in message_queue.drain(..) {
|
||||||
webview.post_web_message_as_string(msg).ok();
|
webview.post_web_message_as_string(msg.as_str()).ok();
|
||||||
}
|
}
|
||||||
*message_queue = vec![];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue