From 0e7bd22f4c48f9d5bce12801b21c43d4803e3889 Mon Sep 17 00:00:00 2001 From: guihkx <626206+guihkx@users.noreply.github.com> Date: Thu, 11 Apr 2024 18:57:39 -0300 Subject: [PATCH] Avoid some crashes in the process scanner thread get_window_process() can fail for many reasons, one of them being lack of permission to inject into some processes. Before this change, the process scanner thread could crash by simply launching the Task Manager (taskmgr.exe), before we injected into Spotify. I also added a check for event.window_handle(), just to be safe. --- burnt-sushi/src/spotify_process_scanner.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/burnt-sushi/src/spotify_process_scanner.rs b/burnt-sushi/src/spotify_process_scanner.rs index 683457a..5071349 100644 --- a/burnt-sushi/src/spotify_process_scanner.rs +++ b/burnt-sushi/src/spotify_process_scanner.rs @@ -144,8 +144,12 @@ impl SpotifyProcessScanner { while let Some(event) = event_rx.recv().await { // scoped to make future Send let state = { - let window = event.window_handle().unwrap(); - let process = get_window_process(window)?; + let Some(window) = event.window_handle() else { + continue; + }; + let Ok(process) = get_window_process(window) else { + continue; + }; if !is_spotify_process(process.borrowed()) || !is_main_spotify_window(window) { continue; }