#[cfg(not(windows))]
#[cfg(target_os = "linux")]
extern crate dbus;
#[cfg(not(windows))]
#[cfg(target_os = "linux")]
use dbus::blocking::Connection;
#[cfg(not(windows))]
#[cfg(target_os = "linux")]
use dbus::strings::{BusName, Path, Interface, Member};
#[cfg(not(windows))]
#[cfg(target_os = "linux")]
use dbus::Message;
#[cfg(not(windows))]
#[cfg(target_os = "linux")]
use dbus::blocking::BlockingSender;
#[cfg(not(windows))]
#[cfg(target_os = "linux")]
use dbus::Signature;
#[cfg(not(windows))]
#[cfg(target_os = "linux")]
use dbus::arg::messageitem::MessageItem;
#[cfg(not(windows))]
#[cfg(target_os = "linux")]
use dbus::arg::messageitem::MessageItemArray;
#[cfg(not(windows))]
#[cfg(target_os = "linux")]
struct SendDbus<'a> {
title: & 'a str,
app_name: & 'a str,
body: & 'a str,
icon: & 'a str,
id: & 'a u32,
timeout: & 'a i32,
}
#[cfg(target_os = "linux")]
#[cfg(not(windows))]
impl <'a>SendDbus<'a> {
fn dbus_notify_send(title: & 'a str, app_name: & 'a str, body: & 'a str,
icon: & 'a str, id: & 'a u32,
timeout: & 'a i32) -> SendDbus<'a>
{
let debug_instance = Debug::new();
let connection_result = Connection::new_session();
let connection = Connection::new_session().unwrap();
let mut arg = Vec::new();
arg.push(format!("--title={}", title));
arg.push(format!("--app_name={}", app_name));
arg.push(format!("--body={}", body));
arg.push(format!("--icon={}", icon));
arg.push(format!("--id={}", id));
arg.push(format!("--timeout={}", timeout));
debug_instance.handle_dbus_connection(connection_result);
debug_instance.print_msg_arg(&arg);
let mut message = Message::method_call(
&BusName::new("org.freedesktop.Notifications").unwrap(),
&Path::new("/org/freedesktop/Notifications").unwrap(),
&Interface::new("org.freedesktop.Notifications").unwrap(),
&Member::new("Notify").unwrap(),
);
let array_as = MessageItem::Array(MessageItemArray::new(vec![], Signature::new("as").unwrap()).unwrap());
let array_asv = MessageItem::Array(MessageItemArray::new(vec![], Signature::new("a{sv}").unwrap()).unwrap());
message.append_items(&[
title.into(), (*id).into(), icon.into(), app_name.into(), body.into(), array_as,
array_asv,
(*timeout).into(),]);
match connection.send_with_reply_and_block(message, std::time::Duration::from_secs(2)) {
Ok(_) => {
debug_instance.print("The notification was sent successfully.");
},
Err(err) => {
let error_message = format!("Sending notification: {}", err);
debug_instance.error(&error_message);
}
}
SendDbus { title, app_name, body, icon, id, timeout}
}
}