Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions electron/ipc/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ export enum IPC {
OpenPath = 'open_path',
ReadFileText = 'read_file_text',

// Clipboard
SaveClipboardImage = 'save_clipboard_image',

// Notifications
ShowNotification = 'show_notification',
NotificationClicked = 'notification_clicked',
Expand Down
17 changes: 16 additions & 1 deletion electron/ipc/register.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ipcMain, dialog, shell, app, BrowserWindow, Notification } from 'electron';
import { ipcMain, dialog, shell, app, clipboard, BrowserWindow, Notification } from 'electron';
import fs from 'fs';
import os from 'os';
import { fileURLToPath } from 'url';
import { IPC } from './channels.js';
import {
Expand Down Expand Up @@ -463,6 +464,20 @@ export function registerAllHandlers(win: BrowserWindow): void {
return fs.readFileSync(args.filePath, 'utf8');
});

// --- Clipboard ---
const clipboardImagePath = path.join(os.tmpdir(), 'parallel-code-clipboard.png');
ipcMain.handle(IPC.SaveClipboardImage, async () => {
try {
const img = clipboard.readImage();
if (img.isEmpty()) return null;
const buf = img.toPNG();
await fs.promises.writeFile(clipboardImagePath, buf);
return clipboardImagePath;
} catch {
return null;
}
});

// --- System ---
ipcMain.handle(IPC.GetSystemFonts, () => getSystemMonospaceFonts());

Expand Down
2 changes: 2 additions & 0 deletions electron/preload.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ const ALLOWED_CHANNELS = new Set([
// File links
'open_path',
'read_file_text',
// Clipboard
'save_clipboard_image',
// Notifications
'show_notification',
'notification_clicked',
Expand Down
13 changes: 10 additions & 3 deletions src/components/TerminalView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,16 @@ export function TerminalView(props: TerminalViewProps) {

if (isPaste) {
e.preventDefault();
navigator.clipboard.readText().then((text) => {
if (text) enqueueInput(text);
});
(async () => {
const text = await navigator.clipboard.readText().catch(() => '');
if (text) {
enqueueInput(text);
return;
}
// Fall back to clipboard image → save to temp file and paste path
const filePath = await invoke<string | null>(IPC.SaveClipboardImage);
if (filePath) enqueueInput(filePath);
})().catch(() => {});
return false;
}

Expand Down
Loading