Skip to content

Commit

Permalink
prevent potential panic
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxVerevkin committed Mar 18, 2024
1 parent e3718e9 commit dea2603
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
18 changes: 6 additions & 12 deletions src/dbus_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,12 +478,9 @@ fn signal_set_property_to_outputs(ctx: PropContext<WaylandState>, 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());
}
}
}

Expand All @@ -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());
}
}
}
10 changes: 4 additions & 6 deletions src/wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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<String> {
self.name
.as_deref()
.map(|name| format!("/outputs/{}", name.replace('-', "_")))
}

fn update_displayed_color(&mut self, conn: &mut Connection<State>) -> Result<()> {
Expand Down

0 comments on commit dea2603

Please sign in to comment.