@@ -19,26 +19,26 @@ use inputmodule_control::commands::ClapCli;
19
19
use inputmodule_control:: inputmodule:: { serial_commands} ;
20
20
use clap:: { Parser , Subcommand } ;
21
21
22
+ use log:: debug;
23
+
22
24
fn handle_message ( msg : & Message ) {
23
- println ! ( "Got message from DBus: {:?}" , msg) ;
25
+ debug ! ( "Got message from DBus: {:?}" , msg) ;
26
+
24
27
let mut iter = msg. iter_init ( ) ;
25
28
while let Some ( arg) = iter. get_refarg ( ) {
26
- // Extract the inner value as a string and convert it to a String
27
29
if let Some ( string_ref) = arg. as_str ( ) {
28
30
let string_value: String = string_ref. to_string ( ) ;
29
- println ! ( "String value: {}" , string_value) ;
31
+ debug ! ( "String value: {}" , string_value) ;
30
32
31
33
if string_value. contains ( "calendar.google.com" ) {
32
34
run_inputmodule_command ( vec ! [ "led-matrix" , "--pattern" , "all-on" , "--blink-n-times" , "3" ] ) ;
33
35
run_inputmodule_command ( vec ! [ "led-matrix" , "--brightness" , "0" ] ) ;
34
36
}
35
- } else {
36
- println ! ( "Not a string." ) ;
37
37
}
38
38
iter. next ( ) ;
39
39
}
40
40
41
- println ! ( "Message handled" ) ;
41
+ debug ! ( "DBus Message handled" ) ;
42
42
}
43
43
44
44
pub fn run_inputmodule_command ( args : Vec < & str > ) {
@@ -52,7 +52,7 @@ pub fn run_inputmodule_command(args: Vec<&str>){
52
52
pub fn run_dbus_monitor ( ) {
53
53
// First open up a connection to the desired bus.
54
54
let conn = Connection :: new_session ( ) . expect ( "D-Bus connection failed" ) ;
55
- println ! ( "Connection to DBus session monitor opened" ) ;
55
+ debug ! ( "Connection to DBus session monitor opened" ) ;
56
56
57
57
// Second create a rule to match messages we want to receive; in this example we add no
58
58
// further requirements, so all messages will match
@@ -72,23 +72,23 @@ pub fn run_dbus_monitor() {
72
72
"BecomeMonitor" ,
73
73
( vec ! [ rule. match_str( ) ] , 0u32 ) ,
74
74
) ;
75
- println ! ( "Monitoring DBus channel..." ) ;
75
+ debug ! ( "Monitoring DBus channel..." ) ;
76
76
77
77
match result {
78
78
// BecomeMonitor was successful, start listening for messages
79
79
Ok ( _) => {
80
80
conn. start_receive (
81
81
rule,
82
82
Box :: new ( |msg, _| {
83
- println ! ( "Start listening" ) ;
83
+ debug ! ( "Start listening" ) ;
84
84
handle_message ( & msg) ;
85
85
true
86
86
} ) ,
87
87
) ;
88
88
}
89
89
// BecomeMonitor failed, fallback to using the old scheme
90
90
Err ( e) => {
91
- eprintln ! (
91
+ debug ! (
92
92
"Failed to BecomeMonitor: '{}', falling back to eavesdrop" ,
93
93
e
94
94
) ;
@@ -113,7 +113,7 @@ pub fn run_dbus_monitor() {
113
113
// This can sometimes fail, for example when listening to the system bus as a non-root user.
114
114
// So, just like `dbus-monitor`, we attempt to fallback without `eavesdrop=true`:
115
115
Err ( e) => {
116
- eprintln ! ( "Failed to eavesdrop: '{}', trying without it" , e) ;
116
+ debug ! ( "Failed to eavesdrop: '{}', trying without it" , e) ;
117
117
conn. add_match ( rule, |_: ( ) , _, msg| {
118
118
handle_message ( & msg) ;
119
119
true
0 commit comments