fix(desktop): ignore activation during quit cleanup

This commit is contained in:
Theo Browne committed 2026-08-13 18:10:57 -07:00
1 parent 9a82604523
commit 65ecd5aadc
2 files changed
+52 -5

No files matched your search

+45 -4
View File
@@ -75,17 +75,22 @@ function makeElectronWindowLayer(destroyAll: Effect.Effect<void> = Effect.void)
});
}
function makeDesktopWindowLayer(flushMainWindowBounds: Effect.Effect<void> = Effect.void) {
function makeDesktopWindowLayer(
input: {
readonly activate?: Effect.Effect<void>;
readonly flushMainWindowBounds?: Effect.Effect<void>;
} = {},
) {
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<string, (...args: readonly unknown[]) => 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));
}),
);
});
+7 -1
View File
@@ -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(