diff --git a/cosmic-applet-graphics/src/window.rs b/cosmic-applet-graphics/src/window.rs index 294fbeb6..f466b176 100644 --- a/cosmic-applet-graphics/src/window.rs +++ b/cosmic-applet-graphics/src/window.rs @@ -43,6 +43,7 @@ pub struct Window { popup: Option, graphics_mode: Option, dbus: Option<(Connection, PowerDaemonProxy<'static>)>, + switchable: bool, } #[allow(dead_code)] @@ -50,7 +51,7 @@ pub struct Window { pub enum Message { CurrentGraphics(Option), AppliedGraphics(Option), - DBusInit(Option<(Connection, PowerDaemonProxy<'static>)>), + DBusInit(Option<(Connection, PowerDaemonProxy<'static>)>, bool), SelectGraphicsMode(Graphics), TogglePopup, PopupClosed(window::Id), @@ -72,9 +73,18 @@ impl cosmic::Application for Window { }; ( window, - iced::Command::perform(dbus::init(), |x| { - cosmic::app::message::app(Message::DBusInit(x)) - }), + iced::Command::perform( + async { + let dbus = dbus::init().await; + let switchable = if let Some((_, proxy)) = dbus.as_ref() { + proxy.get_switchable().await.ok().unwrap_or(false) + } else { + false + }; + (dbus, switchable) + }, + |(dbus, switchable)| cosmic::app::message::app(Message::DBusInit(dbus, switchable)), + ), ) } @@ -132,7 +142,11 @@ impl cosmic::Application for Window { return iced::Command::batch(commands).map(cosmic::app::message::app); } } - Message::DBusInit(dbus) => { + Message::DBusInit(dbus, switchable) => { + self.switchable = switchable; + if !switchable { + std::process::exit(0); + } if dbus.is_none() { eprintln!("Could not connect to com.system76.PowerDaemon. Exiting."); std::process::exit(0); @@ -209,6 +223,9 @@ impl cosmic::Application for Window { } fn view(&self) -> Element { + if !self.switchable { + return horizontal_space(1.0).into(); + } match self.core.applet.anchor { PanelAnchor::Left | PanelAnchor::Right => self .core