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(exe): allow launch-at-login to turn on after GitHub upgrades

Deepender2501775b2bfd58
diff --git a/electron/main/loginItems.ts b/electron/main/loginItems.ts
index af118e8..9f2f5d5 100644
--- a/electron/main/loginItems.ts
+++ b/electron/main/loginItems.ts
@@ -2,7 +2,8 @@
* Launch-at-login.
*
* GitHub NSIS: Electron Run keys. Older builds used different value names, so
- * enable/disable clears every name Task Manager might still list.
+ * disable still clears leftover names. Enable must not disable Edge-Drop first
+ * — that stamps Windows Startup apps as Off and the toggle then fails.
*
* Store / AppX: Windows.ApplicationModel.StartupTask only —
* getStatus / enable (RequestEnableAsync) / disable. Same API as
@@ -31,11 +32,21 @@ export interface LaunchAtLoginResult {
ok: boolean
}
+export function normalizeLoginPath(p: string): string {
+ let s = p.trim().replace(/\//g, '\\').toLowerCase()
+ if (s.startsWith('"')) {
+ const end = s.indexOf('"', 1)
+ s = end > 0 ? s.slice(1, end) : s.replace(/"/g, '')
+ } else {
+ const exe = s.indexOf('.exe')
+ if (exe >= 0) s = s.slice(0, exe + 4)
+ }
+ return s
+}
+
export function isOurLoginExe(candidate: string | undefined, exePath: string): boolean {
if (!candidate) return false
- const a = candidate.replace(/\//g, '\\').toLowerCase()
- const b = exePath.replace(/\//g, '\\').toLowerCase()
- return a === b
+ return normalizeLoginPath(candidate) === normalizeLoginPath(exePath)
}
function resultFromState(state: number | null, wantEnabled?: boolean): LaunchAtLoginResult {
@@ -53,6 +64,19 @@ function resultFromState(state: number | null, wantEnabled?: boolean): LaunchAtL
}
}
+function collectGithubLoginNames(exePath: string): Set<string> {
+ const names = new Set<string>(GITHUB_LOGIN_ITEM_NAMES)
+ try {
+ const items = app.getLoginItemSettings({ path: exePath }).launchItems ?? []
+ for (const item of items) {
+ if (item.name && isOurLoginExe(item.path, exePath)) names.add(item.name)
+ }
+ } catch {
+ /* ignore */
+ }
+ return names
+}
+
function readGithubLaunchAtLogin(): LaunchAtLoginResult {
const exePath = app.getPath('exe')
const seen = app.getLoginItemSettings({
@@ -61,35 +85,30 @@ function readGithubLaunchAtLogin(): LaunchAtLoginResult {
})
const items = seen.launchItems ?? []
const ours = items.filter((item) => isOurLoginExe(item.path, exePath))
- const enabled = ours.some((item) => item.enabled) || (!!seen.executableWillLaunchAtLogin && ours.length > 0)
+ const anyEnabled = ours.some((item) => item.enabled)
+ const enabled = anyEnabled || !!seen.executableWillLaunchAtLogin
return {
enabled,
- blockedByUser: ours.some((item) => !item.enabled) && !enabled,
+ blockedByUser: ours.length > 0 && !anyEnabled && ours.some((item) => !item.enabled) && !seen.executableWillLaunchAtLogin,
ok: true
}
}
function applyGithubLaunchAtLogin(wantLaunch: boolean): LaunchAtLoginResult {
const exePath = app.getPath('exe')
- const extraNames = new Set<string>(GITHUB_LOGIN_ITEM_NAMES)
- try {
- const items = app.getLoginItemSettings({ path: exePath }).launchItems ?? []
- for (const item of items) {
- if (item.name && isOurLoginExe(item.path, exePath)) extraNames.add(item.name)
- }
- } catch {
- /* ignore */
- }
-
- for (const name of extraNames) {
- app.setLoginItemSettings({
- openAtLogin: false,
- path: exePath,
- name
- })
- }
+ const names = collectGithubLoginNames(exePath)
if (wantLaunch) {
+ // Do not disable Edge-Drop before enabling it. That writes Windows
+ // StartupApproved as Off and the in-app toggle then fails after upgrades.
+ for (const name of names) {
+ if (name === CANONICAL_LOGIN_ITEM_NAME) continue
+ app.setLoginItemSettings({
+ openAtLogin: false,
+ path: exePath,
+ name
+ })
+ }
app.setLoginItemSettings({
openAtLogin: true,
path: exePath,
@@ -97,8 +116,18 @@ function applyGithubLaunchAtLogin(wantLaunch: boolean): LaunchAtLoginResult {
name: CANONICAL_LOGIN_ITEM_NAME,
enabled: true
})
+ const read = readGithubLaunchAtLogin()
+ if (read.blockedByUser) return { ...read, ok: false }
+ return { enabled: true, blockedByUser: false, ok: true }
}
+ for (const name of names) {
+ app.setLoginItemSettings({
+ openAtLogin: false,
+ path: exePath,
+ name
+ })
+ }
return readGithubLaunchAtLogin()
}
@@ -131,7 +160,8 @@ export async function applyLaunchAtLogin(wantLaunch: boolean): Promise<LaunchAtL
}
try {
const result = applyGithubLaunchAtLogin(wantLaunch)
- return { ...result, ok: result.enabled === wantLaunch }
+ if (wantLaunch) return result
+ return { ...result, ok: !result.enabled }
} catch (err) {
console.error('[LoginItems] GitHub Run-key update failed:', err)
return { enabled: !wantLaunch, blockedByUser: false, ok: false }
diff --git a/tests/storeLoginItem.test.ts b/tests/storeLoginItem.test.ts
index 6fe6cbe..1ba466b 100644
--- a/tests/storeLoginItem.test.ts
+++ b/tests/storeLoginItem.test.ts
@@ -61,7 +61,7 @@ vi.mock('../electron/main/powershell', () => ({
getWritableCwd: () => 'C:\\Temp'
}))
-import { applyLaunchAtLogin, reconcileLaunchAtLoginOnStartup, GITHUB_LOGIN_ITEM_NAMES } from '../electron/main/loginItems'
+import { applyLaunchAtLogin, reconcileLaunchAtLoginOnStartup } from '../electron/main/loginItems'
import { syncLoginItemSettings } from '../electron/main/ipc'
describe('GitHub exe launch-at-login (orphan Run keys)', () => {
@@ -88,7 +88,7 @@ describe('GitHub exe launch-at-login (orphan Run keys)', () => {
expect(mocks.setLoginItemSettings).not.toHaveBeenCalled()
})
- it('enable: clears every historical name then writes Edge-Drop with --hidden and enabled:true', async () => {
+ it('enable: writes Edge-Drop on without disabling it first, and only clears other leftover names', async () => {
mocks.getLoginItemSettings.mockReturnValue({
launchItems: [
{ name: 'Edge-Drop', path: mocks.exePath, enabled: true, args: ['--hidden'] }
@@ -98,13 +98,21 @@ describe('GitHub exe launch-at-login (orphan Run keys)', () => {
const result = await applyLaunchAtLogin(true)
expect(result.ok).toBe(true)
expect(result.enabled).toBe(true)
- for (const name of GITHUB_LOGIN_ITEM_NAMES) {
- expect(mocks.setLoginItemSettings).toHaveBeenCalledWith({
- openAtLogin: false,
- path: mocks.exePath,
- name
- })
- }
+ expect(mocks.setLoginItemSettings).not.toHaveBeenCalledWith({
+ openAtLogin: false,
+ path: mocks.exePath,
+ name: 'Edge-Drop'
+ })
+ expect(mocks.setLoginItemSettings).toHaveBeenCalledWith({
+ openAtLogin: false,
+ path: mocks.exePath,
+ name: 'com.edgedrop.app'
+ })
+ expect(mocks.setLoginItemSettings).toHaveBeenCalledWith({
+ openAtLogin: false,
+ path: mocks.exePath,
+ name: 'electron.app.Edge-Drop'
+ })
expect(mocks.setLoginItemSettings).toHaveBeenCalledWith({
openAtLogin: true,
path: mocks.exePath,
@@ -114,6 +122,34 @@ describe('GitHub exe launch-at-login (orphan Run keys)', () => {
})
})
+ it('enable: does not fail the toggle when read-back is empty after writing', async () => {
+ mocks.getLoginItemSettings.mockReturnValue({
+ launchItems: [],
+ executableWillLaunchAtLogin: false
+ })
+ const result = await applyLaunchAtLogin(true)
+ expect(result.ok).toBe(true)
+ expect(result.enabled).toBe(true)
+ expect(mocks.setLoginItemSettings).toHaveBeenCalledWith(expect.objectContaining({
+ openAtLogin: true,
+ name: 'Edge-Drop',
+ enabled: true
+ }))
+ })
+
+ it('enable: Windows Startup apps Off is blocked, not treated as success', async () => {
+ mocks.getLoginItemSettings.mockReturnValue({
+ launchItems: [
+ { name: 'Edge-Drop', path: mocks.exePath, enabled: false, args: ['--hidden'] }
+ ],
+ executableWillLaunchAtLogin: false
+ })
+ const result = await applyLaunchAtLogin(true)
+ expect(result.enabled).toBe(false)
+ expect(result.blockedByUser).toBe(true)
+ expect(result.ok).toBe(false)
+ })
+
it('disable: removes every historical name, including leftovers Task Manager still lists', async () => {
mocks.getLoginItemSettings.mockReturnValue({
launchItems: [