]> git.seodisparate.com - mpd_info_screen/commitdiff
WIP some minor fixes
authorStephen Seo <seo.disparate@gmail.com>
Tue, 14 Dec 2021 10:49:31 +0000 (19:49 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Tue, 14 Dec 2021 10:49:31 +0000 (19:49 +0900)
src/display.rs
src/main.rs
src/mpd_handler.rs

index bdacd2d76d3de59d3d3aafb98c641ca1f4eaf69e..b9f51f592fe01f3fe2df0ae5faf627cc588b172c 100644 (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)
     }
index cbe84d0fbf28240f8265365e53c6f48c2c58a13c..dc9c307ef495b87a77b78d829140d8aa2a969f1e 100644 (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 => {
index 34ef9d801157a19e6e94cb150ca5f4eafb0335c8..b60baaff011808f84b7408c4947c259e6ff53353 100644 (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
         }
     }
 }