betterdisplaycli 0.1.19 → 0.2.1
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 +2 -2
- package/src/Device.ts +6 -26
- package/src/get.ts +41 -11
- package/src/index.ts +7 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "betterdisplaycli",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
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": "
|
|
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 {
|
|
2
|
+
import { print, type QuietOption } from "./get";
|
|
3
3
|
import { isNotUndefined, ResolutionInfo } from "./ResolutionInfo";
|
|
4
4
|
|
|
5
5
|
type BOOLEAN_SETTING = "connected" | "hiDPI" | "notch";
|
|
@@ -149,11 +149,11 @@ class SingleDisplay extends Device {
|
|
|
149
149
|
const currentResolution = await this.resolution.get();
|
|
150
150
|
|
|
151
151
|
const args: string[] = [];
|
|
152
|
-
if (
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
args.push(`--
|
|
152
|
+
if (
|
|
153
|
+
resolutionInfo.width !== currentResolution.width ||
|
|
154
|
+
resolutionInfo.width !== currentResolution.height
|
|
155
|
+
) {
|
|
156
|
+
args.push(`--resolution=${resolutionInfo.logicalResolutionString()}`);
|
|
157
157
|
}
|
|
158
158
|
if (
|
|
159
159
|
isNotUndefined(resolutionInfo.hiDPI) &&
|
|
@@ -199,26 +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(options?: QuietOption): Promise<Display> {
|
|
204
|
-
return getDisplayWithSelectorArg("--displayWithMainStatus", options);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
static fromName(name: string, options?: QuietOption): Promise<Display> {
|
|
208
|
-
return getDisplayWithSelectorArg(`--name=${name}`, options);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
static async tryFromName(
|
|
212
|
-
name: string,
|
|
213
|
-
options?: QuietOption,
|
|
214
|
-
): Promise<Display | null> {
|
|
215
|
-
try {
|
|
216
|
-
return await getDisplayWithSelectorArg(`--name=${name}`, options);
|
|
217
|
-
} catch {
|
|
218
|
-
// TODO: what is the simplest way to verify this was because there was no such display (as opposed to a general invocation error)?
|
|
219
|
-
return null;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
202
|
}
|
|
223
203
|
|
|
224
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,16 +75,47 @@ 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}`,
|
|
81
|
-
options?:
|
|
112
|
+
options?: GetDeviceOptions,
|
|
82
113
|
): Promise<Display> {
|
|
83
114
|
return (
|
|
84
115
|
await getDeviceInfos<Display>(
|
|
85
116
|
new PrintableShellCommand("betterdisplaycli", [
|
|
86
117
|
"get",
|
|
87
118
|
arg,
|
|
88
|
-
"--type=Display",
|
|
89
119
|
"--identifiers",
|
|
90
120
|
]),
|
|
91
121
|
options,
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
export * from "./Device";
|
|
2
|
-
export {
|
|
2
|
+
export {
|
|
3
|
+
connectAllDisplays,
|
|
4
|
+
getAllDevices,
|
|
5
|
+
getByName,
|
|
6
|
+
getMain,
|
|
7
|
+
tryGetByName,
|
|
8
|
+
} from "./get";
|
|
3
9
|
export { ResolutionInfo, type ResolutionInfoData } from "./ResolutionInfo";
|