From 254fcc988f70989f7b9e5f2b8ccd0a2901733a14 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Mon, 16 Sep 2024 14:41:39 -0700 Subject: [PATCH] fix(bar): use custom windows-icons w/o panics This commit uses a custom fork of windows-icons which removes runtime panics and instead exposes a safe Option based API. --- Cargo.lock | 3 +-- komorebi-bar/Cargo.toml | 2 +- komorebi-bar/src/komorebi.rs | 18 ++++++++++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e34a1f01..978a322e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6115,8 +6115,7 @@ dependencies = [ [[package]] name = "windows-icons" version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8bbc62fa6f23804699b9559429f6f1eb761d215184e011cd365041d202e0b2e" +source = "git+https://github.com/LGUG2Z/windows-icons?rev=d67cc9920aa9b4883393e411fb4fa2ddd4c498b5#d67cc9920aa9b4883393e411fb4fa2ddd4c498b5" dependencies = [ "base64", "image", diff --git a/komorebi-bar/Cargo.toml b/komorebi-bar/Cargo.toml index 908f2bd5..4c31aa80 100644 --- a/komorebi-bar/Cargo.toml +++ b/komorebi-bar/Cargo.toml @@ -33,4 +33,4 @@ tracing = "0.1" tracing-appender = "0.2" tracing-subscriber = { version = "0.3", features = ["env-filter"] } windows = { workspace = true } -windows-icons = "0.1" \ No newline at end of file +windows-icons = { git = "https://github.com/LGUG2Z/windows-icons", rev = "d67cc9920aa9b4883393e411fb4fa2ddd4c498b5" } \ No newline at end of file diff --git a/komorebi-bar/src/komorebi.rs b/komorebi-bar/src/komorebi.rs index e9471605..2c9f0ca4 100644 --- a/komorebi-bar/src/komorebi.rs +++ b/komorebi-bar/src/komorebi.rs @@ -223,8 +223,13 @@ impl KomorebiNotificationState { if let Ok(title) = window.title() { self.focused_window_title.clone_from(&title); self.focused_window_pid = Some(window.process_id()); - let img = windows_icons::get_icon_by_process_id(window.process_id()); - self.focused_window_icon = Some(img); + if let Some(img) = + windows_icons::get_icon_by_process_id(window.process_id()) + { + self.focused_window_icon = Some(img); + } else { + self.focused_window_icon = None; + } } } } else if let Some(container) = @@ -234,8 +239,13 @@ impl KomorebiNotificationState { if let Ok(title) = window.title() { self.focused_window_title.clone_from(&title); self.focused_window_pid = Some(window.process_id()); - let img = windows_icons::get_icon_by_process_id(window.process_id()); - self.focused_window_icon = Some(img); + if let Some(img) = + windows_icons::get_icon_by_process_id(window.process_id()) + { + self.focused_window_icon = Some(img); + } else { + self.focused_window_icon = None; + } } } } else {