diff --git a/packages/kbot/dist/win-64/tauri-app.exe b/packages/kbot/dist/win-64/tauri-app.exe index 4bd13128..dcea3002 100644 Binary files a/packages/kbot/dist/win-64/tauri-app.exe and b/packages/kbot/dist/win-64/tauri-app.exe differ diff --git a/packages/kbot/gui/tauri-app/src-tauri/src/clipboard.rs b/packages/kbot/gui/tauri-app/src-tauri/src/clipboard.rs index b07849bc..70717313 100644 --- a/packages/kbot/gui/tauri-app/src-tauri/src/clipboard.rs +++ b/packages/kbot/gui/tauri-app/src-tauri/src/clipboard.rs @@ -57,31 +57,42 @@ async fn parse_clipboard_images( let candidate_format = candidate_format.unwrap_or_else(|| "png".to_string()); let temp_dir = temp_dir.unwrap_or_else(|| std::env::temp_dir()); - // Try to get file list first (drag and drop from explorer/finder) - if let Ok(file_list) = clipboard.get().file_list() { - info!("[parse_clipboard_images] File list: {:?}", file_list); - for file in file_list { - let path_str = file.to_string_lossy().to_string(); - // Filter for image files only - if path_str.to_lowercase().ends_with(".png") - || path_str.to_lowercase().ends_with(".jpg") - || path_str.to_lowercase().ends_with(".jpeg") - || path_str.to_lowercase().ends_with(".gif") - || path_str.to_lowercase().ends_with(".webp") { - result.push(path_str); + // Try to get image data first (screenshot, copied image) + match clipboard.get().image() { + Ok(image_data) => { + info!( + "[parse_clipboard_images] Found image data: {}x{}, {} bytes", + image_data.width, + image_data.height, + image_data.bytes.len() + ); + let temp_path = save_rgba_image_to_temp(&image_data, &candidate_format, &temp_dir)?; + result.push(temp_path); + } + Err(e) => { + info!("[parse_clipboard_images] No image data found: {}", e); + + // Try to get file list (drag and drop from explorer/finder) + match clipboard.get().file_list() { + Ok(file_list) => { + info!("[parse_clipboard_images] Found file list: {:?}", file_list); + for file in file_list { + let path_str = file.to_string_lossy().to_string(); + // Filter for image files only + if path_str.to_lowercase().ends_with(".png") + || path_str.to_lowercase().ends_with(".jpg") + || path_str.to_lowercase().ends_with(".jpeg") + || path_str.to_lowercase().ends_with(".gif") + || path_str.to_lowercase().ends_with(".webp") { + result.push(path_str); + } + } + } + Err(e2) => { + info!("[parse_clipboard_images] No file list found: {}", e2); + } } } - } - // If no files, try to get image data (screenshot, copied image) - else if let Ok(image_data) = clipboard.get().image() { - info!( - "[parse_clipboard_images] Image data: {}x{}, {} bytes", - image_data.width, - image_data.height, - image_data.bytes.len() - ); - let temp_path = save_rgba_image_to_temp(&image_data, &candidate_format, &temp_dir)?; - result.push(temp_path); } Ok(result) diff --git a/packages/kbot/gui/tauri-app/src/App.tsx b/packages/kbot/gui/tauri-app/src/App.tsx index 189addc8..d9825fe3 100644 --- a/packages/kbot/gui/tauri-app/src/App.tsx +++ b/packages/kbot/gui/tauri-app/src/App.tsx @@ -361,10 +361,27 @@ function App() { // Update destination directory const firstPath = uniqueNewPaths[0]; - const lastSeparatorIndex = Math.max(firstPath.lastIndexOf('/'), firstPath.lastIndexOf('\\')); - const newDir = firstPath.substring(0, lastSeparatorIndex); + + // Check if this is a clipboard image (from temp directory) + const isClipboardImage = firstPath.includes('kbot_clipboard_') || + firstPath.includes(process.platform === 'win32' ? '\\Temp\\' : '/tmp/') || + firstPath.includes('AppData\\Local\\Temp') || + firstPath.includes('/var/folders/'); // macOS temp + + let newDir: string; + if (isClipboardImage) { + // For clipboard images, use current working directory or user's Documents folder + newDir = './'; // Use current working directory + log.info('📋 Clipboard image detected, using current working directory for output'); + } else { + // For regular files, use the directory of the first file + const lastSeparatorIndex = Math.max(firstPath.lastIndexOf('/'), firstPath.lastIndexOf('\\')); + newDir = firstPath.substring(0, lastSeparatorIndex); + } + const currentFilename = dst.split(/[/\\]/).pop() || generateDefaultDst(1, firstPath); - const newDst = `${newDir}${firstPath.includes('\\') ? '\\' : '/'}${currentFilename}`; + const separator = firstPath.includes('\\') ? '\\' : '/'; + const newDst = newDir === './' ? currentFilename : `${newDir}${separator}${currentFilename}`; setDst(newDst); // Read files diff --git a/packages/kbot/gui/tauri-app/src/components/PromptForm.tsx b/packages/kbot/gui/tauri-app/src/components/PromptForm.tsx index bc9c4196..fe954ecd 100644 --- a/packages/kbot/gui/tauri-app/src/components/PromptForm.tsx +++ b/packages/kbot/gui/tauri-app/src/components/PromptForm.tsx @@ -126,7 +126,7 @@ const PromptForm: React.FC = ({ log.info('📋 Paste event detected, checking for images...'); // Try to get images from clipboard using our Tauri command - const result = await tauriApi.parseClipboardImages('png'); + const result = await tauriApi.parseClipboardImages('png', ''); if (result?.success && result.paths && result.paths.length > 0) { log.info(`📋 Found ${result.paths.length} image(s) in clipboard`, { diff --git a/packages/kbot/gui/tauri-app/src/lib/tauriApi.ts b/packages/kbot/gui/tauri-app/src/lib/tauriApi.ts index 288ea229..aed1b2f4 100644 --- a/packages/kbot/gui/tauri-app/src/lib/tauriApi.ts +++ b/packages/kbot/gui/tauri-app/src/lib/tauriApi.ts @@ -239,7 +239,7 @@ export const tauriApi = { parseClipboardImages: (candidateFormat: string = 'png', tempDir?: string) => safeInvoke<{ success: boolean; paths?: string[]; error?: string }>('ipc_parse_clipboard_images', { - candidate_format: candidateFormat, - temp_dir: tempDir || '' + candidateFormat: candidateFormat, + tempDir: tempDir || '' }), };