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

fix: tray icon crash (main thread safety) + search navigation fixes

Louis Beaumontac46aa43712f
diff --git a/apps/screenpipe-app-tauri/app/search/page.tsx b/apps/screenpipe-app-tauri/app/search/page.tsx
index 95c880da1..9d91da965 100644
--- a/apps/screenpipe-app-tauri/app/search/page.tsx
+++ b/apps/screenpipe-app-tauri/app/search/page.tsx
@@ -6,16 +6,13 @@
import { useCallback, useEffect } from "react";
import { SearchModal } from "@/components/rewind/search-modal";
-import { emit } from "@tauri-apps/api/event";
+import { invoke } from "@tauri-apps/api/core";
import { commands } from "@/lib/utils/tauri";
export default function SearchPage() {
const handleNavigate = useCallback(async (timestamp: string) => {
- await commands.showWindow("Main");
- setTimeout(() => {
- emit("search-navigate-to-timestamp", { timestamp });
- commands.closeWindow({ Search: { query: null } });
- }, 200);
+ // Rust command: shows Main, emits navigation event from app handle, closes Search
+ invoke("search_navigate_to_timeline", { timestamp }).catch(console.error);
}, []);
const handleClose = useCallback(async () => {
diff --git a/apps/screenpipe-app-tauri/components/rewind/timeline.tsx b/apps/screenpipe-app-tauri/components/rewind/timeline.tsx
index e0d749947..d453ddab7 100644
--- a/apps/screenpipe-app-tauri/components/rewind/timeline.tsx
+++ b/apps/screenpipe-app-tauri/components/rewind/timeline.tsx
@@ -894,28 +894,19 @@ export default function Timeline({ embedded = false }: { embedded?: boolean }) {
};
// Listen for cross-window search navigation (from separate Search window)
+ // Always use navigateDirectToDate — the Main panel may have been hidden
+ // (order_out) so frames could be stale/empty. navigateDirectToDate does
+ // a fresh fetch and uses pendingNavigationRef to jump once frames arrive.
useEffect(() => {
const unlisten = listen<{ timestamp: string }>("search-navigate-to-timestamp", (event) => {
const timestamp = event.payload.timestamp;
const targetDate = new Date(timestamp);
setSeekingTimestamp(timestamp);
- if (!isSameDay(targetDate, currentDate)) {
- navigateDirectToDate(targetDate);
- } else {
- pendingNavigationRef.current = targetDate;
- const hasTargetDayFrames = frames.some(f =>
- isSameDay(new Date(f.timestamp), targetDate)
- );
- if (hasTargetDayFrames) {
- setSearchNavFrame(true);
- jumpToTime(targetDate);
- pendingNavigationRef.current = null;
- setSeekingTimestamp(null);
- }
- }
+ setSearchNavFrame(true);
+ navigateDirectToDate(targetDate);
});
return () => { unlisten.then(fn => fn()); };
- }, [currentDate, frames, navigateDirectToDate, jumpToTime]);
+ }, [navigateDirectToDate]);
// The same Timeline component is used in both overlay and window mode.
// The window sizing/decoration is handled by Rust (window_api.rs).
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
index 5e2a74286..1bf89936e 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
@@ -45,35 +45,41 @@ pub fn write_browser_logs(entries: Vec<BrowserLogEntry>) {
#[tauri::command]
#[specta::specta]
pub fn set_tray_unhealth_icon(app_handle: tauri::AppHandle) {
- if let Some(main_tray) = app_handle.tray_by_id("screenpipe_main") {
- match tauri::image::Image::from_path("icons/screenpipe-logo-tray-failed.png") {
- Ok(icon) => {
- if let Err(e) = crate::safe_icon::safe_set_icon(&main_tray, icon) {
- error!("failed to set tray unhealthy icon: {}", e);
+ let app = app_handle.clone();
+ let _ = app_handle.run_on_main_thread(move || {
+ if let Some(main_tray) = app.tray_by_id("screenpipe_main") {
+ match tauri::image::Image::from_path("icons/screenpipe-logo-tray-failed.png") {
+ Ok(icon) => {
+ if let Err(e) = crate::safe_icon::safe_set_icon(&main_tray, icon) {
+ error!("failed to set tray unhealthy icon: {}", e);
+ }
+ }
+ Err(e) => {
+ error!("failed to load tray unhealthy icon: {}", e);
}
- }
- Err(e) => {
- error!("failed to load tray unhealthy icon: {}", e);
}
}
- }
+ });
}
#[tauri::command]
#[specta::specta]
pub fn set_tray_health_icon(app_handle: tauri::AppHandle) {
- if let Some(main_tray) = app_handle.tray_by_id("screenpipe_main") {
- match tauri::image::Image::from_path("icons/screenpipe-logo-tray-black.png") {
- Ok(icon) => {
- if let Err(e) = crate::safe_icon::safe_set_icon(&main_tray, icon) {
- error!("failed to set tray healthy icon: {}", e);
+ let app = app_handle.clone();
+ let _ = app_handle.run_on_main_thread(move || {
+ if let Some(main_tray) = app.tray_by_id("screenpipe_main") {
+ match tauri::image::Image::from_path("icons/screenpipe-logo-tray-black.png") {
+ Ok(icon) => {
+ if let Err(e) = crate::safe_icon::safe_set_icon(&main_tray, icon) {
+ error!("failed to set tray healthy icon: {}", e);
+ }
+ }
+ Err(e) => {
+ error!("failed to load tray healthy icon: {}", e);
}
- }
- Err(e) => {
- error!("failed to load tray healthy icon: {}", e);
}
}
- }
+ });
}
#[tauri::command]
@@ -528,6 +534,30 @@ pub async fn ensure_webview_focus(app_handle: tauri::AppHandle) -> Result<(), St
Ok(())
}
+/// Navigate from Search to a timestamp on the Main timeline.
+/// Shows Main, emits the navigation event from the app handle (not a webview),
+/// then closes the Search window.
+#[tauri::command]
+#[specta::specta]
+pub async fn search_navigate_to_timeline(
+ app_handle: tauri::AppHandle,
+ timestamp: String,
+) -> Result<(), String> {
+ // Show the Main timeline
+ ShowRewindWindow::Main.show(&app_handle).map_err(|e| e.to_string())?;
+
+ // Small delay for the Main webview to restore focus and process events
+ let app = app_handle.clone();
+ tokio::spawn(async move {
+ tokio::time::sleep(tokio::time::Duration::from_millis(300)).await;
+ let _ = app.emit("search-navigate-to-timestamp", serde_json::json!({ "timestamp": timestamp }));
+ tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
+ let _ = ShowRewindWindow::Search { query: None }.close(&app);
+ });
+
+ Ok(())
+}
+
/// Resize the Search NSPanel. Regular Tauri setSize doesn't work on NSPanels.
#[tauri::command]
#[specta::specta]
@@ -544,6 +574,10 @@ pub async fn resize_search_window(
let app = app_handle.clone();
run_on_main_thread_safe(&app_handle, move || {
let label = RewindWindowId::Search.label();
+ // Check window still exists before touching the panel
+ if app.get_webview_window(&label).is_none() {
+ return;
+ }
if let Ok(panel) = app.get_webview_panel(&label) {
unsafe {
use objc::{msg_send, sel, sel_impl};
@@ -558,7 +592,8 @@ pub async fn resize_search_window(
NSPoint::new(frame.origin.x, new_y),
NSSize::new(width, new_h),
);
- let _: () = msg_send![&*panel, setFrame: new_frame display: true animate: true];
+ // animate: false (NO) to avoid use-after-free if panel closes mid-animation
+ let _: () = msg_send![&*panel, setFrame: new_frame display: true animate: false];
}
} else {
// Fallback: try as regular window
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/health.rs b/apps/screenpipe-app-tauri/src-tauri/src/health.rs
index fb3942d1a..1de8fd858 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/health.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/health.rs
@@ -287,42 +287,49 @@ pub async fn start_health_check(app: tauri::AppHandle) -> Result<()> {
last_status = current_status.to_string();
last_theme = theme;
- if let Some(main_tray) = app.tray_by_id("screenpipe_main") {
- let icon_path = if is_unhealthy_icon(current_status) {
- if theme == Mode::Light {
- "assets/screenpipe-logo-tray-black-failed.png"
- } else {
- "assets/screenpipe-logo-tray-white-failed.png"
- }
+ // Resolve icon path on this thread (no AppKit calls)
+ let icon_path = if is_unhealthy_icon(current_status) {
+ if theme == Mode::Light {
+ "assets/screenpipe-logo-tray-black-failed.png"
} else {
- if theme == Mode::Light {
- "assets/screenpipe-logo-tray-black.png"
- } else {
- "assets/screenpipe-logo-tray-white.png"
- }
- };
+ "assets/screenpipe-logo-tray-white-failed.png"
+ }
+ } else {
+ if theme == Mode::Light {
+ "assets/screenpipe-logo-tray-black.png"
+ } else {
+ "assets/screenpipe-logo-tray-white.png"
+ }
+ };
- let icon_path = match app.path().resolve(icon_path, BaseDirectory::Resource) {
- Ok(p) => p,
- Err(e) => {
- error!("failed to resolve icon path: {}", e);
- continue;
- }
- };
-
- match tauri::image::Image::from_path(&icon_path) {
- Ok(image) => {
- if let Err(e) =
- crate::safe_icon::safe_set_icon_as_template(&main_tray, image)
- {
- error!("failed to set tray icon: {}", e);
- }
- }
- Err(e) => {
- error!("failed to load tray icon from {:?}: {}", icon_path, e);
+ let icon_path = match app.path().resolve(icon_path, BaseDirectory::Resource) {
+ Ok(p) => p,
+ Err(e) => {
+ error!("failed to resolve icon path: {}", e);
+ continue;
+ }
+ };
+
+ let image = match tauri::image::Image::from_path(&icon_path) {
+ Ok(img) => img,
+ Err(e) => {
+ error!("failed to load tray icon from {:?}: {}", icon_path, e);
+ continue;
+ }
+ };
+
+ // TrayIcon must be accessed and dropped on the main thread
+ // (NSStatusBar operations crash if called from a tokio thread)
+ let app_clone = app.clone();
+ let _ = app.run_on_main_thread(move || {
+ if let Some(main_tray) = app_clone.tray_by_id("screenpipe_main") {
+ if let Err(e) =
+ crate::safe_icon::safe_set_icon_as_template(&main_tray, image)
+ {
+ error!("failed to set tray icon: {}", e);
}
}
- }
+ });
}
}
});
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
index 026abfb94..a6bb2a8e5 100755
--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
@@ -55,6 +55,7 @@ mod livetext;
mod livetext_ffi;
mod permissions;
mod pi;
+mod pipe_suggestions_scheduler;
mod recording;
mod reminders;
mod remote_sync_commands;
@@ -1317,6 +1318,7 @@ async fn main() {
commands::ensure_webview_focus,
commands::close_window,
commands::resize_search_window,
+ commands::search_navigate_to_timeline,
commands::reset_main_window,
commands::set_window_size,
// Onboarding commands
@@ -1386,6 +1388,9 @@ async fn main() {
reminders::reminders_set_custom_prompt,
reminders::reminders_get_audio_only,
reminders::reminders_set_audio_only,
+ // Pipe suggestions scheduler commands
+ pipe_suggestions_scheduler::pipe_suggestions_get_settings,
+ pipe_suggestions_scheduler::pipe_suggestions_update_settings,
// Calendar commands
calendar::calendar_status,
calendar::calendar_authorize,
@@ -1437,6 +1442,7 @@ async fn main() {
let pi_state = pi::PiState(Arc::new(tokio::sync::Mutex::new(pi::PiPool::new())));
let reminders_state = reminders::RemindersState::new();
let suggestions_state = suggestions::SuggestionsState::new();
+ let pipe_suggestions_state = pipe_suggestions_scheduler::PipeSuggestionsState::new();
#[allow(clippy::single_match)]
let app = tauri::Builder::default()
.plugin(tauri_plugin_opener::init())
@@ -1522,6 +1528,7 @@ async fn main() {
.manage(pi_state)
.manage(reminders_state)
.manage(suggestions_state)
+ .manage(pipe_suggestions_state)
.invoke_handler(tauri::generate_handler![
commands::is_enterprise_build_cmd,
spawn_screenpipe,
@@ -1551,6 +1558,7 @@ async fn main() {
commands::ensure_webview_focus,
commands::close_window,
commands::resize_search_window,
+ commands::search_navigate_to_timeline,
commands::reset_main_window,
commands::set_window_size,
// Permission recovery commands
@@ -1627,6 +1635,9 @@ async fn main() {
reminders::reminders_set_custom_prompt,
reminders::reminders_get_audio_only,
reminders::reminders_set_audio_only,
+ // Pipe suggestions scheduler commands
+ pipe_suggestions_scheduler::pipe_suggestions_get_settings,
+ pipe_suggestions_scheduler::pipe_suggestions_update_settings,
// Calendar commands
calendar::calendar_status,
calendar::calendar_authorize,
@@ -2295,6 +2306,17 @@ async fn main() {
reminders::auto_start_scheduler(app_handle_clone, &reminders_state_clone).await;
});
+ // Auto-start pipe suggestions scheduler if enabled
+ let app_handle_clone = app_handle.clone();
+ let pipe_suggestions_state = app_handle.state::<pipe_suggestions_scheduler::PipeSuggestionsState>();
+ let pipe_suggestions_state_clone = pipe_suggestions_scheduler::PipeSuggestionsState {
+ scheduler_handle: pipe_suggestions_state.scheduler_handle.clone(),
+ };
+ tauri::async_runtime::spawn(async move {
+ tokio::time::sleep(tokio::time::Duration::from_secs(10)).await;
+ pipe_suggestions_scheduler::auto_start_scheduler(app_handle_clone, &pipe_suggestions_state_clone).await;
+ });
+
// Start calendar events publisher (publishes to event bus for meeting detection)
tauri::async_runtime::spawn(async move {
tokio::time::sleep(tokio::time::Duration::from_secs(10)).await;
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/updates.rs b/apps/screenpipe-app-tauri/src-tauri/src/updates.rs
index 257f81688..65bc5a067 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/updates.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/updates.rs
@@ -261,7 +261,7 @@ impl UpdatesManager {
item.set_text("Downloading latest version of screenpipe")?;
}
- if let Some(tray) = self.app.tray_by_id("screenpipe_main") {
+ {
let theme = dark_light::detect().unwrap_or(Mode::Dark);
let icon_path = if theme == Mode::Light {
"assets/screenpipe-logo-tray-updates-black.png"
@@ -274,9 +274,17 @@ impl UpdatesManager {
.path()
.resolve(icon_path, tauri::path::BaseDirectory::Resource)?;
- if let Ok(image) = tauri::image::Image::from_path(path) {
- crate::safe_icon::safe_set_icon_as_template(&tray, image)?;
- }
+ let image = tauri::image::Image::from_path(path)?;
+
+ // TrayIcon must be accessed/dropped on the main thread
+ let app_clone = self.app.clone();
+ let _ = self.app.run_on_main_thread(move || {
+ if let Some(tray) = app_clone.tray_by_id("screenpipe_main") {
+ if let Err(e) = crate::safe_icon::safe_set_icon_as_template(&tray, image) {
+ error!("failed to set tray update icon: {}", e);
+ }
+ }
+ });
}
// Download and install on all platforms