fix: exit if graphics are not switchable

This commit is contained in:
Ashley Wulber 2023-12-15 10:36:47 -05:00 committed by Ashley Wulber
parent 5a0b6e03e9
commit 3c863ed781

View file

@ -144,6 +144,9 @@ impl cosmic::Application for Window {
} }
Message::DBusInit(dbus, switchable) => { Message::DBusInit(dbus, switchable) => {
self.switchable = switchable; self.switchable = switchable;
if !switchable {
std::process::exit(0);
}
if dbus.is_none() { if dbus.is_none() {
eprintln!("Could not connect to com.system76.PowerDaemon. Exiting."); eprintln!("Could not connect to com.system76.PowerDaemon. Exiting.");
std::process::exit(0); std::process::exit(0);
@ -220,12 +223,15 @@ impl cosmic::Application for Window {
} }
fn view(&self) -> Element<Message> { fn view(&self) -> Element<Message> {
if !self.switchable {
return horizontal_space(1.0).into();
}
match self.core.applet.anchor { match self.core.applet.anchor {
PanelAnchor::Left | PanelAnchor::Right => self PanelAnchor::Left | PanelAnchor::Right => self
.core .core
.applet .applet
.icon_button(ID) .icon_button(ID)
.on_press_maybe(self.switchable.then(|| Message::TogglePopup)) .on_press(Message::TogglePopup)
.into(), .into(),
PanelAnchor::Top | PanelAnchor::Bottom => button( PanelAnchor::Top | PanelAnchor::Bottom => button(
row![ row![
@ -254,7 +260,7 @@ impl cosmic::Application for Window {
.padding([0, self.core.applet.suggested_size().0 / 2]) .padding([0, self.core.applet.suggested_size().0 / 2])
.align_items(Alignment::Center), .align_items(Alignment::Center),
) )
.on_press_maybe(self.switchable.then(|| Message::TogglePopup)) .on_press(Message::TogglePopup)
.padding(8) .padding(8)
.width(Length::Shrink) .width(Length::Shrink)
.height(Length::Shrink) .height(Length::Shrink)