betterdisplaycli 0.1.18 → 0.2.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "betterdisplaycli",
3
- "version": "0.1.18",
3
+ "version": "0.2.0",
4
4
  "description": "TypeScript bindings for `betterdisplaycli`.",
5
5
  "author": "Lucas Garron <code@garron.net>",
6
6
  "license": "MIT",
@@ -15,7 +15,7 @@
15
15
  }
16
16
  },
17
17
  "dependencies": {
18
- "printable-shell-command": ">=5.0.7"
18
+ "printable-shell-command": "^5.0.8"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@biomejs/biome": "2.3.9",
package/src/Device.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { PrintableShellCommand } from "printable-shell-command";
2
- import { getDisplayWithSelectorArg, print, type QuietOption } from "./get";
2
+ import { print, type QuietOption } from "./get";
3
3
  import { isNotUndefined, ResolutionInfo } from "./ResolutionInfo";
4
4
 
5
5
  type BOOLEAN_SETTING = "connected" | "hiDPI" | "notch";
@@ -199,23 +199,6 @@ export class Display extends SingleDisplay {
199
199
  constructor(public override readonly info: DisplayInfo) {
200
200
  super(info);
201
201
  }
202
-
203
- static main(): Promise<Display> {
204
- return getDisplayWithSelectorArg("--displayWithMainStatus");
205
- }
206
-
207
- static fromName(name: string): Promise<Display> {
208
- return getDisplayWithSelectorArg(`--name=${name}`);
209
- }
210
-
211
- static async tryFromName(name: string): Promise<Display | null> {
212
- try {
213
- return await getDisplayWithSelectorArg(`--name=${name}`);
214
- } catch {
215
- // TODO: what is the simplest way to verify this was because there was no such display (as opposed to a general invocation error)?
216
- return null;
217
- }
218
- }
219
202
  }
220
203
 
221
204
  export class VirtualScreen extends SingleDisplay {
package/src/get.ts CHANGED
@@ -3,6 +3,7 @@ import {
3
3
  type Device,
4
4
  type DeviceInfo,
5
5
  type Display,
6
+ type DisplayGroup,
6
7
  deviceFromInfo,
7
8
  type VirtualScreen,
8
9
  } from "./Device";
@@ -24,11 +25,13 @@ export function print(
24
25
  return command;
25
26
  }
26
27
 
28
+ type GetDeviceOptions = {
29
+ ignoreDisplayGroups?: true;
30
+ } & QuietOption;
31
+
27
32
  async function getDeviceInfos<T>(
28
33
  printable_shell_command: PrintableShellCommand,
29
- options?: {
30
- ignoreDisplayGroups?: true;
31
- } & QuietOption,
34
+ options?: GetDeviceOptions,
32
35
  ): Promise<T[]> {
33
36
  const jsonStream = await print(
34
37
  printable_shell_command,
@@ -49,14 +52,10 @@ async function getDeviceInfos<T>(
49
52
  }
50
53
 
51
54
  export async function getAllDevices(
52
- options?: {
53
- ignoreDisplayGroups?: true;
54
- } & QuietOption,
55
+ options?: GetDeviceOptions,
55
56
  ): Promise<(Display | VirtualScreen)[]>;
56
57
  export async function getAllDevices(
57
- options?: {
58
- ignoreDisplayGroups?: boolean;
59
- } & QuietOption,
58
+ options?: GetDeviceOptions,
60
59
  ): Promise<Device[]> {
61
60
  const jsonStream = await print(
62
61
  new PrintableShellCommand(BINARY_NAME, [["get", "--identifiers"]]),
@@ -76,17 +75,50 @@ export async function getAllDevices(
76
75
  });
77
76
  }
78
77
 
78
+ export function getMain(
79
+ options?: QuietOption,
80
+ ): Promise<Display | VirtualScreen> {
81
+ return getDisplayWithSelectorArg("--displayWithMainStatus", {
82
+ ...options,
83
+ ignoreDisplayGroups: true,
84
+ });
85
+ }
86
+
87
+ export async function getByName(
88
+ name: string,
89
+ options?: GetDeviceOptions,
90
+ ): Promise<Display | VirtualScreen>;
91
+ export function getByName(
92
+ name: string,
93
+ options?: GetDeviceOptions,
94
+ ): Promise<Display | VirtualScreen | DisplayGroup> {
95
+ return getDisplayWithSelectorArg(`--name=${name}`, options);
96
+ }
97
+
98
+ export async function tryGetByName(
99
+ name: string,
100
+ options?: GetDeviceOptions,
101
+ ): Promise<Display | VirtualScreen | undefined>;
102
+ export async function tryGetByName(
103
+ name: string,
104
+ options?: GetDeviceOptions,
105
+ ): Promise<Display | VirtualScreen | DisplayGroup | undefined> {
106
+ const devices = await getAllDevices(options);
107
+ return devices.filter((device) => device.info.name === name)[0];
108
+ }
109
+
79
110
  export async function getDisplayWithSelectorArg(
80
111
  arg: "--displayWithMainStatus" | `--name=${string}`,
112
+ options?: GetDeviceOptions,
81
113
  ): Promise<Display> {
82
114
  return (
83
115
  await getDeviceInfos<Display>(
84
116
  new PrintableShellCommand("betterdisplaycli", [
85
117
  "get",
86
118
  arg,
87
- "--type=Display",
88
119
  "--identifiers",
89
120
  ]),
121
+ options,
90
122
  )
91
123
  )[0];
92
124
  }
package/src/index.ts CHANGED
@@ -1,3 +1,9 @@
1
1
  export * from "./Device";
2
- export { connectAllDisplays, getAllDevices } from "./get";
2
+ export {
3
+ connectAllDisplays,
4
+ getAllDevices,
5
+ getByName,
6
+ getMain,
7
+ tryGetByName,
8
+ } from "./get";
3
9
  export { ResolutionInfo, type ResolutionInfoData } from "./ResolutionInfo";