fix(graphics): exit if connection to com.system76.PowerDaemon fails

This commit is contained in:
Ashley Wulber 2023-08-30 19:25:44 -04:00 committed by Ashley Wulber
parent 2d1b8680f9
commit 28446a33ab
2 changed files with 9 additions and 1 deletions

View file

@ -89,5 +89,9 @@ pub async fn init() -> Option<(Connection, PowerDaemonProxy<'static>)> {
_ => return None,
};
if matches!(proxy.introspect().await, Err(zbus::fdo::Error::ServiceUnknown(_))) {
return None;
}
Some((conn, proxy))
}

View file

@ -132,6 +132,10 @@ impl cosmic::Application for Window {
}
}
Message::DBusInit(dbus) => {
if dbus.is_none() {
eprintln!("Could not connect to com.system76.PowerDaemon. Exiting.");
std::process::exit(0);
}
self.dbus = dbus;
return iced::Command::perform(
get_current_graphics(self.dbus.as_ref().unwrap().1.clone()),
@ -139,7 +143,7 @@ impl cosmic::Application for Window {
Message::CurrentGraphics(match cur_graphics {
Ok(g) => Some(g),
Err(err) => {
eprintln!("{err}");
eprintln!("{err:?}");
None
}
})