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