iovxw / ksni

A Rust implementation of the KDE/freedesktop StatusNotifierItem specification
The Unlicense
72 stars 11 forks source link

Handle::update: Return the return value of the callback #13

Closed crumblingstatue closed 2 years ago

crumblingstatue commented 2 years ago

This allows callers of update to initialize variables computed in the closure.

An example use case is the following pattern:

let event_flags = app.tray_handle.update(|tray: &mut AppTray| {
    app.write_tray_info(&mut tray.app_state.tray_info);
    tray.app_state.paused = app.paused_or_stopped();
    tray.event_flags.take()
});
if event_flags.quit_clicked {
    break;
}
if event_flags.activated {
    win_visible ^= true;
    rw.set_visible(win_visible);
}
...
iovxw commented 2 years ago

:+1: