From 95de5c757d308ef4830595d9dc5eb22a536ece8b Mon Sep 17 00:00:00 2001 From: Vladimir Borisov Date: Mon, 26 Jul 2021 09:24:47 +0300 Subject: [PATCH] Make clippy happy; use VecDeque in webview --- src/main.rs | 3 +-- .../stremio_wevbiew/stremio_wevbiew.rs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index c1b5127..f6b61d4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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); } diff --git a/src/stremio_app/stremio_wevbiew/stremio_wevbiew.rs b/src/stremio_app/stremio_wevbiew/stremio_wevbiew.rs index a3df9f9..5d21eb7 100644 --- a/src/stremio_app/stremio_wevbiew/stremio_wevbiew.rs +++ b/src/stremio_app/stremio_wevbiew/stremio_wevbiew.rs @@ -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, Arc>>)>>, notice: nwg::Notice, compute: RefCell>>, - message_queue: Arc>>, + message_queue: Arc>>, } 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![]; } } _ => {}