diff --git a/apps/desktop/src/app/DesktopLifecycle.test.ts b/apps/desktop/src/app/DesktopLifecycle.test.ts index 5f7ebb9ba9..6309a91900 100644 --- a/apps/desktop/src/app/DesktopLifecycle.test.ts +++ b/apps/desktop/src/app/DesktopLifecycle.test.ts @@ -75,17 +75,22 @@ function makeElectronWindowLayer(destroyAll: Effect.Effect = Effect.void) }); } -function makeDesktopWindowLayer(flushMainWindowBounds: Effect.Effect = Effect.void) { +function makeDesktopWindowLayer( + input: { + readonly activate?: Effect.Effect; + readonly flushMainWindowBounds?: Effect.Effect; + } = {}, +) { return Layer.succeed(DesktopWindow.DesktopWindow, { createMain: Effect.die("unexpected window creation"), ensureMain: Effect.die("unexpected window creation"), revealOrCreateMain: Effect.die("unexpected window creation"), - activate: Effect.void, + activate: input.activate ?? Effect.void, createMainIfBackendReady: Effect.void, showConnectingSplash: Effect.void, handleBackendReady: () => Effect.void, handleBackendNotReady: Effect.void, - flushMainWindowBounds, + flushMainWindowBounds: input.flushMainWindowBounds ?? Effect.void, dispatchMenuAction: () => Effect.void, zoomMain: () => Effect.void, syncAppearance: Effect.void, @@ -176,7 +181,7 @@ describe("DesktopLifecycle", () => { Layer.provideMerge(makeElectronAppLayer(appListeners, quit)), Layer.provideMerge(electronThemeLayer), Layer.provideMerge(makeElectronWindowLayer(destroyAll)), - Layer.provideMerge(makeDesktopWindowLayer(flushMainWindowBounds)), + Layer.provideMerge(makeDesktopWindowLayer({ flushMainWindowBounds })), Layer.provideMerge(environmentLayer), Layer.provideMerge(desktopShutdownLayer), Layer.provideMerge(DesktopState.layer), @@ -201,4 +206,40 @@ describe("DesktopLifecycle", () => { ).pipe(Effect.provide(layer)); }), ); + + it.effect("ignores app activation while quitting", () => + Effect.gen(function* () { + const appListeners = new Map void>(); + let activationCount = 0; + const activate = Effect.sync(() => { + activationCount += 1; + }); + const environmentLayer = Layer.succeed(DesktopEnvironment.DesktopEnvironment, { + platform: "darwin", + isDevelopment: false, + } as DesktopEnvironment.DesktopEnvironment["Service"]); + const layer = DesktopLifecycle.layer.pipe( + Layer.provideMerge(makeElectronAppLayer(appListeners)), + Layer.provideMerge(electronThemeLayer), + Layer.provideMerge(makeElectronWindowLayer()), + Layer.provideMerge(makeDesktopWindowLayer({ activate })), + Layer.provideMerge(environmentLayer), + Layer.provideMerge(DesktopShutdown.layer), + Layer.provideMerge(DesktopState.layer), + ); + + yield* Effect.scoped( + Effect.gen(function* () { + const lifecycle = yield* DesktopLifecycle.DesktopLifecycle; + const state = yield* DesktopState.DesktopState; + yield* lifecycle.register; + yield* Ref.set(state.quitting, true); + + appListeners.get("activate")?.(); + + assert.equal(activationCount, 0); + }), + ).pipe(Effect.provide(layer)); + }), + ); }); diff --git a/apps/desktop/src/app/DesktopLifecycle.ts b/apps/desktop/src/app/DesktopLifecycle.ts index 5dec4113c0..6a98e59eb8 100644 --- a/apps/desktop/src/app/DesktopLifecycle.ts +++ b/apps/desktop/src/app/DesktopLifecycle.ts @@ -223,7 +223,13 @@ export const make = DesktopLifecycle.of({ ); }); yield* electronApp.on("activate", () => { - void runEffect(desktopWindow.activate.pipe(Effect.withSpan("desktop.lifecycle.activate"))); + void runEffect( + Effect.gen(function* () { + const state = yield* DesktopState.DesktopState; + if (yield* Ref.get(state.quitting)) return; + yield* desktopWindow.activate; + }).pipe(Effect.withSpan("desktop.lifecycle.activate")), + ); }); yield* electronApp.on("window-all-closed", () => { void runEffect(