VTray
VTray is a cross-platform V library to place an icon and menu in the notification area.
Features
- Create a tray
- Custom icon for tray
- Add tooltip.
- Add an on click event listener
- Supported on Windows
- Supported on Linux
- Supported on MacOS
- Menu items can be checked and/or disabled
- Allow menus to have their own icons
Requirements
For Linux you will need the following packages installed:
sudo apt-get install libayatana-appindicator3-dev
sudo apt-get install libgtk-3-dev
sudo apt-get install pkg-config
For MacOS the tray icon size must be 22x22 pixels in order for it to render correctly.
Example
module main
import ouri028.vtray
enum MenuItems {
edit = 1
quit = 2
}
struct App {
pub mut:
tray vtray.VTrayApp
}
fn main() {
mut app := App{
tray: vtray.VTrayApp{
identifier: 'VTray!'
tooltip: 'VTray Demo!'
icon: '${@VMODROOT}/assets/icon.ico'
items: [
&vtray.VTrayMenuItem{
id: int(MenuItems.edit)
text: 'Edit'
},
&vtray.VTrayMenuItem{
id: int(MenuItems.quit)
text: 'Quit'
},
]
}
}
app.tray.on_click = app.on_click
app.tray.vtray_init()
app.tray.run()
app.tray.destroy()
}
fn (app &App) on_click(menu_id int) {
match menu_id {
int(MenuItems.edit) {
println('EDIT!')
}
int(MenuItems.quit) {
app.tray.destroy()
}
else {}
}
}
Edit v.mod
Module {
name: 'myapp'
description: ''
version: '0.0.1'
license: 'MIT'
dependencies: ['ouri028.vtray']
}
Windows 11
Linux
MacOS