xbp 10.43.0

XBP is a zero-config build pack that can also interact with proxies, kafka, sockets, synthetic monitors.
Documentation
//! Platform event pumping and tray icon loading for native system tray UIs.

use tray_icon::Icon;

const TRAY_ICON_SIZE: u32 = 32;

/// Decode embedded PNG bytes and resize to a tray-friendly dimension.
pub fn load_tray_icon_from_png(bytes: &[u8]) -> Result<Icon, String> {
    let image = image::load_from_memory(bytes)
        .map_err(|error| format!("Failed to decode tray icon: {error}"))?
        .into_rgba8();

    let image = if image.width() > TRAY_ICON_SIZE || image.height() > TRAY_ICON_SIZE {
        image::imageops::resize(
            &image,
            TRAY_ICON_SIZE,
            TRAY_ICON_SIZE,
            image::imageops::FilterType::Lanczos3,
        )
    } else {
        image
    };

    let (width, height) = (image.width(), image.height());
    Icon::from_rgba(image.into_raw(), width, height)
        .map_err(|error| format!("Failed to create tray icon: {error}"))
}

/// Pump native UI events so tray icons and context menus stay responsive.
pub fn pump_tray_events() {
    #[cfg(windows)]
    pump_windows_events();

    #[cfg(target_os = "linux")]
    pump_gtk_events();
}

#[cfg(windows)]
fn pump_windows_events() {
    use std::mem::zeroed;
    use windows_sys::Win32::UI::WindowsAndMessaging::{
        DispatchMessageW, PeekMessageW, TranslateMessage, MSG, PM_REMOVE,
    };

    unsafe {
        let mut msg: MSG = zeroed();
        while PeekMessageW(&mut msg, std::ptr::null_mut(), 0, 0, PM_REMOVE) != 0 {
            TranslateMessage(&msg);
            DispatchMessageW(&msg);
        }
    }
}

#[cfg(target_os = "linux")]
fn pump_gtk_events() {
    while gtk::events_pending() {
        gtk::main_iteration();
    }
}