use std::os::raw::{c_int, c_longlong};
use libc::wchar_t;
#[repr(C)]
#[derive(Debug)]
#[allow(dead_code)]
enum Results {
Success = 0,
SystemNotSupported = 1,
InitializationFailure = 2,
ToastFailed = 3,
}
extern "C" {
fn show_notification(
actions_acs: *const wchar_t,
appName: *const wchar_t,
appUserModelID: *const wchar_t,
text: *const wchar_t,
imagePath: *const wchar_t,
attribute: *const wchar_t,
expiration: c_longlong,
) -> c_int;
}
pub struct WinSend<'a> {
pub action: & 'a str,
pub app_name: & 'a str,
pub app_user_model_id: & 'a str,
pub text: & 'a str,
pub img: & 'a str,
pub attr: & 'a str,
pub expiration: & 'a i64
}
impl <'a>WinSend<'a> {
pub fn new() -> WinSend <'a> {
WinSend { action: "", app_name: "",
app_user_model_id: "", text: "",
img: "", attr: "", expiration: &0}
}
pub fn win32_send(&self, action: & 'a str, app_name: & 'a str,
app_user_model_id: & 'a str, text: & 'a str,
img: & 'a str, attr: & 'a str, expiration: & 'a i64) -> WinSend <'a>
{
Self::wintoast_send(action, app_name, app_user_model_id, text, img, attr, expiration);
WinSend { action, app_name, app_user_model_id, text, img, attr, expiration}
}
pub fn wintoast_send(action: & 'a str, app_name: & 'a str,
app_user_model_id: & 'a str, text: & 'a str,
img: & 'a str, attr: & 'a str, expiration: & 'a i64) -> WinSend <'a>
{
let debug = Debug::new();
let actions = widestring::WideCString::from_str(action).unwrap();
let app_name_ = widestring::WideCString::from_str(app_name).unwrap();
let app_user_model_id_ = widestring::WideCString::from_str(app_user_model_id).unwrap();
let text_ = widestring::WideCString::from_str(text).unwrap();
let image_path_ = widestring::WideCString::from_str(img).unwrap();
let attribute_ = widestring::WideCString::from_str(attr).unwrap();
let exp: i64 = *expiration;
let mut arg = Vec::new();
if !action.is_empty() {
arg.push(format!("Action: {}", action));
}
arg.push(format!("AppName: {}", app_name));
arg.push(format!("AppID: {}", app_user_model_id));
arg.push(format!("Body: {}", text));
arg.push(format!("ImagePath: {}", img));
arg.push(format!("Urgency Mode: {}", attr));
arg.push(format!("Timeout: {}", expiration));
debug.print_msg_arg(&arg);
unsafe {
let result = show_notification(
actions.as_ptr(),
app_name_.as_ptr(),
app_user_model_id_.as_ptr(),
text_.as_ptr(),
image_path_.as_ptr(),
attribute_.as_ptr(),
exp,
);
match result {
0 => {debug.print("Notification displayed successfully");},
1 => {debug.error("System not supported!");},
2 => {debug.error("Initialization failed!");},
3 => {debug.error("Toast failed to display!");},
_ => {debug.error("Unknown error occurred!");},
}
}
WinSend { action, app_name, app_user_model_id, text, img, attr, expiration}
}
}