From 23730088d5d55598f157ba1b9753d950682645b1 Mon Sep 17 00:00:00 2001 From: Alexandr Bogomyakov Date: Thu, 28 Nov 2019 17:59:24 +0300 Subject: [PATCH] Add dbus client. --- Cargo.toml | 1 + src/main.rs | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 14804c6..2a3db26 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,4 @@ edition = "2018" [dependencies] sys-info = "*" +dbus = "*" diff --git a/src/main.rs b/src/main.rs index fd0f2fb..ee77476 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,9 @@ +extern crate dbus; + use std::fs; use std::env; +use std::time::Duration; +use dbus::blocking::Connection; use sys_info; const LOW: &str = "#[fg=colour186]"; @@ -55,6 +59,25 @@ fn cpu_load_bar(bar_len: i32) { print!("{:.2} LA1", one); } +fn player_info() -> Result<(), Box> { + // First open up a connection to the session bus. + let conn = Connection::new_session()?; + + // Second, create a wrapper struct around the connection that makes it easy + // to send method calls to a specific destination and path. + let proxy = conn.with_proxy("org.mpris.MediaPlayer2.cmus", "/org/mpris/MediaPlayer2", Duration::from_millis(5000)); + + // Now make the method call. The ListNames method call takes zero input parameters and + // one output parameter which is an array of strings. + // Therefore the input is a zero tuple "()", and the output is a single tuple "(names,)". + let (names,): (Vec,) = proxy.method_call("org.mpris.MediaPlayer2.cmus", "Metadata", ())?; + + // Let's print all the names to stdout. + for name in names { println!("{}", name); } + + Ok(()) +} + fn main() { let args: Vec = env::args().collect(); let help_text: &str = "Available commands -mb, -cb"; @@ -66,6 +89,7 @@ fn main() { match args[1].as_ref() { "-cb" => cpu_load_bar(15), "-mb" => mem_load_bar(15), + "-p" => { let x = player_info();}, _ => panic!(help_text), } },