ksni

A Rust implementation of the KDE/freedesktop StatusNotifierItem specification
Example
```rust
use ksni;
[derive(Debug)]
struct MyTray {
selected_option: usize,
checked: bool,
}
impl ksni::Tray for MyTray {
fn iconname(&self) -> String {
"help-about".into()
}
fn title(&self) -> String {
if self.checked { "CHECKED!" } else { "MyTray" }.into()
}
fn menu(&self) -> Vec> {
use ksni::menu::*;
vec![
SubMenu {
label: "a".into(),
submenu: vec![
SubMenu {
label: "a1".into(),
submenu: vec![
StandardItem {
label: "a1.1".into(),
..Default::default()
}
.into(),
StandardItem {
label: "a1.2".into(),
..Default::default()
}
.into(),
],
..Default::default()
}
.into(),
StandardItem {
label: "a2".into(),
..Default::default()
}
.into(),
],
..Default::default()
}
.into(),
MenuItem::Sepatator,
RadioGroup {
selected: self.selectedoption,
select: Box::new(|this: &mut Self, current| {
this.selectedoption = current;
}),
options: vec![
RadioItem {
label: "Option 0".into(),
..Default::default()
},
RadioItem {
label: "Option 1".into(),
..Default::default()
},
RadioItem {
label: "Option 2".into(),
..Default::default()
},
],
..Default::default()
}
.into(),
CheckmarkItem {
label: "Checkable".into(),
checked: self.checked,
activate: Box::new(|this: &mut Self| this.checked = !this.checked),
..Default::default()
}
.into(),
StandardItem {
label: "Exit".into(),
iconname: "application-exit".into(),
activate: Box::new(|_| std::process::exit(0)),
..Default::default()
}
.into(),
]
}
}
fn main() {
let service = ksni::TrayService::new(MyTray {
selected_option: 0,
checked: false,
});
let state = service.state();
service.spawn();
std::thread::sleep(std::time::Duration::from_secs(5));
// We can modify the state
state.update(|state: &mut MyTray| {
state.checked = true;
});
// Run forever
loop {
std::thread::park();
}
}
```
Will create a system tray like this:

(In GNOME with AppIndicator extension)
Todo
- [X] org.kde.StatusNotifierItem
- [X] com.canonical.dbusmenu
- [X] org.freedesktop.DBus.Introspectable
- [X] org.freedesktop.DBus.Properties
- [X] radio item
- [ ] documents
- [ ] async diwic/dbus-rs#166
- [X] mutable menu items
License
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.