Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add system tray icon macos #126

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions examples/apps/screenpipe-app-tauri/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ use tauri_plugin_autostart::MacosLauncher;
use tauri_plugin_autostart::ManagerExt;
use tauri_plugin_shell::process::CommandChild;


use tauri::{
menu::{MenuBuilder, MenuItemBuilder},
tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent},
utils::assets::EmbeddedAssets
};
use tauri::image::Image;

mod analytics;

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

// Add System Tray
let toggle = MenuItemBuilder::with_id("toggle", "Screenpipe").build(app)?;
let menu = MenuBuilder::new(app).items(&[&toggle]).build()?;

let icon_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("icons")
.join("32x32.png");

let icon = Image::from_path(icon_path).expect("Failed to load icon");

let _tray = TrayIconBuilder::new()
.menu(&menu)
.icon(icon)
.on_menu_event(move |_app, event| match event.id().as_ref() {
"toggle" => {
println!("toggle clicked");
}
_ => (),
})
.on_tray_icon_event(|_tray, event| {
if let TrayIconEvent::Click {
button: MouseButton::Left,
button_state: MouseButtonState::Up,
..
} = event
{
println!("tray closed");
}
})
.build(app)?;

let stores = app.app_handle().state::<StoreCollection<Wry>>();

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