steamosctl: Fix get-all-properties

This commit is contained in:
Vicki Pfau 2024-08-02 18:31:17 -07:00
parent db345b3f3d
commit 0871125e3e

View file

@ -9,6 +9,7 @@ use anyhow::Result;
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use itertools::Itertools; use itertools::Itertools;
use std::collections::HashMap; use std::collections::HashMap;
use std::io::Cursor;
use std::ops::Deref; use std::ops::Deref;
use steamos_manager::cec::HdmiCecState; use steamos_manager::cec::HdmiCecState;
use steamos_manager::hardware::FanControlState; use steamos_manager::hardware::FanControlState;
@ -20,9 +21,9 @@ use steamos_manager::proxy::{
WifiPowerManagement1Proxy, WifiPowerManagement1Proxy,
}; };
use steamos_manager::wifi::{WifiBackend, WifiDebugMode, WifiPowerManagement}; use steamos_manager::wifi::{WifiBackend, WifiDebugMode, WifiPowerManagement};
use zbus::fdo::PropertiesProxy; use zbus::fdo::{IntrospectableProxy, PropertiesProxy};
use zbus::names::InterfaceName;
use zbus::{zvariant, Connection}; use zbus::{zvariant, Connection};
use zbus_xml::Node;
#[derive(Parser)] #[derive(Parser)]
#[command(version, about, long_about = None)] #[command(version, about, long_about = None)]
@ -178,16 +179,38 @@ async fn main() -> Result<()> {
// Then process arguments // Then process arguments
match &args.command { match &args.command {
Commands::GetAllProperties => { Commands::GetAllProperties => {
let proxy = IntrospectableProxy::builder(&conn)
.destination("com.steampowered.SteamOSManager1")?
.path("/com/steampowered/SteamOSManager1")?
.build()
.await?;
let introspection = proxy.introspect().await?;
let introspection = Node::from_reader(Cursor::new(introspection))?;
let properties_proxy = PropertiesProxy::new( let properties_proxy = PropertiesProxy::new(
&conn, &conn,
"com.steampowered.SteamOSManager1", "com.steampowered.SteamOSManager1",
"/com/steampowered/SteamOSManager1", "/com/steampowered/SteamOSManager1",
) )
.await?; .await?;
let name = InterfaceName::try_from("com.steampowered.SteamOSManager1.Manager")?;
let properties = properties_proxy let mut properties = HashMap::new();
.get_all(zvariant::Optional::from(Some(name))) for interface in introspection.interfaces() {
.await?; let name = match interface.name() {
name if name
.as_str()
.starts_with("com.steampowered.SteamOSManager1") =>
{
name
}
_ => continue,
};
properties.extend(
properties_proxy
.get_all(zvariant::Optional::from(Some(name)))
.await?,
);
}
for key in properties.keys().sorted() { for key in properties.keys().sorted() {
let value = &properties[key]; let value = &properties[key];
let val = value.deref(); let val = value.deref();