Edge-Drop is a clipboard shelf on the edge of your screen. Hover to open it. Drag files and images into any app, click to copy text and links. Free and open-source for Windows.
TypeScript clipboardclipboard-managerdesktop-appdrag-and-dropelectronopen-sourceproductivityproductivity-toolwindows
fix(clipboard, ui): fix image copy in web apps (#44) and link card overflow
Deepender2573e1069f50f5
diff --git a/electron/main/ipc.ts b/electron/main/ipc.tsindex 57c4783..cc97cb5 100644--- a/electron/main/ipc.ts+++ b/electron/main/ipc.ts@@ -10,7 +10,7 @@ import { existsSync, readFileSync } from 'node:fs'import { join } from 'node:path'import { execFile } from 'node:child_process'import { psHost, getSystemPowerShellPath } from './powershell'-import { filterValidPaths, isValidFilePath, isExistingFilePath } from './pathValidation'+import { filterValidPaths, isExistingFilePath } from './pathValidation'import { type InvokeMap, type InvokeChannel, type SendMap, type SendChannel } from '../../shared/ipc'import { getStore, loadSettings, saveSettings, pushState, addFiles, getWatcher } from './state'import { sendToMainWindow, setInteractive, setHeartbeatPaused, setHotZoneWidth, repositionWindow, getDisplayListOptions, popUpAndRetract, setWindowFocusable } from './window'@@ -108,37 +108,32 @@ async function writeFileListToClipboard(rawPaths: string[]): Promise<void> {}}-async function writeImageToClipboard(imagePath: string | null, previewDataUrl: string): Promise<void> {- if (process.platform === 'win32' && imagePath && isValidFilePath(imagePath) && existsSync(imagePath)) {+export async function writeImageToClipboard(imagePath: string | null, previewDataUrl?: string): Promise<void> {+ // If we have the full image path on disk, load the nativeImage directly from path+ if (imagePath && existsSync(imagePath)) {try {- const b64Path = Buffer.from(imagePath, 'utf8').toString('base64')- const script = [- 'Add-Type -AssemblyName System.Windows.Forms',- 'Add-Type -AssemblyName System.Drawing',- `$p=[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('${b64Path}'))`,- '$bmp=[Drawing.Image]::FromFile($p)',- '$d=New-Object Windows.Forms.DataObject',- '$d.SetImage($bmp)',- '$c=New-Object System.Collections.Specialized.StringCollection',- '$c.Add($p)|Out-Null',- '$d.SetFileDropList($c)',- '[Windows.Forms.Clipboard]::SetDataObject($d,$true)',- '$bmp.Dispose()'- ].join(';')- await psHost.run(script, 3000)- return+ const img = nativeImage.createFromPath(imagePath)+ if (!img.isEmpty()) {+ clipboard.clear()+ clipboard.writeImage(img)+ return+ }} catch (err) {- console.error('[ipc] writeImageToClipboard PowerShell failed, using bitmap fallback:', err)+ console.error('[ipc] writeImageToClipboard nativeImage.createFromPath failed:', err)}}- // Fallback: write bitmap only via Electron (no file reference)- try {- const img = nativeImage.createFromDataURL(previewDataUrl)- if (!img.isEmpty()) {- clipboard.clear()- clipboard.writeImage(img)- }- } catch { /* ignore */ }++ // Fallback if imagePath was missing but previewDataUrl exists+ if (previewDataUrl) {+ try {+ const img = nativeImage.createFromDataURL(previewDataUrl)+ if (!img.isEmpty()) {+ clipboard.clear()+ clipboard.writeImage(img)+ return+ }+ } catch { /* ignore */ }+ }}/**diff --git a/src/components/PreviewFlyout.tsx b/src/components/PreviewFlyout.tsxindex d8f2d44..112e04b 100644--- a/src/components/PreviewFlyout.tsx+++ b/src/components/PreviewFlyout.tsx@@ -596,12 +596,16 @@ function PreviewContent({background: 'rgba(255, 255, 255, 0.08)',border: '1px solid rgba(255, 255, 255, 0.14)',borderRadius: 999,- padding: '3px 10px'+ padding: '3px 10px',+ maxWidth: 'calc(100% - 75px)',+ overflow: 'hidden',+ whiteSpace: 'nowrap',+ boxSizing: 'border-box'}}><GlobeIcon width={13} height={13} style={{ color: 'rgba(255, 255, 255, 0.85)', flexShrink: 0 }} />- <span style={{ fontSize: 12, fontWeight: 600, color: '#ffffff', fontFamily: SYS_FONT }}>{info.serviceName}</span>- <span style={{ fontSize: 11, color: 'rgba(255, 255, 255, 0.35)' }}>·</span>- <span style={{ fontSize: 11.5, color: 'rgba(255, 255, 255, 0.65)', fontFamily: SYS_FONT }}>{info.domain}</span>+ <span style={{ fontSize: 12, fontWeight: 600, color: '#ffffff', fontFamily: SYS_FONT, flexShrink: 0, whiteSpace: 'nowrap' }}>{info.serviceName}</span>+ <span style={{ fontSize: 11, color: 'rgba(255, 255, 255, 0.35)', flexShrink: 0 }}>·</span>+ <span style={{ fontSize: 11.5, color: 'rgba(255, 255, 255, 0.65)', fontFamily: SYS_FONT, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', minWidth: 0, flexShrink: 1 }}>{info.domain}</span></div><div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>diff --git a/src/styles/item.css b/src/styles/item.cssindex 56cc4ea..cfb204b 100644--- a/src/styles/item.css+++ b/src/styles/item.css@@ -203,10 +203,15 @@flex-direction: column;gap: 6px;width: 100%;+ min-width: 0;+ overflow: hidden;}.link-preview-header {display: flex;align-items: center;+ width: 100%;+ min-width: 0;+ overflow: hidden;}.link-brand-pill {display: inline-flex;@@ -216,21 +221,34 @@border: 1px solid rgba(255, 255, 255, 0.12);border-radius: 999px;padding: 3px 10px;+ max-width: 100%;+ min-width: 0;+ box-sizing: border-box;+ overflow: hidden;+ white-space: nowrap;}.link-service {font-size: calc(11.5px * var(--font-scale, 1));font-weight: 600;color: #ffffff;letter-spacing: -0.01em;+ white-space: nowrap;+ flex-shrink: 0;}.link-dot {font-size: 10px;color: rgba(255, 255, 255, 0.35);+ flex-shrink: 0;}.link-domain {font-size: calc(11px * var(--font-scale, 1));color: rgba(255, 255, 255, 0.65);font-weight: 450;+ white-space: nowrap;+ overflow: hidden;+ text-overflow: ellipsis;+ min-width: 0;+ flex-shrink: 1;}.link-title {font-size: calc(13px * var(--font-scale, 1));@@ -240,11 +258,15 @@overflow: hidden;text-overflow: ellipsis;white-space: nowrap;+ min-width: 0;}.link-url {font-size: calc(11.5px * var(--font-scale, 1));color: rgba(255, 255, 255, 0.70);- word-break: break-all;+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+ min-width: 0;}/* Image thumbnails */diff --git a/tests/imageClipboard.test.ts b/tests/imageClipboard.test.tsnew file mode 100644index 0000000..0a9849e--- /dev/null+++ b/tests/imageClipboard.test.ts@@ -0,0 +1,131 @@+import { describe, it, expect, vi, beforeEach } from 'vitest'+import { writeImageToClipboard } from '../electron/main/ipc'+import { clipboard, nativeImage } from 'electron'++vi.mock('electron', () => {+ let mockClipboardImage: any = null+ return {+ clipboard: {+ clear: vi.fn(),+ writeImage: vi.fn((img) => {+ mockClipboardImage = img+ }),+ readImage: vi.fn(() => mockClipboardImage)+ },+ nativeImage: {+ createFromPath: vi.fn((path: string) => {+ if (path.includes('valid.png')) {+ return {+ isEmpty: () => false,+ getSize: () => ({ width: 1920, height: 1080 })+ }+ }+ return {+ isEmpty: () => true,+ getSize: () => ({ width: 0, height: 0 })+ }+ }),+ createFromDataURL: vi.fn((url: string) => {+ if (url && url.startsWith('data:image/png;base64,')) {+ return {+ isEmpty: () => false,+ getSize: () => ({ width: 240, height: 135 })+ }+ }+ return {+ isEmpty: () => true,+ getSize: () => ({ width: 0, height: 0 })+ }+ })+ },+ app: {+ isPackaged: false,+ getAppPath: () => 'C:\\mock\\app',+ getPath: () => 'C:\\mock\\userData',+ disableHardwareAcceleration: vi.fn(),+ enableSandbox: vi.fn(),+ requestSingleInstanceLock: vi.fn(() => true),+ setAppUserModelId: vi.fn(),+ commandLine: {+ appendSwitch: vi.fn()+ },+ on: vi.fn(),+ whenReady: vi.fn(() => new Promise(() => {})), // never resolves in isolated unit tests+ quit: vi.fn()+ },+ protocol: {+ registerSchemesAsPrivileged: vi.fn(),+ handle: vi.fn()+ },+ ipcMain: {+ on: vi.fn(),+ handle: vi.fn()+ },+ BrowserWindow: {+ fromWebContents: vi.fn()+ },+ powerMonitor: {+ on: vi.fn(),+ removeAllListeners: vi.fn()+ }+ }+})++vi.mock('node:fs', () => ({+ existsSync: vi.fn((p: string) => {+ return p.includes('valid.png')+ }),+ readFileSync: vi.fn(),+ writeFileSync: vi.fn(),+ statSync: vi.fn(),+ mkdirSync: vi.fn()+}))++vi.mock('../electron/main/powershell', () => ({+ psHost: {+ run: vi.fn()+ }+}))++vi.mock('../electron/main/state', () => ({+ getStore: vi.fn(),+ getWatcher: vi.fn(),+ pushState: {+ items: vi.fn(),+ togglePanel: vi.fn()+ }+}))++vi.mock('../electron/store/settings', () => ({+ loadSettings: vi.fn(() => ({ historyLimit: 250, incognito: false }))+}))++describe('writeImageToClipboard (#44)', () => {+ beforeEach(() => {+ vi.clearAllMocks()+ })++ it('writes pure in-memory nativeImage to clipboard when image path exists on disk', async () => {+ const validPath = 'C:\\mock\\images\\valid.png'+ await writeImageToClipboard(validPath)++ expect(nativeImage.createFromPath).toHaveBeenCalledWith(validPath)+ expect(clipboard.clear).toHaveBeenCalledTimes(1)+ expect(clipboard.writeImage).toHaveBeenCalledTimes(1)+ })++ it('uses previewDataUrl fallback if image file is missing on disk', async () => {+ const missingPath = 'C:\\mock\\images\\missing.png'+ const fallbackDataUrl = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUg=='+ await writeImageToClipboard(missingPath, fallbackDataUrl)++ expect(nativeImage.createFromDataURL).toHaveBeenCalledWith(fallbackDataUrl)+ expect(clipboard.clear).toHaveBeenCalledTimes(1)+ expect(clipboard.writeImage).toHaveBeenCalledTimes(1)+ })++ it('does not throw or corrupt clipboard when image is null/empty', async () => {+ await writeImageToClipboard(null)+ expect(clipboard.writeImage).not.toHaveBeenCalled()+ })+})