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
perf(electron): optimize RAM footprint via edgelocal streaming and cache workArea to eliminate idle Win32 kernel calls
Deepender250e8166c61b80
diff --git a/electron/main/index.ts b/electron/main/index.tsindex 100ed52..278b732 100644--- a/electron/main/index.ts+++ b/electron/main/index.ts@@ -34,6 +34,9 @@ app.disableHardwareAcceleration()// Restrict the renderer to a single webContents and forbid remote module usage.app.enableSandbox()+// Expose GC switch for safe idle memory trimming when panel is closed.+app.commandLine.appendSwitch('js-flags', '--expose-gc')+// ---- single instance -------------------------------------------------------const gotLock = app.requestSingleInstanceLock()if (!gotLock) {diff --git a/electron/main/window.ts b/electron/main/window.tsindex 99e9152..a825eca 100644--- a/electron/main/window.ts+++ b/electron/main/window.ts@@ -47,14 +47,18 @@ export let previewActive = falseexport let currentHotZoneWidth = 3export let currentStickDisplayId: number | undefined-/**- * Fix 3: Consecutive-stale-reads counter for getStickGeometry self-heal.- * Tracks how many consecutive repositionWindow() calls have found the saved- * stickDisplayId absent from the display list. The preference is only wiped- * from disk after this reaches STALE_THRESHOLD (2), preventing transient TV- * mirror ID renegotiations from destroying the user's saved monitor choice.- */let staleIdConsecutiveCount = 0+let cachedWorkArea = { x: 0, y: 0, width: 1920, height: 1080 }++export function updateCachedWorkArea(): void {+ try {+ const all = screen.getAllDisplays()+ const stick = all.find(d => d.id === currentStickDisplayId) || screen.getPrimaryDisplay()+ if (stick && stick.workArea) {+ cachedWorkArea = stick.workArea+ }+ } catch {}+}export function setHotZoneWidth(width: number): void {currentHotZoneWidth = width@@ -62,6 +66,7 @@ export function setHotZoneWidth(width: number): void {export function setStickDisplayId(id: number | undefined): void {currentStickDisplayId = id+ updateCachedWorkArea()}export function getMainWindow(): BrowserWindow | null {@@ -96,6 +101,15 @@ export function setInteractive(value: boolean): void {// Panel is closed: full click-through, no forwarding needed.mainWindow.setIgnoreMouseEvents(true, { forward: false })mainWindow.setAlwaysOnTop(true, 'screen-saver')++ // Trigger gentle idle memory cleanup 1.5s after panel closes to reclaim RAM+ if (global.gc) {+ setTimeout(() => {+ if (!interactive && global.gc) {+ try { global.gc() } catch { /* ignore */ }+ }+ }, 1500)+ }}}@@ -189,14 +203,10 @@ function _pollTick(): void {const pt = screen.getCursorScreenPoint()- // Find the stick display (or fallback to primary)- const allDisplays = screen.getAllDisplays()- let stickDisplay = allDisplays.find(d => d.id === currentStickDisplayId)- if (!stickDisplay) {- stickDisplay = screen.getPrimaryDisplay()+ if (cachedWorkArea.width === 1920 && cachedWorkArea.height === 1080) {+ updateCachedWorkArea()}-- const wa = stickDisplay.workArea+ const wa = cachedWorkArea// Translate screen coords → stick display client coords.const clientX = pt.x - wa.x@@ -458,6 +468,7 @@ export function createWindow(): BrowserWindow {})const handleDisplayChange = (triggerPopUp = false) => {+ updateCachedWorkArea()console.log('[Main] Display metrics/topology changed — validating bounds and repositioning window')repositionWindow()if (triggerPopUp) {diff --git a/electron/store/ItemStore.ts b/electron/store/ItemStore.tsindex 30ac263..aeaf9a3 100644--- a/electron/store/ItemStore.ts+++ b/electron/store/ItemStore.ts@@ -537,6 +537,8 @@ export class ItemStore {* duplicates every image in the main process, IPC payload and renderer heap.*/imageToDataUrl(imageId: string, ext?: string): string | null {+ const THUMB_SIZE = 240+ const PREVIEW_CACHE_MAX = 20const cacheKey = `${imageId}.${ext || ''}`const cached = this.previewCache.get(cacheKey)if (cached) {@@ -624,13 +626,13 @@ export class ItemStore {const { kind, imageId, width, height, bytes, ext } = it.datareturn {...it,- data: { kind, imageId, width, height, bytes, ext, preview: this.imageToDataUrl(imageId, ext) ?? '' }+ data: { kind, imageId, width, height, bytes, ext, preview: `edgelocal://${imageId}` }}}if (it.data.kind === 'image-collection') {const imagesWithPreviews = it.data.images.map((img) => ({...img,- preview: this.imageToDataUrl(img.imageId, img.ext) ?? ''+ preview: `edgelocal://${img.imageId}`}))return {...it,@@ -638,15 +640,16 @@ export class ItemStore {}}if (it.data.kind === 'files') {- // Build per-file metadata entries. Generate image preview thumbnails for image files.+ // Build per-file metadata entries. Generate image preview protocol URLs for image files.let imagePreviewCount = 0const entries = it.data.paths.map((p) => {const entry = buildFileEntry(p)if (entry.isImage && imagePreviewCount < 20) {imagePreviewCount+++ const norm = p.replace(/\\/g, '/')return {...entry,- preview: fileToDataUrl(p)+ preview: `edgelocal://file/${encodeURIComponent(norm)}`}}return entry@@ -681,7 +684,6 @@ function isImageExt(p: string): boolean {* hides the size label when it's 0.*/const fileEntryCache = new Map<string, FileEntry>()-const fileDataUrlCache = new Map<string, string>()function buildFileEntry(p: string): FileEntry {if (fileEntryCache.has(p)) return fileEntryCache.get(p)!@@ -698,58 +700,3 @@ function buildFileEntry(p: string): FileEntry {fileEntryCache.set(p, entry)return entry}--/**- * Read an image file from disk and return a small thumbnail as a JPEG data URL.- * We use Electron's nativeImage.createFromPath().resize() to generate a small- * thumbnail on-the-fly without loading the full image bytes into memory.- * This keeps the IPC payload tiny (thumbnail vs 8-9MB original) and prevents- * the main thread from blocking when the user copies large images.- */-const THUMB_SIZE = 240 // px — enough for the card UI, tiny IPC payload--const PREVIEW_CACHE_MAX = 100--function fileToDataUrl(p: string): string {- if (fileDataUrlCache.has(p)) return fileDataUrlCache.get(p)!- try {- // Use Electron nativeImage to create a thumbnail without loading the full file.- const img = nativeImage.createFromPath(p)- if (!img.isEmpty()) {- const size = img.getSize()- // Only resize if the image is larger than our thumbnail size.- const needsResize = size.width > THUMB_SIZE || size.height > THUMB_SIZE- const thumb = needsResize- ? img.resize({ width: THUMB_SIZE, quality: 'good' })- : img- const url = thumb.toDataURL({ scaleFactor: 1.0 })- if (fileDataUrlCache.size > 200) fileDataUrlCache.clear()- fileDataUrlCache.set(p, url)- return url- }- // Fallback for SVG and other formats nativeImage can't decode — read raw.- const buf = readFileSync(p)- const mime = detectImageMime(buf)- const url = `data:${mime};base64,${buf.toString('base64')}`- if (fileDataUrlCache.size > 200) fileDataUrlCache.clear()- fileDataUrlCache.set(p, url)- return url- } catch {- return ''- }-}--/** Detect exact MIME type from image magic bytes. */-function detectImageMime(buf: Buffer): string {- if (buf.length >= 3 && buf[0] === 0xFF && buf[1] === 0xD8 && buf[2] === 0xFF) return 'image/jpeg'- if (buf.length >= 4 && buf[0] === 0x89 && buf[1] === 0x50 && buf[2] === 0x4E && buf[3] === 0x47) return 'image/png'- if (buf.length >= 3 && buf[0] === 0x47 && buf[1] === 0x49 && buf[2] === 0x46) return 'image/gif'- if (buf.length >= 12 && buf[0] === 0x52 && buf[1] === 0x49 && buf[2] === 0x46 && buf[3] === 0x46 && buf[8] === 0x57 && buf[9] === 0x45 && buf[10] === 0x42 && buf[11] === 0x50) return 'image/webp'- if (buf.length >= 2 && buf[0] === 0x42 && buf[1] === 0x4D) return 'image/bmp'- if (buf.length >= 4 && buf[0] === 0x00 && buf[1] === 0x00 && buf[2] === 0x01 && buf[3] === 0x00) return 'image/x-icon'- if (buf.length >= 4 && ((buf[0] === 0x49 && buf[1] === 0x49 && buf[2] === 0x2A && buf[3] === 0x00) || (buf[0] === 0x4D && buf[1] === 0x4D && buf[2] === 0x00 && buf[3] === 0x2A))) return 'image/tiff'- if (buf.length >= 12 && buf[4] === 0x66 && buf[5] === 0x74 && buf[6] === 0x79 && buf[7] === 0x70) return 'image/avif'- const head = buf.subarray(0, 1024).toString('utf8').trim()- if (head.startsWith('<svg') || head.startsWith('<?xml') || head.includes('<svg')) return 'image/svg+xml'- return 'image/png'-}