Make clippy happy; use VecDeque in webview

This commit is contained in:
Vladimir Borisov 2021-07-26 09:24:47 +03:00
parent e8dce2535a
commit e9e8dc3bb6
No known key found for this signature in database
GPG key ID: F9A584BE4FCB6603
2 changed files with 9 additions and 10 deletions

View file

@ -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);
} }

View file

@ -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![];
} }
} }
_ => {} _ => {}