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: make ask AI button in audio transcript more reliable

Louis Beaumontabcce619124e
diff --git a/apps/screenpipe-app-tauri/components/rewind/timeline/audio-transcript.tsx b/apps/screenpipe-app-tauri/components/rewind/timeline/audio-transcript.tsx
index dc6c2e957..dedb69b09 100644
--- a/apps/screenpipe-app-tauri/components/rewind/timeline/audio-transcript.tsx
+++ b/apps/screenpipe-app-tauri/components/rewind/timeline/audio-transcript.tsx
@@ -12,6 +12,7 @@ import {
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { showChatWithPrefill } from "@/lib/chat-utils";
+import { toast } from "@/components/ui/use-toast";
import {
ConversationBubble,
TimeGapDivider,
@@ -475,7 +476,10 @@ export function AudioTranscript({
const handleSendToChat = useCallback(async () => {
const data = !!activeMeeting ? meetingConversationData : conversationData;
- if (!data.items.length) return;
+ if (!data.items.length) {
+ toast({ title: "no transcript data to send", variant: "destructive" });
+ return;
+ }
const lines = data.items.map((item) => {
const { speakerName } = getSpeakerInfo(item.audio);
diff --git a/apps/screenpipe-app-tauri/lib/chat-utils.ts b/apps/screenpipe-app-tauri/lib/chat-utils.ts
index fe40cd42e..6f94dc448 100644
--- a/apps/screenpipe-app-tauri/lib/chat-utils.ts
+++ b/apps/screenpipe-app-tauri/lib/chat-utils.ts
@@ -6,7 +6,7 @@
// Shared chat utilities - mention parsing, shortcut formatting, app suggestions
// ============================================================================
-import { emit, once } from "@tauri-apps/api/event";
+import { emit, listen } from "@tauri-apps/api/event";
import { commands } from "@/lib/utils/tauri";
// ============================================================================
@@ -31,15 +31,23 @@ export interface ChatPrefillData {
*/
export async function showChatWithPrefill(data: ChatPrefillData): Promise<void> {
await commands.showWindow("Chat");
- // Wait for the chat component to signal readiness
+ // Wait for the chat component to signal readiness.
+ // Use `listen` (not `once`) so we don't miss events that fire before the
+ // listener is registered — we unlisten manually after the first event.
await new Promise<void>((resolve) => {
- const timeout = setTimeout(resolve, 5000);
- once("chat-ready", () => {
+ let resolved = false;
+ const done = () => {
+ if (resolved) return;
+ resolved = true;
clearTimeout(timeout);
+ unlistenPromise.then((fn) => fn());
resolve();
- });
- // Ping in case chat is already mounted (won't re-emit "chat-ready" on its own)
- emit("chat-ping", {});
+ };
+ const timeout = setTimeout(done, 5000);
+ const unlistenPromise = listen("chat-ready", done);
+ // Ping in case chat is already mounted (won't re-emit "chat-ready" on its own).
+ // Small delay to ensure the listen call above has registered first.
+ setTimeout(() => emit("chat-ping", {}), 50);
});
await emit("chat-prefill", { ...data, targetWindow: "chat" });
}