Skip to content

Instantly share code, notes, and snippets.

@craigcabrey
Created May 6, 2024 22:24
Show Gist options
  • Save craigcabrey/1330a8ad10796f98f5a56cb5fcf6f619 to your computer and use it in GitHub Desktop.
Save craigcabrey/1330a8ad10796f98f5a56cb5fcf6f619 to your computer and use it in GitHub Desktop.
[package]
name = "gnome-shell-dbus-debug"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
async-std = { version = "1.12.0", features = ["attributes"] }
zbus = "4.2.0"
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const iface = `
<node>
<interface name="net.hadess.PowerProfiles">
<property name="ActiveProfile" type="s" access="readwrite"/>
</interface>
</node>`;
const proxyWrapper = Gio.DBusProxy.makeProxyWrapper(iface);
let proxy = new proxyWrapper(
Gio.DBus.system,
"net.hadess.PowerProfiles",
"/net/hadess/PowerProfiles"
);
proxy.connect('g-properties-changed', (changed_properties, invalidated_properties) => {
log("Properties changed, getting active profile:");
log(changed_properties, invalidated_properties);
log(proxy.ActiveProfile);
});
log("Pre set:", proxy.ActiveProfile);
proxy.ActiveProfile = "client-provided-value";
log("Post set:", proxy.ActiveProfile);
let loop = new GLib.MainLoop(null, false);
loop.run();
use std::future::pending;
use zbus::{connection, interface, Result};
struct Handler {
value: String,
}
#[interface(name = "net.hadess.PowerProfiles")]
impl Handler {
#[zbus(property)]
async fn active_profile(&self) -> String {
println!("Getting {}", self.value);
self.value.clone()
}
#[zbus(property)]
async fn set_active_profile(&mut self, value: String) {
println!("Setting to {}", value);
self.value = value.clone()
}
}
#[async_std::main]
async fn main() -> Result<()> {
let handler = Handler {
value: "initial-value".to_string()
};
let _conn = connection::Builder::system()?
.name("net.hadess.PowerProfiles")?
.serve_at("/net/hadess/PowerProfiles", handler)?
.build()
.await?;
Ok(pending::<()>().await)
}
@zeenix
Copy link

zeenix commented May 7, 2024

thanks. I can reproduce the issue too.

Stop & disable power-profiles-daemon: systemctl disable --now power-profiles-daemon

Actually, you can just switch both service and client code to use the session bus instead and then you don't have to do anything special.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment