2024-09-14 10:33:40 +00:00
use zbus ::{ Connection , Result } ;
2024-09-01 08:20:17 +00:00
use futures_util ::stream ::TryStreamExt ;
2024-08-27 11:28:05 +00:00
#[ tokio::main ]
async fn main ( ) -> Result < ( ) > {
let connection = Connection ::session ( ) . await ? ;
2024-09-01 08:20:17 +00:00
connection
2024-09-14 10:33:40 +00:00
. request_name ( " org.freedesktop.Notifications " ) // Requesting dbus for this service name. Any other services using this name should be stopped/disabled before this
2024-09-01 08:20:17 +00:00
. await ? ;
2024-08-25 21:10:15 +00:00
2024-09-14 10:33:40 +00:00
let mut stream = zbus ::MessageStream ::from ( & connection ) ; // Convert connection to a MessageStream, yields Message items
2024-09-01 11:31:19 +00:00
while let Some ( msg ) = stream . try_next ( ) . await ? {
2024-09-14 10:33:40 +00:00
println! ( " {} " , msg ) ;
let msg_header = msg . header ( ) ;
dbg! ( & msg ) ;
match msg_header . message_type ( ) {
zbus ::message ::Type ::MethodCall = > {
// real code would check msg_header path(), interface() and member()
// handle invalid calls, introspection, errors etc
let body = msg . body ( ) ;
let arg : & str = body . deserialize ( ) ? ;
println! ( " {} " , arg ) ;
connection . reply ( & msg , & ( format! ( " Hello {} ! " , arg ) ) ) . await ? ;
// break;
}
_ = > continue ,
}
2024-09-01 11:31:19 +00:00
}
Ok ( ( ) )
}