betterdisplaycli 0.2.3 → 0.2.4
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 +1 -1
- package/src/Device.ts +128 -35
- package/src/get.ts +15 -0
package/package.json
CHANGED
package/src/Device.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { PrintableShellCommand } from "printable-shell-command";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
type DetachOption,
|
|
4
|
+
print,
|
|
5
|
+
type QuietOption,
|
|
6
|
+
shellOutSilentOrDetach,
|
|
7
|
+
} from "./get";
|
|
3
8
|
import { isNotUndefined, ResolutionInfo } from "./ResolutionInfo";
|
|
4
9
|
|
|
5
10
|
type BOOLEAN_SETTING = "connected" | "hiDPI" | "notch";
|
|
6
11
|
type STRING_SETTING = "resolution";
|
|
12
|
+
type FLOAT_SETTING = "brightness";
|
|
13
|
+
type INTEGER_SETTING = "bit-depth" | "rotation";
|
|
7
14
|
|
|
8
15
|
export type NumberString = string;
|
|
9
16
|
|
|
@@ -76,32 +83,37 @@ class SingleDisplay extends Device {
|
|
|
76
83
|
set: async (
|
|
77
84
|
settingName: BOOLEAN_SETTING,
|
|
78
85
|
on: boolean,
|
|
79
|
-
options?: QuietOption,
|
|
86
|
+
options?: QuietOption & DetachOption,
|
|
80
87
|
): Promise<void> => {
|
|
81
|
-
await
|
|
82
|
-
|
|
83
|
-
"
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
await shellOutSilentOrDetach(
|
|
89
|
+
print(
|
|
90
|
+
new PrintableShellCommand("betterdisplaycli", [
|
|
91
|
+
"set",
|
|
92
|
+
`--name=${this.info.name}`,
|
|
93
|
+
`--${settingName}=${on ? "on" : "off"}`,
|
|
94
|
+
]),
|
|
95
|
+
{ argumentLineWrapping: "inline" },
|
|
96
|
+
options,
|
|
97
|
+
),
|
|
98
|
+
);
|
|
90
99
|
},
|
|
91
100
|
|
|
92
101
|
toggle: async (
|
|
93
102
|
settingName: BOOLEAN_SETTING,
|
|
94
|
-
options?: QuietOption,
|
|
103
|
+
options?: QuietOption & DetachOption,
|
|
95
104
|
): Promise<void> => {
|
|
96
|
-
await
|
|
97
|
-
|
|
98
|
-
"
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
105
|
+
await shellOutSilentOrDetach(
|
|
106
|
+
print(
|
|
107
|
+
new PrintableShellCommand("betterdisplaycli", [
|
|
108
|
+
"toggle",
|
|
109
|
+
`--name=${this.info.name}`,
|
|
110
|
+
`--${settingName}`,
|
|
111
|
+
]),
|
|
112
|
+
{ argumentLineWrapping: "inline" },
|
|
113
|
+
options,
|
|
114
|
+
),
|
|
103
115
|
options,
|
|
104
|
-
)
|
|
116
|
+
);
|
|
105
117
|
},
|
|
106
118
|
};
|
|
107
119
|
|
|
@@ -124,17 +136,91 @@ class SingleDisplay extends Device {
|
|
|
124
136
|
set: async (
|
|
125
137
|
settingName: STRING_SETTING,
|
|
126
138
|
value: string,
|
|
139
|
+
options?: QuietOption & DetachOption,
|
|
140
|
+
): Promise<void> => {
|
|
141
|
+
await shellOutSilentOrDetach(
|
|
142
|
+
print(
|
|
143
|
+
new PrintableShellCommand("betterdisplaycli", [
|
|
144
|
+
"set",
|
|
145
|
+
`--name=${this.info.name}`,
|
|
146
|
+
`--${settingName}=${value}`,
|
|
147
|
+
]),
|
|
148
|
+
{ argumentLineWrapping: "inline" },
|
|
149
|
+
options,
|
|
150
|
+
),
|
|
151
|
+
);
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
float = {
|
|
156
|
+
get: async (
|
|
157
|
+
settingName: FLOAT_SETTING,
|
|
127
158
|
options?: QuietOption,
|
|
159
|
+
): Promise<number> => {
|
|
160
|
+
const value = await print(
|
|
161
|
+
new PrintableShellCommand("betterdisplaycli", [
|
|
162
|
+
"get",
|
|
163
|
+
`--name=${this.info.name}`,
|
|
164
|
+
`--${settingName}`,
|
|
165
|
+
]),
|
|
166
|
+
{ argumentLineWrapping: "inline" },
|
|
167
|
+
options,
|
|
168
|
+
).text({ trimTrailingNewlines: "single-required" });
|
|
169
|
+
return parseFloat(value);
|
|
170
|
+
},
|
|
171
|
+
|
|
172
|
+
set: async (
|
|
173
|
+
settingName: FLOAT_SETTING,
|
|
174
|
+
value: number,
|
|
175
|
+
options?: QuietOption & DetachOption,
|
|
128
176
|
): Promise<void> => {
|
|
129
|
-
await
|
|
177
|
+
await shellOutSilentOrDetach(
|
|
178
|
+
print(
|
|
179
|
+
new PrintableShellCommand("betterdisplaycli", [
|
|
180
|
+
"set",
|
|
181
|
+
`--name=${this.info.name}`,
|
|
182
|
+
`--${settingName}=${value}`,
|
|
183
|
+
]),
|
|
184
|
+
{ argumentLineWrapping: "inline" },
|
|
185
|
+
options,
|
|
186
|
+
),
|
|
187
|
+
);
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
int = {
|
|
192
|
+
get: async (
|
|
193
|
+
settingName: INTEGER_SETTING,
|
|
194
|
+
options?: QuietOption,
|
|
195
|
+
): Promise<number> => {
|
|
196
|
+
const value = await print(
|
|
130
197
|
new PrintableShellCommand("betterdisplaycli", [
|
|
131
|
-
"
|
|
198
|
+
"get",
|
|
132
199
|
`--name=${this.info.name}`,
|
|
133
|
-
`--${settingName}
|
|
200
|
+
`--${settingName}`,
|
|
134
201
|
]),
|
|
135
202
|
{ argumentLineWrapping: "inline" },
|
|
136
203
|
options,
|
|
137
|
-
).
|
|
204
|
+
).text({ trimTrailingNewlines: "single-required" });
|
|
205
|
+
return parseInt(value, 10);
|
|
206
|
+
},
|
|
207
|
+
|
|
208
|
+
set: async (
|
|
209
|
+
settingName: INTEGER_SETTING,
|
|
210
|
+
value: number,
|
|
211
|
+
options?: QuietOption & DetachOption,
|
|
212
|
+
): Promise<void> => {
|
|
213
|
+
await shellOutSilentOrDetach(
|
|
214
|
+
print(
|
|
215
|
+
new PrintableShellCommand("betterdisplaycli", [
|
|
216
|
+
"set",
|
|
217
|
+
`--name=${this.info.name}`,
|
|
218
|
+
`--${settingName}=${value}`,
|
|
219
|
+
]),
|
|
220
|
+
{ argumentLineWrapping: "inline" },
|
|
221
|
+
options,
|
|
222
|
+
),
|
|
223
|
+
);
|
|
138
224
|
},
|
|
139
225
|
};
|
|
140
226
|
|
|
@@ -142,10 +228,15 @@ class SingleDisplay extends Device {
|
|
|
142
228
|
get: async (): Promise<ResolutionInfo> => {
|
|
143
229
|
return ResolutionInfo.fromString(await this.string.get("resolution"));
|
|
144
230
|
},
|
|
145
|
-
|
|
231
|
+
/**
|
|
232
|
+
* The return value indicates if any changes were
|
|
233
|
+
*
|
|
234
|
+
* - needed and
|
|
235
|
+
* - performed successfully (non-detached) or initiated successfully (detached).
|
|
236
|
+
*/
|
|
146
237
|
set: async (
|
|
147
238
|
resolutionInfo: ResolutionInfo,
|
|
148
|
-
options?: QuietOption,
|
|
239
|
+
options?: QuietOption & DetachOption,
|
|
149
240
|
): Promise<boolean> => {
|
|
150
241
|
const currentResolution = await this.resolution.get();
|
|
151
242
|
|
|
@@ -175,15 +266,17 @@ class SingleDisplay extends Device {
|
|
|
175
266
|
return false;
|
|
176
267
|
}
|
|
177
268
|
|
|
178
|
-
await
|
|
179
|
-
|
|
180
|
-
"
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
269
|
+
await shellOutSilentOrDetach(
|
|
270
|
+
print(
|
|
271
|
+
new PrintableShellCommand("betterdisplaycli", [
|
|
272
|
+
"set",
|
|
273
|
+
`--name=${this.info.name}`,
|
|
274
|
+
...args,
|
|
275
|
+
]),
|
|
276
|
+
{ argumentLineWrapping: "inline" },
|
|
277
|
+
options,
|
|
278
|
+
),
|
|
279
|
+
);
|
|
187
280
|
return true;
|
|
188
281
|
},
|
|
189
282
|
};
|
package/src/get.ts
CHANGED
|
@@ -14,6 +14,10 @@ export interface QuietOption {
|
|
|
14
14
|
quiet?: boolean;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
export interface DetachOption {
|
|
18
|
+
detach?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
17
21
|
export function print(
|
|
18
22
|
command: PrintableShellCommand,
|
|
19
23
|
printOptions?: Parameters<PrintableShellCommand["print"]>[0],
|
|
@@ -25,6 +29,17 @@ export function print(
|
|
|
25
29
|
return command;
|
|
26
30
|
}
|
|
27
31
|
|
|
32
|
+
export async function shellOutSilentOrDetach(
|
|
33
|
+
command: PrintableShellCommand,
|
|
34
|
+
options?: DetachOption,
|
|
35
|
+
): Promise<void> {
|
|
36
|
+
if (options?.detach) {
|
|
37
|
+
command.spawnDetached();
|
|
38
|
+
} else {
|
|
39
|
+
await command.shellOut({ print: false });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
28
43
|
type GetDeviceOptions = {
|
|
29
44
|
ignoreDisplayGroups?: true;
|
|
30
45
|
} & QuietOption;
|