Add tray icon

This commit is contained in:
Nicola Spadari
2024-10-08 13:55:56 +02:00
parent 84626cfbbd
commit 85f9de7a0f
4 changed files with 32 additions and 3 deletions

View File

@@ -28,7 +28,7 @@ serde_json = "1"
[dependencies.tauri]
version = "2.0.2"
features = [ ]
features = [ "tray-icon" ]
[dependencies.serde]
version = "1"

View File

@@ -12,6 +12,7 @@
"core:app:default",
"core:resources:default",
"core:menu:default",
"core:tray:default",
"shell:allow-open",
{
"identifier": "shell:allow-execute",

View File

@@ -1 +1 @@
{"main":{"identifier":"main","description":"Capabilities for the main window","local":true,"windows":["main"],"permissions":["core:path:default","core:event:default","core:window:default","core:app:default","core:resources:default","core:menu:default","shell:allow-open",{"identifier":"shell:allow-execute","allow":[{"args":["-c",{"validator":"\\S+"}],"cmd":"sh","name":"exec-sh","sidecar":false}]},"notification:default","os:allow-platform","os:allow-arch","os:allow-family","os:allow-version","os:allow-locale","fs:allow-document-read","fs:allow-document-write"]}}
{"main":{"identifier":"main","description":"Capabilities for the main window","local":true,"windows":["main"],"permissions":["core:path:default","core:event:default","core:window:default","core:app:default","core:resources:default","core:menu:default","core:tray:default","shell:allow-open",{"identifier":"shell:allow-execute","allow":[{"args":["-c",{"validator":"\\S+"}],"cmd":"sh","name":"exec-sh","sidecar":false}]},"notification:default","os:allow-platform","os:allow-arch","os:allow-family","os:allow-version","os:allow-locale","fs:allow-document-read","fs:allow-document-write"]}}

View File

@@ -1,10 +1,38 @@
#[cfg_attr(mobile, tauri::mobile_entry_point)]
#[allow(unused)]
use tauri::{
menu::{Menu, MenuItem},
tray::TrayIconBuilder
};
pub fn run() {
tauri::Builder::default()
.setup(|app| {
let quit_i = MenuItem::with_id(app, "quit", "Quit", true, None::<&str>)?;
let menu = Menu::with_items(app, &[&quit_i])?;
let tray = TrayIconBuilder::new()
.menu(&menu)
.menu_on_left_click(true)
.icon(app.default_window_icon().unwrap().clone())
.on_menu_event(|app, event| match event.id.as_ref() {
"quit" => {
app.exit(0);
}
other => {
println!("menu item {} not handled", other);
}
})
.build(app)?;
Ok(())
})
.plugin(tauri_plugin_shell::init())
.plugin(tauri_plugin_notification::init())
.plugin(tauri_plugin_os::init())
.plugin(tauri_plugin_fs::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
}