betterdisplaycli 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Makefile +1 -1
- package/package.json +1 -1
- package/src/get.test.ts +19 -1
- package/src/get.ts +38 -16
package/Makefile
CHANGED
package/package.json
CHANGED
package/src/get.test.ts
CHANGED
|
@@ -1,8 +1,26 @@
|
|
|
1
|
-
import { expect, test } from "bun:test";
|
|
1
|
+
import { expect, spyOn, test } from "bun:test";
|
|
2
|
+
import { stderr } from "node:process";
|
|
2
3
|
import { getAllDevices } from "./get";
|
|
3
4
|
|
|
5
|
+
const stderrMock = spyOn(stderr, "write");
|
|
6
|
+
|
|
4
7
|
test("getAllDevices", async () => {
|
|
5
8
|
const numConnected = (await getAllDevices({ ignoreDisplayGroups: true }))
|
|
6
9
|
.length;
|
|
7
10
|
expect(numConnected).toBeTypeOf("number");
|
|
11
|
+
expect(stderrMock.mock.calls.slice(-2)).toEqual([
|
|
12
|
+
[
|
|
13
|
+
"\u001B[90m\u001B[1mbetterdisplaycli get --identifiers\u001B[22m\u001B[39m",
|
|
14
|
+
],
|
|
15
|
+
["\n"],
|
|
16
|
+
]);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("getAllDevices quiet", async () => {
|
|
20
|
+
stderrMock.mockReset();
|
|
21
|
+
const numConnected = (
|
|
22
|
+
await getAllDevices({ ignoreDisplayGroups: true, quiet: true })
|
|
23
|
+
).length;
|
|
24
|
+
expect(numConnected).toBeTypeOf("number");
|
|
25
|
+
expect(stderrMock.mock.calls).toEqual([]);
|
|
8
26
|
});
|
package/src/get.ts
CHANGED
|
@@ -7,16 +7,36 @@ import {
|
|
|
7
7
|
type VirtualScreen,
|
|
8
8
|
} from "./Device";
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
interface QuietOption {
|
|
11
|
+
quiet?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function print(
|
|
15
|
+
command: PrintableShellCommand,
|
|
16
|
+
printOptions?: Parameters<PrintableShellCommand["print"]>[0],
|
|
17
|
+
quietOptions?: QuietOption,
|
|
18
|
+
): PrintableShellCommand {
|
|
19
|
+
if (!quietOptions?.quiet) {
|
|
20
|
+
command.print(printOptions);
|
|
21
|
+
}
|
|
22
|
+
return command;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function getAllDevices(
|
|
26
|
+
options?: {
|
|
27
|
+
ignoreDisplayGroups?: true;
|
|
28
|
+
} & QuietOption,
|
|
29
|
+
): Promise<(Display | VirtualScreen)[]>;
|
|
30
|
+
export async function getAllDevices(
|
|
31
|
+
options?: {
|
|
32
|
+
ignoreDisplayGroups?: boolean;
|
|
33
|
+
} & QuietOption,
|
|
34
|
+
): Promise<Device[]> {
|
|
35
|
+
const jsonStream = await print(
|
|
36
|
+
new PrintableShellCommand("betterdisplaycli", [["get", "--identifiers"]]),
|
|
37
|
+
{ argumentLineWrapping: "inline" },
|
|
38
|
+
options,
|
|
39
|
+
)
|
|
20
40
|
.stdout()
|
|
21
41
|
.text();
|
|
22
42
|
const deviceInfos: DeviceInfo[] = JSON.parse(`[${jsonStream}]`);
|
|
@@ -30,10 +50,12 @@ export async function getAllDevices(options?: {
|
|
|
30
50
|
});
|
|
31
51
|
}
|
|
32
52
|
|
|
33
|
-
export async function connectAllDisplays(): Promise<void> {
|
|
34
|
-
await
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
53
|
+
export async function connectAllDisplays(options?: QuietOption): Promise<void> {
|
|
54
|
+
await print(
|
|
55
|
+
new PrintableShellCommand("betterdisplaycli", [
|
|
56
|
+
["perform", "--connectAllDisplays"],
|
|
57
|
+
]),
|
|
58
|
+
{ argumentLineWrapping: "inline" },
|
|
59
|
+
options,
|
|
60
|
+
).spawnTransparently().success;
|
|
39
61
|
}
|