Skip to content

Commit 2646bac

Browse files
committed
hard code sort min node version
1 parent 051fcf5 commit 2646bac

File tree

6 files changed

+18
-21
lines changed

6 files changed

+18
-21
lines changed

.changeset/old-baboons-move.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@bluecadet/launchpad-monitor": patch
3+
---
4+
5+
Hard code window reorder MIN_NODE_VERSION instead of making it configurable

packages/monitor/src/core/__tests__/app-manager.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ function setupTestAppManager() {
4747
],
4848
windowsApi: {
4949
debounceDelay: 3000,
50-
nodeVersion: ">=17.4.0",
5150
},
5251
deleteExistingBeforeConnect: false,
5352
plugins: [],

packages/monitor/src/core/app-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class AppManager {
104104

105105
return ResultAsync.combine(appResults).andThen((apps) => {
106106
return ResultAsync.fromPromise(
107-
sortWindows(apps, this.#logger, this.#config.windowsApi.nodeVersion),
107+
sortWindows(apps, this.#logger),
108108
(e) => new Error("Failed to sort windows", { cause: e }),
109109
);
110110
});

packages/monitor/src/monitor-config.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@ const windowsApiConfigSchema = z.object({
1414
.describe(
1515
"The delay until windows are ordered after launch of in ms. Defaults to 3000. If your app takes a long time to open all of its windows, set this number to a higher value to ensure it can be on top of the launchpad terminal window. Keeping this high also reduces the CPU load if apps relaunch often.",
1616
),
17-
/**
18-
* The minimum major node version to support window ordering. Node versions < 17 seem to have a fatal
19-
* bug with the native API, which will intermittently cause V8 to crash hard. Defaults to '>=17.4.0'.
20-
*/
21-
nodeVersion: z
22-
.string()
23-
.default(">=17.4.0")
24-
.describe(
25-
"The minimum major node version to support window ordering. Node versions < 17 seem to have a fatal bug with the native API, which will intermittently cause V8 to crash hard. Defaults to '>=17.4.0'.",
26-
),
2717
});
2818

2919
export type WindowsApiConfig = z.infer<typeof windowsApiConfigSchema>;

packages/monitor/src/utils/__tests__/sort-windows.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { afterEach } from "node:test";
22
import { createMockLogger } from "@bluecadet/launchpad-testing/test-utils.ts";
33
import type { Logger } from "@bluecadet/launchpad-utils";
4-
import chalk from "chalk";
54
import { type Window, windowManager } from "node-window-manager";
65
import semver from "semver";
76
import { beforeEach, describe, expect, it, vi } from "vitest";
8-
import sortWindows from "../sort-windows.js";
7+
import sortWindows, { MIN_NODE_VERSION } from "../sort-windows.js";
98

109
// Mock node-window-manager
1110
vi.mock("node-window-manager", () => ({
@@ -46,11 +45,10 @@ describe("sortWindows", () => {
4645
});
4746

4847
it("should check node version before proceeding", async () => {
49-
const minNodeVersion = ">=18.0.0";
5048
vi.spyOn(semver, "satisfies").mockReturnValueOnce(false);
5149

52-
await expect(sortWindows([], mockLogger, minNodeVersion)).rejects.toThrow(/Can't sort windows/);
53-
expect(semver.satisfies).toHaveBeenCalledWith(process.version, minNodeVersion);
50+
await expect(sortWindows([], mockLogger)).rejects.toThrow(/Can't sort windows/);
51+
expect(semver.satisfies).toHaveBeenCalledWith(process.version, MIN_NODE_VERSION);
5452
});
5553

5654
it("should handle empty apps array", async () => {

packages/monitor/src/utils/sort-windows.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,21 @@ type SortApp = {
99
pid?: number;
1010
};
1111

12+
/**
13+
* The minimum major node version to support window ordering. Node versions < 17 seem to have a fatal
14+
* bug with the native API, which will intermittently cause V8 to crash hard. Defaults to '>=17.4.0'.
15+
*/
16+
export const MIN_NODE_VERSION = ">=17.4.0";
17+
1218
const sortWindows = async (
1319
apps: SortApp[],
14-
logger: Logger,
15-
minNodeVersion?: string,
20+
logger: Logger
1621
): Promise<void> => {
1722
const currNodeVersion = process.version;
18-
if (minNodeVersion && !semver.satisfies(currNodeVersion, minNodeVersion)) {
23+
if (!semver.satisfies(currNodeVersion, MIN_NODE_VERSION)) {
1924
return Promise.reject(
2025
new Error(
21-
`Can't sort windows because the current node version '${currNodeVersion}' doesn't satisfy the required version '${minNodeVersion}'. Please upgrade node to apply window settings like foreground/minimize/hide.`,
26+
`Can't sort windows because the current node version '${currNodeVersion}' doesn't satisfy the required version '${MIN_NODE_VERSION}'. Please upgrade node to apply window settings like foreground/minimize/hide.`,
2227
),
2328
);
2429
}

0 commit comments

Comments
 (0)