Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

release-app add pipe in tray menu

Louis Beaumont8861bc905db9
diff --git a/Cargo.toml b/Cargo.toml
index 8a153477c..2093fb812 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,7 +7,9 @@ members = [
"screenpipe-integrations",
"screenpipe-actions",
]
-exclude = ["screenpipe-app-tauri/src-tauri"]
+exclude = [
+ "screenpipe-app-tauri/src-tauri"
+]
resolver = "2"
diff --git a/screenpipe-app-tauri/src-tauri/Cargo.lock b/screenpipe-app-tauri/src-tauri/Cargo.lock
index 2f32b1aee..43a48fe91 100755
--- a/screenpipe-app-tauri/src-tauri/Cargo.lock
+++ b/screenpipe-app-tauri/src-tauri/Cargo.lock
@@ -4966,7 +4966,7 @@ dependencies = [
[[package]]
name = "screenpipe-app"
-version = "0.17.9"
+version = "0.18.2"
dependencies = [
"anyhow",
"axum",
diff --git a/screenpipe-app-tauri/src-tauri/Cargo.toml b/screenpipe-app-tauri/src-tauri/Cargo.toml
index 603993b73..6050d12bf 100644
--- a/screenpipe-app-tauri/src-tauri/Cargo.toml
+++ b/screenpipe-app-tauri/src-tauri/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "screenpipe-app"
-version = "0.18.2"
+version = "0.18.3"
description = ""
authors = ["you"]
license = ""
diff --git a/screenpipe-app-tauri/src-tauri/src/main.rs b/screenpipe-app-tauri/src-tauri/src/main.rs
index 245c6cdc0..c4b11178d 100755
--- a/screenpipe-app-tauri/src-tauri/src/main.rs
+++ b/screenpipe-app-tauri/src-tauri/src/main.rs
@@ -36,12 +36,14 @@ mod analytics;
mod icons;
use crate::analytics::start_analytics;
use crate::llm_sidecar::LLMSidecar;
+use tauri::Emitter;
mod commands;
mod llm_sidecar;
mod permissions;
mod server;
mod sidecar;
+mod tray;
mod updates;
pub use commands::reset_all_pipes;
pub use commands::set_tray_health_icon;
@@ -56,6 +58,23 @@ pub use permissions::request_permission;
pub struct SidecarState(Arc<tokio::sync::Mutex<Option<SidecarManager>>>);
+async fn get_pipe_port(pipe_id: &str) -> anyhow::Result<u16> {
+ // Fetch pipe config from API
+ let client = reqwest::Client::new();
+ let response = client
+ .get(format!("http://localhost:3030/pipes/info/{}", pipe_id))
+ .send()
+ .await?
+ .json::<Value>()
+ .await?;
+
+ // Extract port from response
+ response["data"]["config"]["port"]
+ .as_u64()
+ .map(|p| p as u16)
+ .ok_or_else(|| anyhow::anyhow!("no port found for pipe {}", pipe_id))
+}
+
fn get_base_dir(app: &tauri::AppHandle, custom_path: Option<String>) -> anyhow::Result<PathBuf> {
let default_path = app.path().local_data_dir().unwrap().join("screenpipe");
@@ -255,6 +274,9 @@ async fn main() {
.build()?;
let _ = main_tray.set_menu(Some(menu));
+ let update_item = update_manager.update_now_menu_item_ref().clone();
+ tray::setup_tray_menu_updater(app.handle().clone(), &update_item);
+
main_tray.on_menu_event(move |app_handle, event| match event.id().as_ref() {
"show" => {
show_main_window(app_handle, false);
@@ -275,8 +297,6 @@ async fn main() {
tokio::task::block_in_place(move || {
Handle::current().block_on(async move {
- // i think it shouldn't kill if we're in dev mode (on macos, windows need to kill)
- // bad UX: i use CLI and it kills my CLI because i updated app
if let Err(err) = sidecar::kill_all_sreenpipes(
app_handle.state::<SidecarState>(),
app_handle.clone(),
@@ -289,6 +309,22 @@ async fn main() {
});
update_manager.update_screenpipe();
}
+ id if id.starts_with("pipe_") => {
+ let pipe_id = id.replace("pipe_", "");
+ let app_handle = app_handle.clone();
+ tauri::async_runtime::spawn(async move {
+ match get_pipe_port(&pipe_id).await {
+ Ok(port) => {
+ if let Err(e) =
+ commands::open_pipe_window(app_handle, port, pipe_id).await
+ {
+ error!("Failed to open pipe window: {}", e);
+ }
+ }
+ Err(e) => error!("Failed to get pipe port: {}", e),
+ }
+ });
+ }
_ => (),
});
main_tray.on_tray_icon_event(move |tray, event| match event {
diff --git a/screenpipe-app-tauri/src-tauri/src/tray.rs b/screenpipe-app-tauri/src-tauri/src/tray.rs
new file mode 100644
index 000000000..8e1d2d3cd
--- /dev/null
+++ b/screenpipe-app-tauri/src-tauri/src/tray.rs
@@ -0,0 +1,89 @@
+use anyhow::Result;
+use serde_json::Value;
+use tauri::{
+ menu::{IsMenuItem, MenuBuilder, MenuItemBuilder, PredefinedMenuItem},
+ AppHandle, Wry,
+};
+use tracing::info;
+
+pub async fn update_tray_menu(
+ app: &AppHandle,
+ update_item: &tauri::menu::MenuItem<Wry>,
+) -> Result<()> {
+ // Fetch enabled pipes from API
+ let client = reqwest::Client::new();
+ let response = client
+ .get("http://localhost:3030/pipes/list")
+ .send()
+ .await?
+ .json::<Value>()
+ .await?;
+
+ // Create all owned menu items first
+ let mut menu_pipes = Vec::new();
+
+ // Add version and show items (these are already references)
+ let show = MenuItemBuilder::with_id("show", "show screenpipe").build(app)?;
+ let version =
+ MenuItemBuilder::with_id("version", format!("version {}", app.package_info().version))
+ .enabled(false)
+ .build(app)?;
+
+ // Add pipe items to owned collection
+ if let Some(pipes) = response["data"].as_array() {
+ for pipe in pipes {
+ if pipe["enabled"].as_bool().unwrap_or(false) {
+ let id = pipe["id"].as_str().unwrap_or_default();
+ if let Some(_port) = pipe["config"]["port"].as_u64() {
+ let pipe_item =
+ MenuItemBuilder::with_id(format!("pipe_{}", id), format!("open {}", id))
+ .build(app)?;
+ menu_pipes.push(pipe_item);
+ }
+ }
+ }
+ }
+
+ // Add quit item to owned collection
+ let quit_item = MenuItemBuilder::with_id("quit", "quit screenpipe").build(app)?;
+
+ // Now create the final menu_items vector with references
+ let menu_divider = PredefinedMenuItem::separator(app)?;
+
+ // Build menu
+ let mut menu_items: Vec<&dyn IsMenuItem<Wry>> =
+ vec![&version, &show, update_item, &menu_divider];
+ // Add pipe items
+ menu_items.extend(menu_pipes.iter().map(|item| item as &dyn IsMenuItem<Wry>));
+ // Add final items
+ menu_items.extend([&menu_divider as &dyn IsMenuItem<Wry>, &quit_item]);
+
+ let menu = MenuBuilder::new(app).items(&menu_items).build()?;
+
+ // Update tray
+ if let Some(tray) = app.tray_by_id("screenpipe_main") {
+ tray.set_menu(Some(menu))?;
+ info!(
+ "updated tray menu with {} enabled pipes",
+ response["data"]
+ .as_array()
+ .map(|arr| arr.len())
+ .unwrap_or(0)
+ );
+ }
+
+ Ok(())
+}
+
+pub fn setup_tray_menu_updater(app: AppHandle, update_item: &tauri::menu::MenuItem<Wry>) {
+ let update_item = update_item.clone();
+ tauri::async_runtime::spawn(async move {
+ let mut interval = tokio::time::interval(std::time::Duration::from_secs(5));
+ loop {
+ interval.tick().await;
+ if let Err(e) = update_tray_menu(&app, &update_item).await {
+ println!("failed to update tray menu: {:#}", e);
+ }
+ }
+ });
+}