diff --git a/qemu-display-listener/Cargo.toml b/qemu-display-listener/Cargo.toml index aa2393d..0025a9b 100644 --- a/qemu-display-listener/Cargo.toml +++ b/qemu-display-listener/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" [dependencies] derivative = "2.2.0" -zbus = "2.0.0-beta" +zbus = { version = "2.0.0-beta", features = ["xml"] } zvariant = { version = "2.4.0", features = ["serde_bytes"] } libc = "0.2.86" glib = { git = "https://github.com/gtk-rs/gtk-rs", optional = true } diff --git a/qemu-display-listener/src/audio.rs b/qemu-display-listener/src/audio.rs index e26b880..164b284 100644 --- a/qemu-display-listener/src/audio.rs +++ b/qemu-display-listener/src/audio.rs @@ -3,6 +3,7 @@ use std::os::unix::net::UnixStream; use std::sync::mpsc::{self, Receiver, SendError}; use std::sync::Arc; use std::{os::unix::io::AsRawFd, thread}; +use std::str::FromStr; use zbus::{dbus_interface, dbus_proxy, export::zvariant::Fd}; @@ -234,6 +235,14 @@ impl Audio { Ok(Self { proxy }) } + pub fn available(conn: &zbus::Connection) -> bool { + // TODO: we may want to generalize interface detection + let ip = zbus::fdo::IntrospectableProxy::new_for(&conn, "org.qemu", "/org/qemu/Display1").unwrap(); + let introspect = zbus::xml::Node::from_str(&ip.introspect().unwrap()).unwrap(); + let has_audio = introspect.nodes().iter().any(|n| n.name().map(|n| n == "Audio").unwrap_or(false)); + has_audio + } + pub fn listen_out(&self) -> Result> { let (p0, p1) = UnixStream::pair()?; let (tx, rx) = mpsc::channel(); diff --git a/qemu-gtk4/src/application.rs b/qemu-gtk4/src/application.rs index d4c5bd4..776ac1f 100644 --- a/qemu-gtk4/src/application.rs +++ b/qemu-gtk4/src/application.rs @@ -96,11 +96,14 @@ mod imp { } .expect("Failed to connect to DBus"); - if let Ok(audio) = Audio::new(&conn) { - self.audio - .set(GstAudio::new(audio).expect("Failed to setup audio")) - .expect("Audio already set"); + if Audio::available(&conn) { + if let Ok(audio) = Audio::new(&conn) { + self.audio + .set(GstAudio::new(audio).expect("Failed to setup audio")) + .unwrap(); + } } + let console = Console::new(&conn, 0).expect("Failed to get the console"); self.conn.set(conn).expect("Connection already set.");