|
14 | 14 | mod cmd;
|
15 | 15 | mod menu;
|
16 | 16 |
|
| 17 | +#[cfg(target_os = "linux")] |
| 18 | +use std::path::PathBuf; |
| 19 | + |
17 | 20 | use serde::Serialize;
|
18 | 21 | use tauri::{
|
19 | 22 | CustomMenuItem, Event, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu, WindowBuilder,
|
@@ -53,7 +56,9 @@ fn main() {
|
53 | 56 | SystemTray::new().with_menu(
|
54 | 57 | SystemTrayMenu::new()
|
55 | 58 | .add_item(CustomMenuItem::new("toggle", "Toggle"))
|
56 |
| - .add_item(CustomMenuItem::new("new", "New window")), |
| 59 | + .add_item(CustomMenuItem::new("new", "New window")) |
| 60 | + .add_item(CustomMenuItem::new("icon_1", "Tray Icon 1")) |
| 61 | + .add_item(CustomMenuItem::new("icon_2", "Tray Icon 2")), |
57 | 62 | ),
|
58 | 63 | )
|
59 | 64 | .on_system_tray_event(|app, event| match event {
|
@@ -89,6 +94,56 @@ fn main() {
|
89 | 94 | },
|
90 | 95 | )
|
91 | 96 | .unwrap(),
|
| 97 | + #[cfg(target_os = "macos")] |
| 98 | + "icon_1" => { |
| 99 | + app.tray_handle().set_icon_as_template(true).unwrap(); |
| 100 | + |
| 101 | + app |
| 102 | + .tray_handle() |
| 103 | + .set_icon(tauri::Icon::Raw( |
| 104 | + include_bytes!("../../../.icons/tray_icon_with_transparency.png").to_vec(), |
| 105 | + )) |
| 106 | + .unwrap(); |
| 107 | + } |
| 108 | + #[cfg(target_os = "macos")] |
| 109 | + "icon_2" => { |
| 110 | + app.tray_handle().set_icon_as_template(true).unwrap(); |
| 111 | + |
| 112 | + app |
| 113 | + .tray_handle() |
| 114 | + .set_icon(tauri::Icon::Raw( |
| 115 | + include_bytes!("../../../.icons/tray_icon.png").to_vec(), |
| 116 | + )) |
| 117 | + .unwrap(); |
| 118 | + } |
| 119 | + #[cfg(target_os = "linux")] |
| 120 | + "icon_1" => app |
| 121 | + .tray_handle() |
| 122 | + .set_icon(tauri::Icon::File(PathBuf::from( |
| 123 | + "../../../.icons/tray_icon_with_transparency.png", |
| 124 | + ))) |
| 125 | + .unwrap(), |
| 126 | + #[cfg(target_os = "linux")] |
| 127 | + "icon_2" => app |
| 128 | + .tray_handle() |
| 129 | + .set_icon(tauri::Icon::File(PathBuf::from( |
| 130 | + "../../../.icons/tray_icon.png", |
| 131 | + ))) |
| 132 | + .unwrap(), |
| 133 | + #[cfg(target_os = "windows")] |
| 134 | + "icon_1" => app |
| 135 | + .tray_handle() |
| 136 | + .set_icon(tauri::Icon::Raw( |
| 137 | + include_bytes!("../../../.icons/tray_icon_with_transparency.ico").to_vec(), |
| 138 | + )) |
| 139 | + .unwrap(), |
| 140 | + #[cfg(target_os = "windows")] |
| 141 | + "icon_2" => app |
| 142 | + .tray_handle() |
| 143 | + .set_icon(tauri::Icon::Raw( |
| 144 | + include_bytes!("../../../.icons/icon.ico").to_vec(), |
| 145 | + )) |
| 146 | + .unwrap(), |
92 | 147 | _ => {}
|
93 | 148 | }
|
94 | 149 | }
|
|
0 commit comments