Skip to content

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.

fix(clipboard): prevent false copy indicator activation on laptop sleep/unlock via powerMonitor guard

Deepender2542b5168c9a73
diff --git a/electron/main/state.ts b/electron/main/state.ts
index 12a0749..99cfbb9 100644
--- a/electron/main/state.ts
+++ b/electron/main/state.ts
@@ -11,7 +11,7 @@ import { loadSettings, saveSettings } from '../store/settings'
import type { ClipboardItemDto, Settings } from '../../shared/types'
import { MAX_STACK } from '../../shared/types'
import { createId } from '../store/ids'
-import { nativeImage, BrowserWindow } from 'electron'
+import { nativeImage, BrowserWindow, powerMonitor } from 'electron'
import { readFileSync } from 'node:fs'
import { PATHS } from '../store/paths'
import { prefetchFileIcons } from './drag'
@@ -20,6 +20,23 @@ import { runtime } from './config'
const store = new ItemStore()
const watcher = new ClipboardWatcher(600)
let pruneTimer: ReturnType<typeof setInterval> | null = null
+let wakeTimer: ReturnType<typeof setTimeout> | null = null
+
+function handleSystemSleep(): void {
+ watcher.setPaused(true)
+}
+
+function handleSystemWake(): void {
+ watcher.resyncSignature()
+ watcher.setPaused(true)
+
+ if (wakeTimer !== null) clearTimeout(wakeTimer)
+ wakeTimer = setTimeout(() => {
+ wakeTimer = null
+ watcher.resyncSignature()
+ watcher.setPaused(loadSettings().incognito)
+ }, 1500)
+}
/** Initialize persistence + start the clipboard watcher. */
export function initState(): void {
@@ -48,6 +65,16 @@ export function initState(): void {
})
watcher.setPaused(loadSettings().incognito)
+ powerMonitor.removeAllListeners('suspend')
+ powerMonitor.removeAllListeners('lock-screen')
+ powerMonitor.removeAllListeners('resume')
+ powerMonitor.removeAllListeners('unlock-screen')
+
+ powerMonitor.on('suspend', handleSystemSleep)
+ powerMonitor.on('lock-screen', handleSystemSleep)
+ powerMonitor.on('resume', handleSystemWake)
+ powerMonitor.on('unlock-screen', handleSystemWake)
+
// After a restart-clear, the watcher.start() seeds lastSig from the live
// clipboard (correct). But if clearUnpinnedOnRestart removed items that are
// still on the clipboard, the user can re-copy them immediately — this works