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
feat(timeline): preserve position when new frames arrive ("live edge" detection)
Louis Beaumont8269a737fa6b
diff --git a/screenpipe-app-tauri/components/rewind/timeline.tsx b/screenpipe-app-tauri/components/rewind/timeline.tsxindex 8eda2a2f9..e938b3fd7 100644--- a/screenpipe-app-tauri/components/rewind/timeline.tsx+++ b/screenpipe-app-tauri/components/rewind/timeline.tsx@@ -82,7 +82,7 @@ export default function Timeline() {setShowAudioTranscript(true);}, [currentIndex]);- const { currentDate, setCurrentDate, fetchTimeRange, hasDateBeenFetched, loadingProgress, onWindowFocus } =+ const { currentDate, setCurrentDate, fetchTimeRange, hasDateBeenFetched, loadingProgress, onWindowFocus, newFramesCount, lastFlushTimestamp, clearNewFramesCount } =useTimelineStore();const { frames, isLoading, error, message, fetchNextDayData, websocket } =@@ -90,6 +90,25 @@ export default function Timeline() {setCurrentFrame(frame);});+ // Track if user is at "live edge" (viewing newest frame, index 0)+ const isAtLiveEdge = currentIndex === 0;+ const prevFramesLengthRef = useRef(frames.length);++ // When new frames arrive and user is NOT at live edge, adjust index to stay on same frame+ useEffect(() => {+ if (newFramesCount > 0 && !isAtLiveEdge && frames.length > prevFramesLengthRef.current) {+ // New frames were added at the front, shift our index to compensate+ setCurrentIndex(prev => prev + newFramesCount);+ console.log(`Adjusted index by +${newFramesCount} to stay on same frame (live edge: ${isAtLiveEdge})`);+ }+ prevFramesLengthRef.current = frames.length;++ // Clear the count after handling+ if (newFramesCount > 0) {+ clearNewFramesCount();+ }+ }, [lastFlushTimestamp, newFramesCount, isAtLiveEdge, frames.length, clearNewFramesCount]);+// Listen for window focus events to refresh timeline datauseEffect(() => {const unlisten = listen<boolean>("window-focused", (event) => {@@ -634,6 +653,8 @@ export default function Timeline() {fetchNextDayData={fetchNextDayData}currentDate={currentDate}startAndEndDates={startAndEndDates}+ newFramesCount={newFramesCount}+ lastFlushTimestamp={lastFlushTimestamp}/>) : (<div className="bg-card/80 backdrop-blur-sm p-4 border-t border-border">diff --git a/screenpipe-app-tauri/components/rewind/timeline/timeline.tsx b/screenpipe-app-tauri/components/rewind/timeline/timeline.tsxindex 8c69fad49..fcb0b0ade 100644--- a/screenpipe-app-tauri/components/rewind/timeline/timeline.tsx+++ b/screenpipe-app-tauri/components/rewind/timeline/timeline.tsx@@ -14,6 +14,8 @@ interface TimelineSliderProps {fetchNextDayData: (date: Date) => void;currentDate: Date;onSelectionChange?: (selectedFrames: StreamTimeSeriesResponse[]) => void;+ newFramesCount?: number; // Number of new frames added (for animation)+ lastFlushTimestamp?: number; // When frames were last added (to trigger animation)}interface AppGroup {@@ -44,6 +46,8 @@ export const TimelineSlider = ({startAndEndDates,currentDate,onSelectionChange,+ newFramesCount = 0,+ lastFlushTimestamp = 0,}: TimelineSliderProps) => {const containerRef = useRef<HTMLDivElement>(null);const observerTargetRef = useRef<HTMLDivElement>(null);@@ -61,6 +65,21 @@ export const TimelineSlider = ({);const { setSelectionRange, selectionRange } = useTimelineSelection();+ // Animation state for new frames pulse+ const [showNewFramesPulse, setShowNewFramesPulse] = useState(false);+ const prevFlushTimestampRef = useRef(lastFlushTimestamp);++ // Trigger pulse animation when new frames arrive+ useEffect(() => {+ if (lastFlushTimestamp > prevFlushTimestampRef.current && newFramesCount > 0) {+ setShowNewFramesPulse(true);+ const timer = setTimeout(() => setShowNewFramesPulse(false), 1500);+ prevFlushTimestampRef.current = lastFlushTimestamp;+ return () => clearTimeout(timer);+ }+ prevFlushTimestampRef.current = lastFlushTimestamp;+ }, [lastFlushTimestamp, newFramesCount]);+// Pre-compute frame index map for O(1) lookups instead of O(n) indexOf// This reduces 2.68M comparisons per render to just 400 Map lookupsconst frameIndexMap = useMemo(() => {@@ -224,6 +243,26 @@ export const TimelineSlider = ({className="absolute top-0 h-1 bg-blue-500/50"style={{ width: lineWidth }}/>+ {/* New frames pulse indicator - appears on right side (newest) */}+ {showNewFramesPulse && (+ <motion.div+ className="absolute right-0 top-0 bottom-0 w-24 pointer-events-none z-20"+ initial={{ opacity: 0 }}+ animate={{ opacity: [0, 1, 0] }}+ transition={{ duration: 1.5, ease: "easeOut" }}+ >+ <div className="h-full w-full bg-gradient-to-l from-green-400/40 via-green-400/20 to-transparent" />+ <motion.div+ className="absolute right-2 top-1/2 -translate-y-1/2 bg-green-500 text-white text-xs font-medium px-2 py-1 rounded-full shadow-lg"+ initial={{ scale: 0, x: 20 }}+ animate={{ scale: 1, x: 0 }}+ exit={{ scale: 0, x: 20 }}+ transition={{ type: "spring", damping: 15 }}+ >+ +{newFramesCount} new+ </motion.div>+ </motion.div>+ )}<divref={containerRef}className="w-full overflow-x-auto overflow-y-visible scroll-smooth scrollbar-hide bg-gradient-to-t from-black/50 to-black/0"diff --git a/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsx b/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsxindex 7702db3b7..58f99c1d9 100644--- a/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsx+++ b/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsx@@ -38,6 +38,9 @@ interface TimelineState {currentDate: Date;websocket: WebSocket | null;sentRequests: Set<string>;+ // Track new frames for animation and position adjustment+ newFramesCount: number; // How many new frames were added at the front (for animation)+ lastFlushTimestamp: number; // Timestamp of last flush (to trigger effects)// ActionssetFrames: (frames: StreamTimeSeriesResponse[]) => void;@@ -51,6 +54,7 @@ interface TimelineState {hasDateBeenFetched: (date: Date) => boolean;flushFrameBuffer: () => void;onWindowFocus: () => void;+ clearNewFramesCount: () => void;}export const useTimelineStore = create<TimelineState>((set, get) => ({@@ -63,12 +67,15 @@ export const useTimelineStore = create<TimelineState>((set, get) => ({currentDate: new Date(),websocket: null,sentRequests: new Set<string>(),+ newFramesCount: 0,+ lastFlushTimestamp: 0,setFrames: (frames) => set({ frames }),setIsLoading: (isLoading) => set({ isLoading }),setError: (error) => set({ error }),setMessage: (message) => set({ message }),setCurrentDate: (date) => set({ currentDate: date }),+ clearNewFramesCount: () => set({ newFramesCount: 0 }),hasDateBeenFetched: (date: Date) => {const { sentRequests } = get();@@ -123,6 +130,20 @@ export const useTimelineStore = create<TimelineState>((set, get) => ({});+ // Count how many new frames ended up at the front (newer than previous newest)+ // This is used for: 1) animation pulse, 2) adjusting currentIndex when not at live edge+ const previousNewest = state.frames[0]?.timestamp;+ let newAtFront = 0;+ if (previousNewest) {+ for (const frame of mergedFrames) {+ if (frame.timestamp.localeCompare(previousNewest) > 0) {+ newAtFront++;+ } else {+ break; // Sorted descending, so once we hit older frames, stop+ }+ }+ }+return {frames: mergedFrames,frameTimestamps: updatedTimestamps,@@ -133,6 +154,8 @@ export const useTimelineStore = create<TimelineState>((set, get) => ({},message: null,error: null,+ newFramesCount: newAtFront,+ lastFlushTimestamp: Date.now(),};});},