img clipboard
This commit is contained in:
parent
33897e7024
commit
b03d74661a
BIN
packages/kbot/dist/win-64/tauri-app.exe
vendored
BIN
packages/kbot/dist/win-64/tauri-app.exe
vendored
Binary file not shown.
@ -57,9 +57,25 @@ 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);
|
||||
// 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
|
||||
@ -72,16 +88,11 @@ async fn parse_clipboard_images(
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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);
|
||||
Err(e2) => {
|
||||
info!("[parse_clipboard_images] No file list found: {}", e2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
|
||||
@ -361,10 +361,27 @@ function App() {
|
||||
|
||||
// Update destination directory
|
||||
const firstPath = uniqueNewPaths[0];
|
||||
|
||||
// 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('\\'));
|
||||
const newDir = firstPath.substring(0, lastSeparatorIndex);
|
||||
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
|
||||
|
||||
@ -126,7 +126,7 @@ const PromptForm: React.FC<PromptFormProps> = ({
|
||||
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`, {
|
||||
|
||||
@ -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 || ''
|
||||
}),
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user