use std::time::Duration;
use crate::error::Result;
use crate::event::Event;
use crate::icon::Icon;
use crate::menu::Menu;
use crate::notification::Notification;
#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "macos")]
mod macos;
#[cfg(target_os = "windows")]
mod windows;
#[allow(dead_code)]
pub(crate) struct Init {
pub icon: Icon,
pub tooltip: String,
pub menu: Option<Menu>,
}
pub(crate) trait Backend: Send {
fn set_icon(&mut self, icon: &Icon) -> Result<()>;
fn set_tooltip(&mut self, text: &str) -> Result<()>;
fn set_menu(&mut self, menu: Option<&Menu>) -> Result<()>;
fn notify(&mut self, notification: &Notification) -> Result<()>;
fn pump(&mut self, timeout: Duration, sink: &mut dyn FnMut(Event)) -> Result<()>;
fn can_spawn(&self) -> bool {
true
}
}
pub(crate) fn new_backend(init: Init) -> Result<Box<dyn Backend>> {
#[cfg(target_os = "linux")]
let backend = linux::new(init);
#[cfg(target_os = "windows")]
let backend = windows::new(init);
#[cfg(target_os = "macos")]
let backend = macos::new(init);
#[cfg(not(any(target_os = "linux", target_os = "windows", target_os = "macos")))]
let backend = {
let _ = init;
Err(crate::error::Error::Unsupported)
};
backend
}