1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Systray Lib

#[macro_use]
extern crate log;
#[cfg(target_os = "windows")]
extern crate winapi;
#[cfg(target_os = "windows")]
extern crate kernel32;
#[cfg(target_os = "windows")]
extern crate user32;
#[cfg(target_os = "windows")]
extern crate libc;

pub mod api;

#[derive(Clone)]
pub enum SystrayError {
    OsError(String),
    NotImplementedError,
    UnknownError,
}

pub struct SystrayEvent {
    menu_index: u32,
    menu_checked: bool
}

pub struct Application {
    pub window: api::api::Window
}

impl Application {
    pub fn new() -> Result<Application, SystrayError> {
        match api::api::Window::new() {
            Ok(w) => Ok(Application {
                window: w
            }),
            Err(e) => Err(e)
        }
    }
}

type Callback = Box<(Fn(&api::api::Window) -> () + 'static)>;

fn make_callback<F>(f: F) -> Callback
    where F: std::ops::Fn(&api::api::Window) -> () + 'static {
    Box::new(f) as Callback
}