Skip to content

Commit b146aa0

Browse files
committed
fix(desktop): destroy every window during quit
1 parent 3ce03d6 commit b146aa0

2 files changed

Lines changed: 29 additions & 13 deletions

File tree

‎apps/desktop/src/electron/ElectronWindow.test.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ describe("ElectronWindow", () => {
208208
}).pipe(Effect.provide(TestLayer)),
209209
);
210210

211-
it.effect("preserves destroy failures with the target window", () =>
211+
it.effect("preserves destroy failures and continues with later windows", () =>
212212
Effect.gen(function* () {
213213
const cause = new Error("window destroy failed");
214214
const window = {
@@ -217,7 +217,11 @@ describe("ElectronWindow", () => {
217217
throw cause;
218218
}),
219219
} as unknown as Electron.BrowserWindow;
220-
getAllWindowsMock.mockReturnValueOnce([window]);
220+
const laterWindow = {
221+
id: 44,
222+
destroy: vi.fn(),
223+
} as unknown as Electron.BrowserWindow;
224+
getAllWindowsMock.mockReturnValueOnce([window, laterWindow]);
221225

222226
const electronWindow = yield* ElectronWindow.ElectronWindow;
223227
const exit = yield* Effect.exit(electronWindow.destroyAll);
@@ -231,6 +235,7 @@ describe("ElectronWindow", () => {
231235
assert.isNull(error.channel);
232236
assert.strictEqual(error.cause, cause);
233237
}
238+
assert.equal(vi.mocked(laterWindow.destroy).mock.calls.length, 1);
234239
}).pipe(Effect.provide(TestLayer)),
235240
);
236241
});

‎apps/desktop/src/electron/ElectronWindow.ts‎

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
2+
import type * as Cause from "effect/Cause";
23
import * as Context from "effect/Context";
34
import * as Effect from "effect/Effect";
5+
import * as Exit from "effect/Exit";
46
import * as Layer from "effect/Layer";
57
import * as Option from "effect/Option";
68
import * as Ref from "effect/Ref";
@@ -257,18 +259,27 @@ export const make = Effect.gen(function* () {
257259
}
258260
}),
259261
destroyAll: Effect.gen(function* () {
262+
let firstFailure: Cause.Cause<never> | undefined;
260263
for (const window of yield* listWindows) {
261-
yield* Effect.try({
262-
try: () => window.destroy(),
263-
catch: (cause) =>
264-
new ElectronWindowOperationError({
265-
operation: "destroy-window",
266-
platform,
267-
windowId: window.id,
268-
channel: null,
269-
cause,
270-
}),
271-
}).pipe(Effect.orDie);
264+
const exit = yield* Effect.exit(
265+
Effect.try({
266+
try: () => window.destroy(),
267+
catch: (cause) =>
268+
new ElectronWindowOperationError({
269+
operation: "destroy-window",
270+
platform,
271+
windowId: window.id,
272+
channel: null,
273+
cause,
274+
}),
275+
}).pipe(Effect.orDie),
276+
);
277+
if (Exit.isFailure(exit)) {
278+
firstFailure ??= exit.cause;
279+
}
280+
}
281+
if (firstFailure !== undefined) {
282+
return yield* Effect.failCause(firstFailure);
272283
}
273284
}),
274285
syncAllAppearance: Effect.fn("desktop.electron.window.syncAllAppearance")(function* <E, R>(

0 commit comments

Comments
 (0)