WIP some minor fixes

This commit is contained in:
Stephen Seo 2021-12-14 19:49:31 +09:00
parent 086ab048fc
commit a132d30f59
3 changed files with 20 additions and 12 deletions

View file

@ -43,7 +43,7 @@ impl EventHandler for MPDDisplay {
fn draw(&mut self, ctx: &mut ggez::Context) -> Result<(), GameError> {
graphics::clear(ctx, Color::BLACK);
self.notice_text.draw(ctx, DrawParam::default());
self.notice_text.draw(ctx, DrawParam::default())?;
graphics::present(ctx)
}

View file

@ -68,11 +68,12 @@ fn main() -> Result<(), String> {
..
},
is_synthetic: _,
} => {
if let event::KeyCode::Escape = keycode {
} => match keycode {
event::KeyCode::Escape | event::KeyCode::Q => {
*control_flow = ControlFlow::Exit;
}
}
_ => (),
},
x => println!("Other window event fired: {:?}", x),
},
event::winit_event::Event::MainEventsCleared => {

View file

@ -240,7 +240,7 @@ impl MPDHandler {
)
.map_err(|_| String::from("Failed to get TCP connection"))?;
let mut s = Arc::new(RwLock::new(Self {
let s = Arc::new(RwLock::new(Self {
art_data: Vec::new(),
art_data_size: 0,
current_song_filename: String::new(),
@ -271,12 +271,12 @@ impl MPDHandler {
stop_flag: Arc::new(AtomicBool::new(false)),
}));
let mut s_clone = s.clone();
let mut thread = Arc::new(Mutex::new(thread::spawn(|| Self::handler_loop(s_clone))));
let s_clone = s.clone();
let thread = Arc::new(Mutex::new(thread::spawn(|| Self::handler_loop(s_clone))));
s.write()
.map_err(|_| String::from("Failed to start MPDHandler thread"))?
.self_thread = Some(thread.clone());
.map_err(|_| String::from("Failed to store thread handle in MPDHandler"))?
.self_thread = Some(thread);
Ok(s)
}
@ -329,6 +329,13 @@ impl MPDHandler {
'main: loop {
if !Self::is_reading_picture(h.clone()) {
thread::sleep(SLEEP_DURATION);
if let Ok(write_handle) = h.write() {
if write_handle.self_thread.is_none() {
// main thread failed to store handle to this thread
println!("MPDHandle thread stopping due to failed handle storage");
break 'main;
}
}
}
if let Err(err_string) =
@ -609,10 +616,10 @@ impl MPDHandler {
fn is_reading_picture(h: Arc<RwLock<MPDHandler>>) -> bool {
if let Ok(read_handle) = h.read() {
return read_handle.poll_state == PollState::ReadPicture
|| read_handle.poll_state == PollState::ReadPictureInDir;
read_handle.poll_state == PollState::ReadPicture
|| read_handle.poll_state == PollState::ReadPictureInDir
} else {
return false;
false
}
}
}