From dea260331727f8f90953b11905a9e4e50350c3b1 Mon Sep 17 00:00:00 2001 From: MaxVerevkin Date: Mon, 18 Mar 2024 08:39:55 +0200 Subject: [PATCH] prevent potential panic --- src/dbus_server.rs | 18 ++++++------------ src/wayland.rs | 10 ++++------ 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/dbus_server.rs b/src/dbus_server.rs index 6caafc0..476eb29 100644 --- a/src/dbus_server.rs +++ b/src/dbus_server.rs @@ -478,12 +478,9 @@ fn signal_set_property_to_outputs(ctx: PropContext, value: Param) .iter() .filter(|output| output.color_changed()) { - signal_change( - &mut ctx.conn.send, - &output.object_path(), - ctx.name, - value.clone(), - ); + if let Some(path) = output.object_path() { + signal_change(&mut ctx.conn.send, &path, ctx.name, value.clone()); + } } } @@ -498,11 +495,8 @@ fn signal_updated_property_to_outputs( .iter() .filter(|output| output.color_changed()) { - signal_change( - &mut ctx.conn.send, - &output.object_path(), - name, - value.clone(), - ); + if let Some(path) = output.object_path() { + signal_change(&mut ctx.conn.send, &path, name, value.clone()); + } } } diff --git a/src/wayland.rs b/src/wayland.rs index 28daea6..db78656 100644 --- a/src/wayland.rs +++ b/src/wayland.rs @@ -107,10 +107,6 @@ impl Output { self.reg_name } - pub fn name(&self) -> &str { - self.name.as_ref().unwrap() - } - pub fn color(&self) -> Color { self.color } @@ -128,8 +124,10 @@ impl Output { self.color_changed = true; } - pub fn object_path(&self) -> String { - format!("/outputs/{}", self.name().replace('-', "_")) + pub fn object_path(&self) -> Option { + self.name + .as_deref() + .map(|name| format!("/outputs/{}", name.replace('-', "_"))) } fn update_displayed_color(&mut self, conn: &mut Connection) -> Result<()> {