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: force LiveText guard rect refresh when timeline frames load

Louis Beaumont91d3d3fdef72
diff --git a/apps/screenpipe-app-tauri/components/pipe-store.tsx b/apps/screenpipe-app-tauri/components/pipe-store.tsx
index faac5d52f..d0e1f5dbb 100644
--- a/apps/screenpipe-app-tauri/components/pipe-store.tsx
+++ b/apps/screenpipe-app-tauri/components/pipe-store.tsx
@@ -75,7 +75,7 @@ interface StorePipe {
review_count: number;
install_count: number;
featured: boolean;
- permissions: PipePermissions;
+ permissions?: PipePermissions;
source?: string;
readme_md?: string;
}
@@ -131,7 +131,8 @@ const PERMISSION_LABELS: { key: string; label: string; icon: React.ReactNode }[]
{ key: "connections", label: "Connections", icon: <Plug className="h-3.5 w-3.5" /> },
];
-function getPermissionStatus(perms: PipePermissions, key: string): "allowed" | "denied" | "unset" {
+function getPermissionStatus(perms: PipePermissions | undefined, key: string): "allowed" | "denied" | "unset" {
+ if (!perms) return "unset";
const allowKey = `allow_${key}` as keyof PipePermissions;
const denyKey = `deny_${key}` as keyof PipePermissions;
if (perms[denyKey] === true) return "denied";
@@ -140,7 +141,8 @@ function getPermissionStatus(perms: PipePermissions, key: string): "allowed" | "
return "unset";
}
-function isUnrestricted(perms: PipePermissions): boolean {
+function isUnrestricted(perms?: PipePermissions): boolean {
+ if (!perms) return true; // no permissions declared = unrestricted
return (
!perms.deny_ocr &&
!perms.deny_audio &&
@@ -995,17 +997,17 @@ function PipeDetailPanel({
);
})}
</div>
- {pipe.permissions.time_range && (
+ {pipe.permissions?.time_range && (
<div className="flex items-center gap-1.5 text-xs text-muted-foreground pt-2 border-t border-border">
<Clock className="h-3.5 w-3.5" />
- time range: {pipe.permissions.time_range}
+ time range: {pipe.permissions?.time_range}
</div>
)}
- {pipe.permissions.day_restrictions &&
+ {pipe.permissions?.day_restrictions &&
pipe.permissions.day_restrictions.length > 0 && (
<div className="flex items-center gap-1.5 text-xs text-muted-foreground">
<Clock className="h-3.5 w-3.5" />
- days: {pipe.permissions.day_restrictions.join(", ")}
+ days: {pipe.permissions?.day_restrictions?.join(", ")}
</div>
)}
</div>
@@ -1358,7 +1360,7 @@ export function PermissionsReview({
permissions,
authorVerified,
}: {
- permissions: PipePermissions;
+ permissions?: PipePermissions;
authorVerified: boolean;
}) {
const unrestricted = isUnrestricted(permissions);
diff --git a/apps/screenpipe-app-tauri/components/rewind/hooks/use-live-text.ts b/apps/screenpipe-app-tauri/components/rewind/hooks/use-live-text.ts
index bfa9138a5..ed98d074d 100644
--- a/apps/screenpipe-app-tauri/components/rewind/hooks/use-live-text.ts
+++ b/apps/screenpipe-app-tauri/components/rewind/hooks/use-live-text.ts
@@ -45,11 +45,6 @@ export function useLiveText(opts: {
const [nativeLiveTextActive, setNativeLiveTextActive] = useState(false);
const liveTextInitRef = useRef(false);
- // Track consecutive failures to decide when to fall back to web mode.
- // Only permanent errors (XPC, helper app) trigger immediate fallback.
- // Transient errors (missing file, skipped) are tolerated — the counter
- // resets on every successful analyze so a single good frame keeps
- // native mode alive.
const analyzeFailCountRef = useRef(0);
// Get absolute position within the window (accounts for sidebar, titlebar, etc.)
@@ -111,9 +106,9 @@ export function useLiveText(opts: {
// Position is managed exclusively by livetext_update_position.
// The analyze call only sets the analysis + shows the overlay.
- // Debounce: 50ms — short enough to feel near-instant, long enough to skip
- // rapid arrow key presses. The 80ms frame-loading debounce already handles
- // fast scrolling; generation counter in Swift cancels stale requests.
+ // Debounce: 150ms — short enough to feel responsive, long enough to skip
+ // intermediate frames during fast scroll. Generation counter in Swift
+ // handles cancellation of stale in-flight requests.
let cancelled = false;
const currentFrameId = String(debouncedFrame.frameId);
const timer = setTimeout(() => {
@@ -126,7 +121,6 @@ export function useLiveText(opts: {
analyzeFailCountRef.current = 0;
// Analysis is stored as pending in Swift — send position update
// to apply it with correct geometry for hit-region computation.
- // Pass frameId so Swift validates the pending analysis matches.
if (!cancelled && renderedImageInfo) {
const pos = getAbsolutePosition(renderedImageInfo);
invoke("livetext_update_position", { frameId: currentFrameId, ...pos }).catch(() => {});
@@ -134,36 +128,21 @@ export function useLiveText(opts: {
}).catch((e: unknown) => {
if (cancelled) return;
const msg = String(e);
-
- // Permanent errors — VisionKit itself is broken, no point retrying
if (msg.includes("helper application") || msg.includes("XPC")) {
console.warn("[livetext] VisionKit unavailable (code signing?), falling back to web mode");
setNativeLiveTextActive(false);
return;
}
-
- // Transient errors — file missing, skipped due to newer request, etc.
- // These are expected during fast scrolling or when snapshot files
- // haven't been written yet. Don't count them toward the fatal limit.
- const isTransient =
- msg.includes("failed to load image") ||
- msg.includes("skipped") ||
- msg.includes("not found");
- if (isTransient) {
- console.debug("[livetext] transient error (will retry on next frame):", msg);
- return;
- }
-
- // Unknown errors — count consecutive failures, fall back after 5
+ // After 3 consecutive failures, fall back to web mode
analyzeFailCountRef.current++;
- if (analyzeFailCountRef.current >= 5) {
- console.warn("[livetext] too many consecutive failures, falling back to web mode");
+ if (analyzeFailCountRef.current >= 3) {
+ console.warn("[livetext] too many failures, falling back to web mode");
setNativeLiveTextActive(false);
return;
}
- console.warn("[livetext] analyze failed:", e);
+ console.warn("live text analyze failed:", e);
});
- }, 50);
+ }, 150);
return () => { cancelled = true; clearTimeout(timer); };
}, [nativeLiveTextActive, debouncedFrame?.frameId, isSnapshotFrame]);
@@ -183,7 +162,6 @@ export function useLiveText(opts: {
const lower = filePath?.toLowerCase() ?? "";
const isSnapshot = lower.endsWith(".jpg") || lower.endsWith(".jpeg") || lower.endsWith(".png");
- // Use local file for snapshots, HTTP for video chunks
const imagePath = isSnapshot && filePath
? filePath
: `http://localhost:3030/frames/${dev.frame_id}`;
@@ -207,11 +185,9 @@ export function useLiveText(opts: {
// Place click guards over UI elements so VisionKit hit regions
// don't intercept clicks on navigation controls, filters, scrubber, etc.
- // Uses ResizeObserver + MutationObserver to track layout changes.
useEffect(() => {
if (!nativeLiveTextActive) return;
- // Collect all named guard refs: navBarRef as "navbar" + any extra guardRefs
const allGuards: Record<string, React.RefObject<HTMLDivElement | null>> = {
...(navBarRef ? { navbar: navBarRef } : {}),
...guardRefs,
@@ -235,16 +211,13 @@ export function useLiveText(opts: {
}
};
- // Initial update
updateAll();
- // Watch for layout changes with ResizeObserver
const ro = new ResizeObserver(() => updateAll());
for (const ref of Object.values(allGuards)) {
if (ref.current) ro.observe(ref.current);
}
- // Also update on window resize (catches zoom, fullscreen, etc.)
window.addEventListener("resize", updateAll);
return () => {
diff --git a/apps/screenpipe-app-tauri/components/rewind/timeline.tsx b/apps/screenpipe-app-tauri/components/rewind/timeline.tsx
index 32c83bf1d..f2919fdaf 100644
--- a/apps/screenpipe-app-tauri/components/rewind/timeline.tsx
+++ b/apps/screenpipe-app-tauri/components/rewind/timeline.tsx
@@ -100,6 +100,15 @@ export default function Timeline({ embedded = false }: { embedded?: boolean }) {
const scrubberRef = useRef<HTMLDivElement | null>(null);
// Stable guardRefs object for Live Text click guards — refs are stable, so useMemo with empty deps is fine
const guardRefs = useMemo(() => ({ filters: filtersRef, scrubber: scrubberRef }), []);
+
+ // Force guard rect refresh when inner timeline mounts/unmounts
+ useEffect(() => {
+ // Slight delay to let DOM layout settle after inner timeline renders
+ const timer = setTimeout(() => {
+ window.dispatchEvent(new Event("resize"));
+ }, 500);
+ return () => clearTimeout(timer);
+ }, [frames.length]);
const [startAndEndDates, setStartAndEndDates] = useState<TimeRange>(() => {
// Lazy init to avoid SSR/client hydration mismatch from new Date()
const now = new Date();
diff --git a/apps/screenpipe-app-tauri/components/settings/sync-settings.tsx b/apps/screenpipe-app-tauri/components/settings/sync-settings.tsx
index 53d36d08c..fc77a45fe 100644
--- a/apps/screenpipe-app-tauri/components/settings/sync-settings.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/sync-settings.tsx
@@ -438,6 +438,7 @@ function EncryptionKeyReveal() {
function ActiveSyncSettings({
status,
devices,
+ deviceCounts,
onToggleSync,
onTriggerSync,
onRemoveDevice,
@@ -447,6 +448,7 @@ function ActiveSyncSettings({
}: {
status: SyncStatus;
devices: SyncDevice[];
+ deviceCounts: Record<string, { frames: number; audioChunks: number }>;
onToggleSync: (enabled: boolean) => void;
onTriggerSync: () => void;
onRemoveDevice: (deviceId: string) => void;
@@ -459,21 +461,6 @@ function ActiveSyncSettings({
? (status.storageUsed / status.storageLimit) * 100
: 0;
- // Fetch local record counts per device
- const [deviceCounts, setDeviceCounts] = useState<Record<string, { frames: number; audioChunks: number }>>({});
- useEffect(() => {
- fetch("http://localhost:3030/data/device-storage")
- .then((r) => r.ok ? r.json() : [])
- .then((data: { machine_id: string; frames: number; audio_chunks: number }[]) => {
- const map: Record<string, { frames: number; audioChunks: number }> = {};
- for (const d of data) {
- map[d.machine_id] = { frames: d.frames, audioChunks: d.audio_chunks };
- }
- setDeviceCounts(map);
- })
- .catch(() => {});
- }, [devices]);
-
return (
<div className="space-y-6">
{/* Header */}
@@ -721,6 +708,7 @@ export function SyncSettings() {
const [subscription, setSubscription] = useState<SubscriptionStatus | null>(null);
const [status, setStatus] = useState<SyncStatus | null>(null);
const [devices, setDevices] = useState<SyncDevice[]>([]);
+ const [deviceCounts, setDeviceCounts] = useState<Record<string, { frames: number; audioChunks: number }>>({});
const [config, setConfig] = useState<SyncConfig | null>(null);
const [isLoading, setIsLoading] = useState(false);
const [isSyncing, setIsSyncing] = useState(false);
@@ -864,6 +852,19 @@ export function SyncSettings() {
return false;
};
+ const fetchDeviceCounts = () => {
+ fetch("http://localhost:3030/data/device-storage")
+ .then((r) => r.ok ? r.json() : [])
+ .then((data: { machine_id: string; frames: number; audio_chunks: number }[]) => {
+ const map: Record<string, { frames: number; audioChunks: number }> = {};
+ for (const d of data) {
+ map[d.machine_id] = { frames: d.frames, audioChunks: d.audio_chunks };
+ }
+ setDeviceCounts(map);
+ })
+ .catch(() => {});
+ };
+
const initSyncBackend = async (): Promise<boolean> => {
console.log("[sync] initSyncBackend called");
try {
@@ -875,6 +876,7 @@ export function SyncSettings() {
setStatus(statusResult);
setConfig(configResult);
setDevices(devicesResult);
+ fetchDeviceCounts();
if (statusResult.enabled) {
setStep("active");
@@ -889,6 +891,7 @@ export function SyncSettings() {
setStatus(newStatus);
setConfig(newConfig);
setDevices(newDevices);
+ fetchDeviceCounts();
setStep("active");
} else {
setStep("password");
@@ -909,6 +912,7 @@ export function SyncSettings() {
setStatus(newStatus);
setConfig(newConfig);
setDevices(newDevices);
+ fetchDeviceCounts();
setStep("active");
return true;
} catch {
@@ -1261,6 +1265,7 @@ export function SyncSettings() {
<ActiveSyncSettings
status={status}
devices={devices}
+ deviceCounts={deviceCounts}
onToggleSync={handleToggleSync}
onTriggerSync={handleTriggerSync}
onRemoveDevice={handleRemoveDevice}