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
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix: deep link navigation — handle all 10 edge cases
Louis Beaumont63eb265b114c
diff --git a/apps/screenpipe-app-tauri/components/deeplink-handler.tsx b/apps/screenpipe-app-tauri/components/deeplink-handler.tsxindex c876b4b64..8eb0a65e4 100644--- a/apps/screenpipe-app-tauri/components/deeplink-handler.tsx+++ b/apps/screenpipe-app-tauri/components/deeplink-handler.tsx@@ -12,12 +12,14 @@ import { commands } from "@/lib/utils/tauri";import { listen, emit } from "@tauri-apps/api/event";import { onOpenUrl } from "@tauri-apps/plugin-deep-link";import { openSettingsWindow } from "@/lib/utils/window";+import { useTimelineStore } from "@/lib/hooks/use-timeline-store";export function DeeplinkHandler() {const { toast } = useToast();const { setShowChangelogDialog } = useChangelogDialog();const { open: openStatusDialog } = useStatusDialog();const { loadUser, reloadStore } = useSettings();+ const setPendingNavigation = useTimelineStore((s) => s.setPendingNavigation);useEffect(() => {const setupDeepLink = async () => {@@ -78,6 +80,8 @@ export function DeeplinkHandler() {try {const date = new Date(timestamp);if (!isNaN(date.getTime())) {+ // Write to store (persists across mounts) AND emit event (instant if timeline is mounted)+ setPendingNavigation({ timestamp });await commands.showWindow("Main");await emit("navigate-to-timestamp", timestamp);toast({@@ -100,9 +104,11 @@ export function DeeplinkHandler() {// Handle frame deep links: screenpipe://frame/12345if (parsedUrl.pathname?.startsWith("/frame/") || parsedUrl.host === "frame") {- const frameId = (parsedUrl.pathname || parsedUrl.host === "frame" ? `/${url.split("frame/")[1]}` : "").replace(/^\//, "");+ const frameId = url.split("frame/")[1]?.replace(/^\//, "");if (frameId) {try {+ // Store frame navigation — timeline will resolve frame → timestamp+ setPendingNavigation({ timestamp: "", frameId });await commands.showWindow("Main");await emit("navigate-to-frame", frameId);toast({diff --git a/apps/screenpipe-app-tauri/components/rewind/chat-message.tsx b/apps/screenpipe-app-tauri/components/rewind/chat-message.tsxindex 8d4b23513..9c9c75de9 100644--- a/apps/screenpipe-app-tauri/components/rewind/chat-message.tsx+++ b/apps/screenpipe-app-tauri/components/rewind/chat-message.tsx@@ -5,6 +5,7 @@ import { useState, useEffect, useRef } from "react";import { emit } from "@tauri-apps/api/event";import { cn } from "@/lib/utils";+import { useTimelineStore } from "@/lib/hooks/use-timeline-store";import { CodeBlock } from "@/components/ui/codeblock";import { MemoizedReactMarkdown } from "@/components/markdown";import {@@ -27,6 +28,7 @@ export interface ChatMessageProps {export function ChatMessage({ message, ...props }: ChatMessageProps) {const { settings } = useSettings();+ const setPendingNavigation = useTimelineStore((s) => s.setPendingNavigation);const [isThinking, setIsThinking] = useState(false);const [thinkingContent, setThinkingContent] = useState<string[]>([]);const [thinkingTime, setThinkingTime] = useState(0);@@ -168,15 +170,25 @@ export function ChatMessage({ message, ...props }: ChatMessageProps) {}// Handle screenpipe:// timeline deep links in-app- if (href?.startsWith("screenpipe://timeline")) {+ if (href?.startsWith("screenpipe://timeline") || href?.startsWith("screenpipe://frame")) {const handleTimelineClick = async (e: React.MouseEvent<HTMLAnchorElement>) => {e.preventDefault();try {+ if (href.startsWith("screenpipe://frame")) {+ const frameId = href.split("frame/")[1]?.replace(/^\//, "");+ if (frameId) {+ setPendingNavigation({ timestamp: "", frameId });+ await commands.showWindow("Main");+ await emit("navigate-to-frame", frameId);+ }+ return;+ }const url = new URL(href);const timestamp = url.searchParams.get("timestamp") || url.searchParams.get("start_time");if (timestamp) {const date = new Date(timestamp);if (!isNaN(date.getTime())) {+ setPendingNavigation({ timestamp });await commands.showWindow("Main");await emit("navigate-to-timestamp", timestamp);toast({diff --git a/apps/screenpipe-app-tauri/components/rewind/timeline.tsx b/apps/screenpipe-app-tauri/components/rewind/timeline.tsxindex 8014f8592..799178b03 100644--- a/apps/screenpipe-app-tauri/components/rewind/timeline.tsx+++ b/apps/screenpipe-app-tauri/components/rewind/timeline.tsx@@ -131,7 +131,7 @@ export default function Timeline() {setShowAudioTranscript(true);}, [currentIndex]);- const { currentDate, setCurrentDate, fetchTimeRange, hasDateBeenFetched, loadingProgress, onWindowFocus, newFramesCount, lastFlushTimestamp, clearNewFramesCount, clearSentRequestForDate, clearFramesForNavigation } =+ const { currentDate, setCurrentDate, fetchTimeRange, hasDateBeenFetched, loadingProgress, onWindowFocus, newFramesCount, lastFlushTimestamp, clearNewFramesCount, clearSentRequestForDate, clearFramesForNavigation, pendingNavigation, setPendingNavigation } =useTimelineStore();const { frames, isLoading, error, message, fetchNextDayData, websocket } =@@ -231,32 +231,90 @@ export default function Timeline() {};}, []);- // Listen for navigate-to-timestamp events from search window- useEffect(() => {- const unlisten = listen<string>("navigate-to-timestamp", async (event) => {- const targetTimestamp = event.payload;- console.log("Navigating to timestamp:", targetTimestamp);+ // Helper to navigate to a timestamp+ const navigateToTimestamp = useCallback(async (targetTimestamp: string) => {+ console.log("Navigating to timestamp:", targetTimestamp);+ const targetDate = new Date(targetTimestamp);+ if (isNaN(targetDate.getTime())) return;- const targetDate = new Date(targetTimestamp);+ setSeekingTimestamp(targetTimestamp);+ pendingNavigationRef.current = targetDate;++ if (!isSameDay(targetDate, currentDate)) {+ await handleDateChange(targetDate);+ }+ }, [currentDate]); // eslint-disable-line react-hooks/exhaustive-deps- // Show seeking overlay- setSeekingTimestamp(targetTimestamp);+ // Listen for navigate-to-timestamp events from search window / deep links+ useEffect(() => {+ const unlisten = listen<string>("navigate-to-timestamp", async (event) => {+ await navigateToTimestamp(event.payload);+ });- // Store the pending navigation target - will be processed by the frames effect- pendingNavigationRef.current = targetDate;+ return () => {+ unlisten.then((fn) => fn());+ };+ }, [navigateToTimestamp]);- // Navigate to the correct date if needed (this triggers frame fetch)- if (!isSameDay(targetDate, currentDate)) {- await handleDateChange(targetDate);+ // Listen for navigate-to-frame events (deep link: screenpipe://frame/12345)+ useEffect(() => {+ const unlisten = listen<string>("navigate-to-frame", async (event) => {+ const frameId = event.payload;+ console.log("Navigating to frame:", frameId);+ try {+ const resp = await fetch(`http://localhost:3030/frames/${frameId}/ocr`);+ if (resp.ok) {+ const data = await resp.json();+ if (data.timestamp) {+ setPendingNavigation(null);+ await navigateToTimestamp(data.timestamp);+ return;+ }+ }+ // Fallback: try to get frame metadata+ const metaResp = await fetch(`http://localhost:3030/frames/${frameId}`);+ if (metaResp.ok) {+ // Frame endpoint returns image, but we got a 200 — frame exists+ // Use search to find timestamp by frame_id+ const searchResp = await fetch(`http://localhost:3030/search?frame_id=${frameId}&limit=1`);+ if (searchResp.ok) {+ const searchData = await searchResp.json();+ if (searchData.data?.[0]?.content?.timestamp) {+ setPendingNavigation(null);+ await navigateToTimestamp(searchData.data[0].content.timestamp);+ return;+ }+ }+ }+ console.warn("Could not resolve frame", frameId, "to timestamp");+ } catch (error) {+ console.error("Failed to navigate to frame:", error);}- // Note: We don't call jumpToTime here even if on same date.- // The frames effect below handles all cases to avoid stale closure issues.});return () => {unlisten.then((fn) => fn());};- }, [currentDate]);+ }, [navigateToTimestamp, setPendingNavigation]);++ // Consume pending navigation from zustand store on mount (survives page navigation)+ useEffect(() => {+ if (!pendingNavigation) return;++ const consume = async () => {+ if (pendingNavigation.frameId) {+ // Frame navigation — emit event so the listener above resolves it+ await emit("navigate-to-frame", pendingNavigation.frameId);+ } else if (pendingNavigation.timestamp) {+ setPendingNavigation(null);+ await navigateToTimestamp(pendingNavigation.timestamp);+ }+ };++ // Small delay to ensure frames are loading+ const timer = setTimeout(consume, 500);+ return () => clearTimeout(timer);+ }, [pendingNavigation, navigateToTimestamp, setPendingNavigation]);// Process pending navigation when frames load after date changeuseEffect(() => {@@ -291,10 +349,24 @@ export default function Timeline() {// Clear pending navigation and UI statependingNavigationRef.current = null;setSeekingTimestamp(null);+ setPendingNavigation(null);isNavigatingRef.current = false;}}- }, [frames, currentDate]);+ }, [frames, currentDate, setPendingNavigation]);++ // Timeout: clear seeking overlay if navigation doesn't resolve within 15s+ useEffect(() => {+ if (!seekingTimestamp) return;+ const timer = setTimeout(() => {+ console.warn("Navigation timeout — clearing seeking state");+ setSeekingTimestamp(null);+ pendingNavigationRef.current = null;+ setPendingNavigation(null);+ isNavigatingRef.current = false;+ }, 15000);+ return () => clearTimeout(timer);+ }, [seekingTimestamp, setPendingNavigation]);// Progressive loading: show UI immediately once we have any framesconst hasInitialFrames = frames.length > 0;diff --git a/apps/screenpipe-app-tauri/components/standalone-chat.tsx b/apps/screenpipe-app-tauri/components/standalone-chat.tsxindex 8e6ce5f9d..45f19fccb 100644--- a/apps/screenpipe-app-tauri/components/standalone-chat.tsx+++ b/apps/screenpipe-app-tauri/components/standalone-chat.tsx@@ -25,6 +25,7 @@ import { getCurrentWindow } from "@tauri-apps/api/window";import { usePlatform } from "@/lib/hooks/use-platform";import { useSqlAutocomplete } from "@/lib/hooks/use-sql-autocomplete";import { commands } from "@/lib/utils/tauri";+import { useTimelineStore } from "@/lib/hooks/use-timeline-store";import { UpgradeDialog } from "@/components/upgrade-dialog";import {parseMentions,@@ -267,15 +268,25 @@ function MarkdownBlock({ text, isUser }: { text: string; isUser: boolean }) {return <VideoComponent filePath={href} className="my-2" />;}- if (href?.startsWith("screenpipe://timeline")) {+ if (href?.startsWith("screenpipe://timeline") || href?.startsWith("screenpipe://frame")) {const handleTimelineClick = async (e: React.MouseEvent<HTMLAnchorElement>) => {e.preventDefault();try {+ if (href.startsWith("screenpipe://frame")) {+ const frameId = href.split("frame/")[1]?.replace(/^\//, "");+ if (frameId) {+ useTimelineStore.getState().setPendingNavigation({ timestamp: "", frameId });+ await commands.showWindow("Main");+ await emit("navigate-to-frame", frameId);+ }+ return;+ }const url = new URL(href);const timestamp = url.searchParams.get("timestamp") || url.searchParams.get("start_time");if (timestamp) {const date = new Date(timestamp);if (!isNaN(date.getTime())) {+ useTimelineStore.getState().setPendingNavigation({ timestamp });await commands.showWindow("Main");await emit("navigate-to-timestamp", timestamp);}diff --git a/apps/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsx b/apps/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsxindex 15e1a0656..aed66fe11 100644--- a/apps/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsx+++ b/apps/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsx@@ -50,7 +50,11 @@ interface TimelineState {isConnected: boolean; // WebSocket connection statushasCachedData: boolean; // Whether we loaded from cache+ // Deep link navigation — persists across component mounts+ pendingNavigation: { timestamp: string; frameId?: string } | null;+// Actions+ setPendingNavigation: (nav: { timestamp: string; frameId?: string } | null) => void;setFrames: (frames: StreamTimeSeriesResponse[]) => void;setIsLoading: (isLoading: boolean) => void;setError: (error: string | null) => void;@@ -82,7 +86,9 @@ export const useTimelineStore = create<TimelineState>((set, get) => ({lastFlushTimestamp: 0,isConnected: false,hasCachedData: false,+ pendingNavigation: null,+ setPendingNavigation: (nav) => set({ pendingNavigation: nav }),setFrames: (frames) => set({ frames }),setIsLoading: (isLoading) => set({ isLoading }),setError: (error) => set({ error }),