Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(graphics): only show the button if the graphics can be switched #174

Merged
merged 2 commits into from
Dec 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions cosmic-applet-graphics/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ pub struct Window {
popup: Option<window::Id>,
graphics_mode: Option<GraphicsMode>,
dbus: Option<(Connection, PowerDaemonProxy<'static>)>,
switchable: bool,
}

#[allow(dead_code)]
#[derive(Clone, Debug)]
pub enum Message {
CurrentGraphics(Option<Graphics>),
AppliedGraphics(Option<Graphics>),
DBusInit(Option<(Connection, PowerDaemonProxy<'static>)>),
DBusInit(Option<(Connection, PowerDaemonProxy<'static>)>, bool),
SelectGraphicsMode(Graphics),
TogglePopup,
PopupClosed(window::Id),
Expand All @@ -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)),
),
)
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -209,6 +223,9 @@ impl cosmic::Application for Window {
}

fn view(&self) -> Element<Message> {
if !self.switchable {
return horizontal_space(1.0).into();
}
match self.core.applet.anchor {
PanelAnchor::Left | PanelAnchor::Right => self
.core
Expand Down
Loading