Skip to content

Commit 0b2a65e

Browse files
committed
feat: Enhance clipboard image handling in RecordSection with improved async processing
1 parent ea39be3 commit 0b2a65e

2 files changed

Lines changed: 45 additions & 30 deletions

File tree

src-tauri/src/summarize.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use anyhow::{Context, Result};
22
use serde::{Deserialize, Serialize};
3+
use std::time::Duration;
34

45
const SYSTEM_PROMPT: &str = r#"You are a professional meeting-notes assistant.
56
Given a raw speaker-labelled transcript, produce concise meeting notes in Markdown with the following sections:
@@ -136,7 +137,10 @@ pub async fn summarize_with_together(
136137
],
137138
};
138139

139-
let client = reqwest::Client::new();
140+
let client = reqwest::Client::builder()
141+
.timeout(Duration::from_secs(300))
142+
.build()
143+
.context("Failed to build HTTP client")?;
140144
let response = client
141145
.post("https://api.together.xyz/v1/chat/completions")
142146
.header("Authorization", format!("Bearer {}", api_key))
@@ -192,7 +196,10 @@ pub async fn summarize_with_claude(
192196
}],
193197
};
194198

195-
let client = reqwest::Client::new();
199+
let client = reqwest::Client::builder()
200+
.timeout(Duration::from_secs(300))
201+
.build()
202+
.context("Failed to build HTTP client")?;
196203
let response = client
197204
.post("https://api.anthropic.com/v1/messages")
198205
.header("x-api-key", api_key)

src/components/RecordSection.svelte

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -120,42 +120,50 @@
120120
appState.pastedImages.push({ dataUrl, timecode, path });
121121
}
122122
123+
let isPasting = false;
124+
123125
async function handlePaste(event: ClipboardEvent) {
124126
if (appState.phase !== "recording") return;
125-
const timecode = appState.elapsedSecs;
126-
127-
// Primary: modern async Clipboard API — more reliable in WKWebView for
128-
// images copied from native apps (screenshots, etc.)
127+
if (isPasting) return;
128+
isPasting = true;
129129
try {
130-
const clipboardItems = await navigator.clipboard.read();
131-
for (const clipItem of clipboardItems) {
132-
const imageType = clipItem.types.find((t) => t.startsWith("image/"));
133-
if (imageType) {
134-
event.preventDefault();
135-
const blob = await clipItem.getType(imageType);
136-
await saveImageBlob(blob, timecode);
137-
return;
130+
const timecode = appState.elapsedSecs;
131+
132+
// Primary: modern async Clipboard API — more reliable in WKWebView for
133+
// images copied from native apps (screenshots, etc.)
134+
try {
135+
const clipboardItems = await navigator.clipboard.read();
136+
for (const clipItem of clipboardItems) {
137+
const imageType = clipItem.types.find((t) => t.startsWith("image/"));
138+
if (imageType) {
139+
event.preventDefault();
140+
const blob = await clipItem.getType(imageType);
141+
await saveImageBlob(blob, timecode);
142+
return;
143+
}
138144
}
145+
} catch {
146+
// Clipboard API unavailable or no permission — fall through to legacy path
139147
}
140-
} catch {
141-
// Clipboard API unavailable or no permission — fall through to legacy path
142-
}
143148
144-
// Fallback: event.clipboardData.items (works for paste from web content)
145-
const items = event.clipboardData?.items;
146-
if (!items) return;
147-
for (const item of Array.from(items)) {
148-
if (item.type.startsWith("image/")) {
149-
event.preventDefault();
150-
const file = item.getAsFile();
151-
if (!file) continue;
152-
try {
153-
await saveImageBlob(file, timecode);
154-
} catch (e) {
155-
console.error("Failed to save pasted image:", e);
149+
// Fallback: event.clipboardData.items (works for paste from web content)
150+
const items = event.clipboardData?.items;
151+
if (!items) return;
152+
for (const item of Array.from(items)) {
153+
if (item.type.startsWith("image/")) {
154+
event.preventDefault();
155+
const file = item.getAsFile();
156+
if (!file) continue;
157+
try {
158+
await saveImageBlob(file, timecode);
159+
} catch (e) {
160+
console.error("Failed to save pasted image:", e);
161+
}
162+
break;
156163
}
157-
break;
158164
}
165+
} finally {
166+
isPasting = false;
159167
}
160168
}
161169

0 commit comments

Comments
 (0)