Skip to content

Commit 2b3f55d

Browse files
authored
Merge pull request #126 from DmacMcgreg/feature/tray-icon-2024-08-08
Add system tray icon macos
2 parents 119634b + eb9d511 commit 2b3f55d

File tree

1 file changed

+39
-0
lines changed
  • examples/apps/screenpipe-app-tauri/src-tauri/src

1 file changed

+39
-0
lines changed

examples/apps/screenpipe-app-tauri/src-tauri/src/main.rs

+39
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ use tauri_plugin_autostart::MacosLauncher;
2323
use tauri_plugin_autostart::ManagerExt;
2424
use tauri_plugin_shell::process::CommandChild;
2525

26+
27+
use tauri::{
28+
menu::{MenuBuilder, MenuItemBuilder},
29+
tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent},
30+
utils::assets::EmbeddedAssets
31+
};
32+
use tauri::image::Image;
33+
2634
mod analytics;
2735

2836
use crate::analytics::start_analytics;
@@ -135,6 +143,37 @@ async fn main() {
135143
let _ = File::create(path.clone()).unwrap();
136144
}
137145

146+
// Add System Tray
147+
let toggle = MenuItemBuilder::with_id("toggle", "Screenpipe").build(app)?;
148+
let menu = MenuBuilder::new(app).items(&[&toggle]).build()?;
149+
150+
let icon_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
151+
.join("icons")
152+
.join("32x32.png");
153+
154+
let icon = Image::from_path(icon_path).expect("Failed to load icon");
155+
156+
let _tray = TrayIconBuilder::new()
157+
.menu(&menu)
158+
.icon(icon)
159+
.on_menu_event(move |_app, event| match event.id().as_ref() {
160+
"toggle" => {
161+
println!("toggle clicked");
162+
}
163+
_ => (),
164+
})
165+
.on_tray_icon_event(|_tray, event| {
166+
if let TrayIconEvent::Click {
167+
button: MouseButton::Left,
168+
button_state: MouseButtonState::Up,
169+
..
170+
} = event
171+
{
172+
println!("tray closed");
173+
}
174+
})
175+
.build(app)?;
176+
138177
let stores = app.app_handle().state::<StoreCollection<Wry>>();
139178

140179
// Initialize the store with default values if it doesn't exist

0 commit comments

Comments
 (0)