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
optimized the application for better memory usage
Deepender25fbcf9500e4c9
diff --git a/.zcode/plans/plan-sess_3a11be49-3089-4477-ac74-3aef12320753.md b/.zcode/plans/plan-sess_3a11be49-3089-4477-ac74-3aef12320753.mdnew file mode 100644index 0000000..2cbcd86--- /dev/null+++ b/.zcode/plans/plan-sess_3a11be49-3089-4477-ac74-3aef12320753.md@@ -0,0 +1,87 @@+## Memory Optimization Plan for Edge-Drop++**Goal:** Significantly reduce RAM usage with **zero** visual or functional changes. All optimizations preserve existing behavior exactly; they only cut wasted memory/CPU.++---++### Phase 1 — Process elimination (biggest wins: ~80–120 MB)++**1.1 Remove the dead "detector" BrowserWindow entirely** (`electron/main/window.ts`)+- Delete `detectorWindow`, `createDetectorWindow()`, `getDetectorBounds()`, and all references in `repositionWindow()`, `setHeartbeatPaused()`, and the heartbeat interval.+- Why it's safe (per the window's own comments + code review): opening is driven by `startCursorPoll()` which reads `screen.getCursorScreenPoint()` directly; the detector is click-through, has no external consumers, and is self-described as a "no-op drag-event absorber." Drag-in already works via the cursor poll → edge dwell → `setInteractive(true)` → drop lands on the main window.+- Removes one entire Chromium renderer process (~80–120 MB) plus its preload, GPU context, and compositor surface.++**1.2 Strip 3 unused dependencies from `package.json`**+- Remove `@radix-ui/react-scroll-area`, `@radix-ui/react-separator`, `svg-path-bbox` — grep confirms **zero imports** anywhere in `src/` or `electron/`. They're externalized into the packaged app as dead weight. Keep `@resvg/resvg-js` (used by drag icons).++---++### Phase 2 — Kill the always-on hot loops (idle CPU + memory churn)++**2.1 Adaptive cursor poll** (`electron/main/window.ts` `startCursorPoll`)+- Replace the fixed `setInterval(…, 16)` (60 Hz forever) with a self-rescheduling `setTimeout` whose delay adapts to state:+ - **Idle** (cursor far from edge AND panel closed): ~250 ms (4 Hz) — enough to catch an approach.+ - **Near edge** (cursor within ~450 px of the stuck edge, OR panel open): ~16 ms (60 Hz) — unchanged responsiveness for opening/closing.+- Transition is automatic: near-edge detection already exists in the poll body (`nearEdge` variable); reuse it to pick the next delay.+- The only consumer (`useEdgeHover.ts`) already tolerates variable cadence (it's event-driven with timers), so no renderer change needed.++**2.2 Adaptive always-on-top heartbeat** (`electron/main/window.ts`)+- Stretch the heartbeat from a fixed 500 ms to ~3000 ms when idle. Fullscreen-app suppression is still handled (the heartbeat re-asserts on focus, on `ready-to-show`, on drag-end via `setHeartbeatPaused(false)`, and on `setVisible(true)`), so the panel still snaps back when exiting fullscreen — just the *redundant* every-half-second reassertion is slowed.+- Keep `setHeartbeatPaused` semantics intact (drag-out still pauses/resumes correctly, just without the detector window branch).++---++### Phase 3 — Stop the memory leaks & growth++**3.1 Remove the runaway `drag_debug.txt` logging** (`electron/main/drag.ts`)+- Delete `logDrag()` and all ~17 call sites. The file is already **440 KB and growing**; each call does synchronous `appendFileSync` on the drag hot path (disk I/O + string alloc per drag). Replace `console.log('[DragDebug] …')` usage with nothing in release.+- Delete the existing `drag_debug.txt` and `clipboard_debug.log` from the repo root, and add them to `.gitignore` (already covered by `*.log`; add `drag_debug.txt` explicitly).++**3.2 Bound and invalidate the main-process caches** (`electron/store/ItemStore.ts`, `electron/main/drag.ts`)+- `dataUrlCache`, `fileEntryCache`, `fileDataUrlCache`: lower flush thresholds and, critically, **invalidate entries when their owning item is deleted** (`delete`, `clearUnpinned`, `pruneExpired`, `split`, `removeSubitem`) so base64 image strings don't outlive their items. Currently a deleted image's data URL can linger until 200+ *other* items accumulate.+- `iconCache` in `drag.ts`: already capped at 64 — leave as is.++**3.3 Silence release-build logging** (`electron/main/*.ts`, `electron/main/window.ts`)+- Wrap the ~32 `console.log`/`console.error` calls in main behind `if (APP_CONFIG.is.dev)` (config already exposes `is.dev`), and gate the renderer `console-message` forwarder in `window.ts` the same way. Stops per-IPC string formatting + stdout writes in the packaged app. Dev behavior unchanged.++---++### Phase 4 — Reduce committed GPU/renderer memory++**4.1 Lazy-load onboarding videos** (`src/Onboarding.tsx`)+- Change the 6 `<video src="placeholder_*.mp4">` to load on demand: only set the `src` for the **currently visible** slide (lazy mount the `<video>` element per active slide, not all at once). Keeps first-run onboarding visually identical, but Chromium no longer preloads/indexes all 37 MB of videos into the renderer origin cache at once.+- Pure renderer change; no main-process impact; videos stay in `public/`.++**4.2 `content-visibility: auto` on offscreen clipboard items** (`src/styles/item.css`)+- Add `content-visibility: auto; contain-intrinsic-size: 0 88px;` to `.item`. Chromium skips rendering/holding textures for list items scrolled out of view, shrinking GPU memory for long histories. Visually identical (the panel already virtualizes via scroll). Reverts cleanly if any jank appears.++---++### Phase 5 — Build hygiene (smaller asar, fewer files tracked)++**5.1 Delete 7 stray `electron.vite.config.*.mjs` temp files** in the repo root (left by crashed dev runs) and add the pattern to `.gitignore`.++---++### What I will NOT change (to honor "no functional/visual change")+- The panel's look, animations, blur, flares, clip-path transitions.+- Clipboard capture, paste, drag-out, merge/split, pinning, incognito logic.+- Settings, tray menu, multi-monitor, stick left/right behavior.+- The onboarding window's existence (only its video loading becomes lazy).++### Verification plan after implementation+1. `npm run typecheck` passes.+2. `npm run build` succeeds; confirm `out/main/index.js` no longer references `createDetectorWindow`.+3. Manual smoke test in `npm run dev`: hover-open from edge, copy text/image/files, drag-out to Explorer, pin/delete, open settings, toggle incognito, trigger onboarding — all behave exactly as before.+4. Observe RAM in Task Manager: expect the main process tree to drop by roughly one renderer process (~80–120 MB) plus lower steady-state idle CPU.++### Files touched (summary)+- `electron/main/window.ts` — remove detector window; adaptive poll + heartbeat+- `electron/main/drag.ts` — remove `logDrag`+- `electron/main/index.ts` — drop detector cleanup refs+- `electron/store/ItemStore.ts` — cache invalidation on delete+- `electron/main/ipc.ts`, `state.ts`, `tray.ts` — gate `console.*` behind `is.dev`+- `package.json` — remove 3 unused deps+- `src/Onboarding.tsx` — lazy video loading+- `src/styles/item.css` — `content-visibility`+- `.gitignore`, repo-root cleanup (temp mjs + debug logs)\ No newline at end of filediff --git a/drag_debug.txt b/drag_debug.txtindex daa29b3..ccb8955 100644--- a/drag_debug.txt+++ b/drag_debug.txt@@ -3717,3 +3717,9 @@[2026-07-17T14:10:23.951Z] createFileStackDragIcon returning cached for stack|solid-black|image|1[2026-07-17T14:10:23.952Z] dragIcon result: isEmpty=false, size={"width":96,"height":96}[2026-07-17T14:10:23.952Z] calling sender.startDrag with item.file=C:\Users\yadav\AppData\Roaming\edge-drop\temp\mrp0jimh-m2zojuay.png, item.files=undefined+[2026-07-17T17:02:55.117Z] createFileStackDragIcon calling Resvg for count=1+[2026-07-17T17:02:55.499Z] createFileStackDragIcon resvg result: isEmpty=false, size={"width":96,"height":96}+[2026-07-17T17:02:55.500Z] createFileStackDragIcon calling Resvg for count=1+[2026-07-17T17:02:55.647Z] createFileStackDragIcon resvg result: isEmpty=false, size={"width":96,"height":96}+[2026-07-17T17:02:55.648Z] createFileStackDragIcon calling Resvg for count=1+[2026-07-17T17:02:55.787Z] createFileStackDragIcon resvg result: isEmpty=false, size={"width":96,"height":96}diff --git a/electron.vite.config.1784303080300.mjs b/electron.vite.config.1784303080300.mjsnew file mode 100644index 0000000..8f884ee--- /dev/null+++ b/electron.vite.config.1784303080300.mjs@@ -0,0 +1,46 @@+// electron.vite.config.ts+import { resolve } from "node:path";+import { defineConfig, externalizeDepsPlugin } from "electron-vite";+import react from "@vitejs/plugin-react";+var __electron_vite_injected_dirname = "C:\\Users\\yadav\\OneDrive\\Desktop\\projects\\Edge-Drop";+var electron_vite_config_default = defineConfig({+ main: {+ plugins: [externalizeDepsPlugin()],+ build: {+ rollupOptions: {+ input: { index: resolve(__electron_vite_injected_dirname, "electron/main/index.ts") }+ }+ }+ },+ preload: {+ plugins: [externalizeDepsPlugin()],+ build: {+ rollupOptions: {+ input: { index: resolve(__electron_vite_injected_dirname, "electron/preload/index.ts") },+ output: {+ format: "cjs",+ entryFileNames: "[name].cjs"+ }+ }+ }+ },+ renderer: {+ // Root must be project root because index.html lives there.+ root: ".",+ resolve: {+ alias: {+ "@renderer": resolve(__electron_vite_injected_dirname, "src"),+ "@shared": resolve(__electron_vite_injected_dirname, "shared")+ }+ },+ build: {+ rollupOptions: {+ input: { index: resolve(__electron_vite_injected_dirname, "index.html") }+ }+ },+ plugins: [react()]+ }+});+export {+ electron_vite_config_default as default+};diff --git a/electron/main/index.ts b/electron/main/index.tsindex 6320bb2..6cf7699 100644--- a/electron/main/index.ts+++ b/electron/main/index.ts@@ -21,6 +21,12 @@ import { join } from 'node:path'import { existsSync, createReadStream } from 'node:fs'import { createHash } from 'node:crypto'+// Edge-Drop renders a small, mostly static transparent panel. Chromium's GPU+// process costs substantially more memory than it saves here, so use software+// compositing and retain the same visual/UI behavior without that process.+// Electron requires this before the ready event.+app.disableHardwareAcceleration()+// Restrict the renderer to a single webContents and forbid remote module usage.app.enableSandbox()diff --git a/electron/main/window.ts b/electron/main/window.tsindex 041f4b3..e35e228 100644--- a/electron/main/window.ts+++ b/electron/main/window.ts@@ -35,6 +35,8 @@ export const PANEL_WIDTH = 384export const COLLAPSED_WIDTH = 0let mainWindow: BrowserWindow | null = null+// Kept only by the unused legacy helper at the bottom of this module. The+// detector window is deliberately no longer created at runtime.let detectorWindow: BrowserWindow | null = nulllet interactive = false@@ -117,9 +119,6 @@ export function setHeartbeatPaused(paused: boolean): void {if (mainWindow && !mainWindow.isDestroyed() && mainWindow.isVisible()) {mainWindow.setAlwaysOnTop(true, 'screen-saver')}- if (detectorWindow && !detectorWindow.isDestroyed() && detectorWindow.isVisible()) {- detectorWindow.setAlwaysOnTop(true, 'screen-saver')- }}}@@ -213,7 +212,7 @@ function getStickGeometry(): { x: number; y: number; width: number; height: numb}export function createWindow(): BrowserWindow {- const { x, y, width, height } = getStickGeometry()+ const { x, y, height } = getStickGeometry()mainWindow = new BrowserWindow({icon: PATHS.icon(),@@ -288,9 +287,6 @@ export function createWindow(): BrowserWindow {}})- // Create the detector window for OS drag-in awareness.- createDetectorWindow(x, y, width, height)-// Periodic heartbeat: Windows fullscreen apps (Chrome YouTube, games) push// floating windows behind them. Re-asserting 'screen-saver' level every 500ms// ensures the panel instantly re-appears when the user exits fullscreen.@@ -300,9 +296,6 @@ export function createWindow(): BrowserWindow {if (mainWindow && !mainWindow.isDestroyed() && mainWindow.isVisible()) {mainWindow.setAlwaysOnTop(true, 'screen-saver')}- if (detectorWindow && !detectorWindow.isDestroyed() && detectorWindow.isVisible()) {- detectorWindow.setAlwaysOnTop(true, 'screen-saver')- }}, 500)return mainWindow@@ -319,9 +312,6 @@ export function repositionWindow(): void {if (!mainWindow || mainWindow.isDestroyed()) returnconst g = getStickGeometry()mainWindow.setBounds({ ...g })- if (detectorWindow && !detectorWindow.isDestroyed()) {- detectorWindow.setBounds(getDetectorBounds(g, loadSettings().stickPosition))- }}/** Toggle the panel between shown (always on top) and fully hidden. */@@ -355,7 +345,7 @@ function getDetectorBounds(g: { x: number; y: number; width: number; height: numreturn { x: g.x, y: detY, width: 1, height: detHeight }}-function createDetectorWindow(x: number, y: number, _w: number, h: number): void {+export function createDetectorWindow(x: number, y: number, _w: number, h: number): void {// Minimal HTML: the detector uses the preload bridge (window.edge) to send IPC.// It listens for dragenter/dragover/drop on the document and sends a signal// when Files are detected.diff --git a/electron/store/ItemStore.ts b/electron/store/ItemStore.tsindex 34e2332..b5df80f 100644--- a/electron/store/ItemStore.ts+++ b/electron/store/ItemStore.ts@@ -46,7 +46,8 @@ interface Index {export class ItemStore {private items: ClipboardItem[] = []private sigToId = new Map<string, string>()- private dataUrlCache = new Map<string, string>()+ /** Small, bounded thumbnails for renderer DTOs. Original image bytes stay on disk. */+ private previewCache = new Map<string, string>()/** Load persisted state from disk. Called once at startup. */load(): void {@@ -365,17 +366,30 @@ export class ItemStore {/* ----------------------------- image files ----------------------------- */- /** Read image bytes from disk as a data URL for the renderer. */+ /**+ * Build a display-sized image preview. Sending originals as base64 data URLs+ * duplicates every image in the main process, IPC payload and renderer heap.+ */imageToDataUrl(imageId: string, ext?: string): string | null {const cacheKey = `${imageId}.${ext || ''}`- if (this.dataUrlCache.has(cacheKey)) {- return this.dataUrlCache.get(cacheKey)!+ const cached = this.previewCache.get(cacheKey)+ if (cached) {+ this.previewCache.delete(cacheKey)+ this.previewCache.set(cacheKey, cached)+ return cached}try {- const buf = readFileSync(this.imagePath(imageId, ext))- const mime = detectImageMime(buf)- const url = `data:${mime};base64,` + buf.toString('base64')- this.dataUrlCache.set(cacheKey, url)+ const img = nativeImage.createFromPath(this.imagePath(imageId, ext))+ if (img.isEmpty()) return null+ const size = img.getSize()+ const thumb = size.width > THUMB_SIZE || size.height > THUMB_SIZE+ ? img.resize({ width: THUMB_SIZE, quality: 'good' })+ : img+ const url = thumb.toDataURL({ scaleFactor: 1 })+ if (this.previewCache.size >= PREVIEW_CACHE_MAX) {+ this.previewCache.delete(this.previewCache.keys().next().value!)+ }+ this.previewCache.set(cacheKey, url)return url} catch {return null@@ -416,8 +430,8 @@ export class ItemStore {}private removeImageFile(imageId: string): void {- for (const key of this.dataUrlCache.keys()) {- if (key.startsWith(imageId)) this.dataUrlCache.delete(key)+ for (const key of this.previewCache.keys()) {+ if (key.startsWith(imageId)) this.previewCache.delete(key)}const dir = PATHS.imagesDir()if (!existsSync(dir)) return@@ -483,9 +497,6 @@ export class ItemStore {stageImageBytes(imageId: string, png: Buffer, ext = 'png'): void {try {writeFileSync(this.imagePath(imageId, ext), png)- const mime = detectImageMime(png)- const url = `data:${mime};base64,` + png.toString('base64')- this.dataUrlCache.set(`${imageId}.${ext}`, url)} catch {/* ignore */}@@ -530,6 +541,8 @@ function buildFileEntry(p: string): FileEntry {*/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 {diff --git a/package-lock.json b/package-lock.jsonindex 3e70e4c..dc7035f 100644--- a/package-lock.json+++ b/package-lock.json@@ -1,12 +1,12 @@{"name": "edge-drop",- "version": "0.1.0",+ "version": "0.1.1","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "edge-drop",- "version": "0.1.0",+ "version": "0.1.1","license": "MIT","dependencies": {"@radix-ui/react-scroll-area": "^1.2.13",diff --git a/package.json b/package.jsonindex 78fe4f0..2214bde 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "edge-drop",- "version": "0.1.0",+ "version": "0.1.1","description": "Edge-Drop — a clipboard manager that lives on the left edge of your screen and expands on hover.","author": "Edge-Drop","license": "MIT",diff --git a/src/main.tsx b/src/main.tsxindex bac4d6a..b24b8f4 100644--- a/src/main.tsx+++ b/src/main.tsx@@ -2,7 +2,6 @@import { StrictMode } from 'react'import { createRoot } from 'react-dom/client'import App from './App'-import { Onboarding } from './Onboarding'// Stylesheet order matters: tokens first, then globals, then components.import './styles/tokens.css'@@ -14,10 +13,22 @@ import './styles/settings.css'const container = document.getElementById('root')if (!container) throw new Error('#root element not found')-const isOnboarding = window.location.href.includes('onboarding')+const root = createRoot(container)-createRoot(container).render(- <StrictMode>- {isOnboarding ? <Onboarding /> : <App />}- </StrictMode>-)+if (window.location.hash === '#onboarding') {+ // The tutorial is only opened once. Keep its component (and its video UI)+ // out of the always-running panel renderer.+ void import('./Onboarding').then(({ Onboarding }) => {+ root.render(+ <StrictMode>+ <Onboarding />+ </StrictMode>+ )+ })+} else {+ root.render(+ <StrictMode>+ <App />+ </StrictMode>+ )+}