Skip to content

A full-featured download manager.

fix(windows): avoid shortcut creation on startup (#2014)

Dr_rOot0152a78a759a
diff --git a/src/main/plugin/capability-host.test.ts b/src/main/plugin/capability-host.test.ts
index a6bb97ec..eaf64637 100644
--- a/src/main/plugin/capability-host.test.ts
+++ b/src/main/plugin/capability-host.test.ts
@@ -87,6 +87,7 @@ describe('createElectronCapabilityHost', () => {
beforeEach(() => {
db = makeDb()
+ MockNotification.isSupported.mockClear()
})
afterEach(() => {
@@ -109,6 +110,22 @@ describe('createElectronCapabilityHost', () => {
expect(host.http).toBeInstanceOf(HttpCapabilityHost)
})
+ it('does not initialize native notification support while wiring capabilities', async () => {
+ await createElectronCapabilityHost({
+ appVersion: '2.0.0',
+ hostLanguage: 'en-US',
+ db,
+ userDataDir: tmpdir(),
+ pluginsDir: path.join(tmpdir(), 'plugins'),
+ settingsManager: makeSettingsManager(),
+ configReader: () => ({}),
+ secretFieldsFor: () => new Set(),
+ manifestCommandIdsFor: () => new Set(),
+ })
+
+ expect(MockNotification.isSupported).not.toHaveBeenCalled()
+ })
+
it('returns a CapabilityHost with a functional storage host', async () => {
const host = await createElectronCapabilityHost({
appVersion: '2.0.0',
diff --git a/src/main/plugin/notify-electron.test.ts b/src/main/plugin/notify-electron.test.ts
index b5d9973b..ef1e12d6 100644
--- a/src/main/plugin/notify-electron.test.ts
+++ b/src/main/plugin/notify-electron.test.ts
@@ -85,13 +85,27 @@ function clearInstances(): void {
describe('ElectronNotifyHost', () => {
beforeEach(() => {
clearInstances()
+ FakeNotification.isSupported.mockClear()
FakeNotification.isSupported.mockReturnValue(true)
})
- // Test 1: available === true when isSupported returns true.
- it('available === true when Notification.isSupported() is true', () => {
+ // Constructing the host must not initialize Electron's native notification
+ // presenter. Electron 43 performs Windows shortcut registration as a side
+ // effect of Notification.isSupported().
+ it('does not query notification support during construction', () => {
+ new ElectronNotifyHost()
+
+ expect(FakeNotification.isSupported).not.toHaveBeenCalled()
+ })
+
+ // Test 1: support detection remains available on demand and is evaluated
+ // only once, matching the previous snapshot semantics.
+ it('resolves and caches availability lazily', () => {
const host = new ElectronNotifyHost()
+
+ expect(host.available).toBe(true)
expect(host.available).toBe(true)
+ expect(FakeNotification.isSupported).toHaveBeenCalledOnce()
})
// Test 2: show() constructs a Notification with the provided title/body.
@@ -153,14 +167,16 @@ describe('ElectronNotifyHost', () => {
expect(first.closed).toBe(true)
})
- // Test 7: available === false — show() throws NotifyCapabilityError.
- it('throws when available is false', async () => {
+ // Test 7: unsupported runtimes still fail when a notification is requested.
+ it('checks support on first use and throws when unavailable', async () => {
+ FakeNotification.isSupported.mockReturnValue(false)
const host = new ElectronNotifyHost()
- // Manually override available to simulate unsupported platform.
- ;(host as unknown as { available: boolean }).available = false
await expect(
host.show('plugin-a', { title: 'Hi', body: 'x' })
).rejects.toMatchObject({ code: 'plugin.capability.unavailable' })
+ expect(host.available).toBe(false)
+ expect(FakeNotification.isSupported).toHaveBeenCalledOnce()
+ expect(instances).toHaveLength(0)
})
})
diff --git a/src/main/plugin/notify-electron.ts b/src/main/plugin/notify-electron.ts
index 88eb852f..d20940ac 100644
--- a/src/main/plugin/notify-electron.ts
+++ b/src/main/plugin/notify-electron.ts
@@ -12,10 +12,19 @@ import {
import { Notification } from 'electron'
export class ElectronNotifyHost implements NotifyCapabilityHost {
- readonly available: boolean = Notification.isSupported()
+ private notificationSupported: boolean | undefined
private readonly active = new Map<string, Notification>()
+ get available(): boolean {
+ // Keep this check lazy. On Windows, Electron 43 initializes its toast
+ // activator from Notification.isSupported(), which creates or rewrites a
+ // per-user Start Menu shortcut. Constructing the capability host happens
+ // on every app launch, even when no plugin requests a notification.
+ this.notificationSupported ??= Notification.isSupported()
+ return this.notificationSupported
+ }
+
async show(pluginId: string, opts: NotifyShowOpts): Promise<void> {
if (!this.available) {
throw new NotifyCapabilityError(