unistore-tray 0.1.0

System tray capability for UniStore - cross-platform tray icon, menu, and notifications
Documentation
//! 【平台实现层】- 条件编译选择具体实现
//!
//! 职责:
//! - 根据目标平台选择具体实现
//! - 提供统一的 PlatformTray trait

#[cfg(target_os = "windows")]
mod windows;
#[cfg(target_os = "windows")]
pub use windows::PlatformTray;

#[cfg(target_os = "macos")]
mod macos;
#[cfg(target_os = "macos")]
pub use macos::PlatformTray;

#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "linux")]
pub use linux::PlatformTray;

// 不支持的平台使用 stub 实现
#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
mod stub;
#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
pub use stub::PlatformTray;

use crate::config::TrayConfig;
use crate::error::TrayResult;
use crate::event::TrayEvent;
use crate::icon::TrayIcon;
use crate::menu::Menu;
use tokio::sync::broadcast;

/// 平台托盘实现需要满足的接口
pub trait PlatformTrayOps: Send + Sync {
    /// 创建平台托盘
    fn new(config: &TrayConfig, event_tx: broadcast::Sender<TrayEvent>) -> TrayResult<Self>
    where
        Self: Sized;

    /// 设置图标
    fn set_icon(&self, icon: &TrayIcon) -> TrayResult<()>;

    /// 设置提示文字
    fn set_tooltip(&self, tooltip: &str) -> TrayResult<()>;

    /// 设置菜单
    fn set_menu(&self, menu: &Menu) -> TrayResult<()>;

    /// 销毁托盘
    fn destroy(&self) -> TrayResult<()>;
}