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: resolve launch at login path drift and desktop shell fullscreen false positives

Deepender25e02e99135016
diff --git a/electron/main/fullscreen.ts b/electron/main/fullscreen.ts
index 711c63d..be3f2c6 100644
--- a/electron/main/fullscreen.ts
+++ b/electron/main/fullscreen.ts
@@ -17,7 +17,7 @@ import koffi from 'koffi'
// Windows QUERY_USER_NOTIFICATION_STATE enum values:
// 1 = QUNS_NOT_PRESENT (screen saver / locked)
-// 2 = QUNS_BUSY (fullscreen app / presentation mode)
+// 2 = QUNS_BUSY (fullscreen app / presentation mode / desktop shell focus)
// 3 = QUNS_RUNNING_D3D_FULL_SCREEN (D3D fullscreen game)
// 4 = QUNS_PRESENTATION_MODE (PowerPoint / Keynote presentation)
// 5 = QUNS_ACCEPTS_NOTIFICATIONS (normal desktop)
@@ -25,24 +25,46 @@ import koffi from 'koffi'
// 7 = QUNS_APP (Windows Store app)
const FULLSCREEN_STATES = new Set([2, 3, 4])
+// Windows Desktop & Shell window classes that report QUNS_BUSY (2) when focused
+const DESKTOP_SHELL_CLASSES = new Set([
+ 'Progman',
+ 'WorkerW',
+ 'Shell_TrayWnd',
+ 'Shell_SecondaryTrayWnd',
+ 'ImmersiveLauncher',
+ 'MultitaskingViewFrame'
+])
+
/**
- * Load SHQueryUserNotificationState from shell32.dll via koffi.
- * Done once at module load — the DLL stays resident in-process so every
+ * Load SHQueryUserNotificationState from shell32.dll and GetForegroundWindow/GetClassNameA from user32.dll via koffi.
+ * Done once at module load — the DLLs stay resident in-process so every
* subsequent call is just a direct function pointer invocation (~1 µs), with
* no process spawning, CLR load, or disk I/O.
*/
type ShQueryFn = (pquns: [number]) => number
+type GetForegroundWindowFn = () => number
+type GetClassNameFn = (hwnd: number, buf: Buffer, maxCount: number) => number
+
let shQueryFn: ShQueryFn | null = null
+let getForegroundWindowFn: GetForegroundWindowFn | null = null
+let getClassNameFn: GetClassNameFn | null = null
+
if (process.platform === 'win32') {
try {
const shell32 = koffi.load('shell32.dll')
- // The signature: HRESULT SHQueryUserNotificationState(QUERY_USER_NOTIFICATION_STATE *pquns)
- // koffi _Out_ tells koffi to copy the pointed-to value back to JS after the call.
shQueryFn = shell32.func('int SHQueryUserNotificationState(_Out_ int *pquns)') as ShQueryFn
- console.log('[Fullscreen] Loaded SHQueryUserNotificationState via koffi (no PowerShell needed)')
+ console.log('[Fullscreen] Loaded SHQueryUserNotificationState via koffi')
} catch (err) {
console.error('[Fullscreen] koffi shell32 load failed — fullscreen detection disabled:', err)
}
+
+ try {
+ const user32 = koffi.load('user32.dll')
+ getForegroundWindowFn = user32.func('uintptr_t GetForegroundWindow()') as GetForegroundWindowFn
+ getClassNameFn = user32.func('int GetClassNameA(uintptr_t hWnd, _Out_ char *lpClassName, int nMaxCount)') as GetClassNameFn
+ } catch (err) {
+ console.error('[Fullscreen] koffi user32 load failed:', err)
+ }
}
let isFullscreenActiveCache = false
@@ -53,6 +75,22 @@ export function registerFullscreenActiveListener(fn: () => void): void {
onFullscreenDetectedFn = fn
}
+/** Check if the current foreground window belongs to the Windows Desktop or Shell. */
+function isDesktopForeground(): boolean {
+ if (!getForegroundWindowFn || !getClassNameFn) return false
+ try {
+ const hwnd = getForegroundWindowFn()
+ if (!hwnd) return false
+ const buf = Buffer.alloc(256)
+ const len = getClassNameFn(hwnd, buf, 256)
+ if (len <= 0) return false
+ const className = buf.toString('utf8', 0, len).trim()
+ return DESKTOP_SHELL_CLASSES.has(className)
+ } catch {
+ return false
+ }
+}
+
/**
* Synchronously query the notification state via the loaded koffi function.
* Returns the QUERY_USER_NOTIFICATION_STATE integer, or -1 on any error.
@@ -78,7 +116,13 @@ export function triggerFullscreenCheck(): void {
const state = queryNotificationState()
if (state < 0) return // koffi unavailable or call failed
- const isNowFullscreen = FULLSCREEN_STATES.has(state)
+ let isNowFullscreen = FULLSCREEN_STATES.has(state)
+ // Windows Shell/Desktop focus reports QUNS_BUSY (2) when no app window is focused.
+ // Exclude Windows Home Screen / Desktop from game fullscreen suppression.
+ if (isNowFullscreen && state === 2 && isDesktopForeground()) {
+ isNowFullscreen = false
+ }
+
isFullscreenActiveCache = isNowFullscreen
if (isNowFullscreen) {
onFullscreenDetectedFn?.()
diff --git a/electron/main/index.ts b/electron/main/index.ts
index fe01ed6..f4ccc1e 100644
--- a/electron/main/index.ts
+++ b/electron/main/index.ts
@@ -13,7 +13,7 @@ import { APP_CONFIG, runtime } from './config'
import { ensureDirs, cleanTemp, PATHS } from '../store/paths'
import { createWindow, getMainWindow, setInteractive, setVisible, startCursorPoll, stopCursorPoll, stopHeartbeat, setHotZoneWidth } from './window'
import { createTray, registerIncognitoApplier } from './tray'
-import { registerIpc, registerSendListeners } from './ipc'
+import { registerIpc, registerSendListeners, syncLoginItemSettings } from './ipc'
import { prewarmDragIcons } from './drag'
import { initState, getWatcher, loadSettings, saveSettings, pushState, stopStateTimers, getStore } from './state'
import { initAutoUpdater } from './updater'
@@ -134,14 +134,7 @@ app.whenReady().then(() => {
}
setHotZoneWidth(settings.hotZoneWidth || 3)
- if (app.isPackaged) {
- try {
- app.setLoginItemSettings({
- openAtLogin: settings.launchAtLogin,
- path: app.getPath('exe')
- })
- } catch { /* ignore in non-packaged / sandbox */ }
- }
+ syncLoginItemSettings(settings.launchAtLogin)
registerIncognitoApplier((v) => getWatcher().setPaused(v))
getWatcher().setPaused(settings.incognito)
pushState.settings(settings)
diff --git a/electron/main/ipc.ts b/electron/main/ipc.ts
index cb25ff7..1c10055 100644
--- a/electron/main/ipc.ts
+++ b/electron/main/ipc.ts
@@ -172,6 +172,35 @@ export function isStoreBuild(): boolean {
return false
}
+/** Synchronizes launch at login settings with Windows Registry, resolving path drift after updates. */
+export function syncLoginItemSettings(launchAtLogin?: boolean): void {
+ if (!app.isPackaged) return
+ const wantLaunch = launchAtLogin ?? loadSettings().launchAtLogin
+ try {
+ const current = app.getLoginItemSettings()
+ const exePath = app.getPath('exe')
+
+ if (wantLaunch) {
+ if (!current.openAtLogin || current.executableWillLaunchAtLogin === false) {
+ app.setLoginItemSettings({
+ openAtLogin: true,
+ path: exePath,
+ args: ['--hidden']
+ })
+ }
+ } else {
+ if (current.openAtLogin) {
+ app.setLoginItemSettings({
+ openAtLogin: false,
+ path: exePath
+ })
+ }
+ }
+ } catch (err) {
+ console.error('[IPC] Failed to sync login item settings:', err)
+ }
+}
+
export function registerIpc(): void {
handle('state:load', () => {
return {
@@ -556,13 +585,8 @@ export function registerIpc(): void {
}
}
const next = saveSettings(enrichedPatch)
- if (patch.launchAtLogin !== undefined && app.isPackaged) {
- try {
- app.setLoginItemSettings({
- openAtLogin: next.launchAtLogin,
- path: app.getPath('exe')
- })
- } catch { /* ignore */ }
+ if (patch.launchAtLogin !== undefined) {
+ syncLoginItemSettings(next.launchAtLogin)
}
if (patch.hotZoneWidth !== undefined) {
setHotZoneWidth(patch.hotZoneWidth)