betterdisplaycli 0.1.7 → 0.1.9
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 +67 -2
- package/src/get.test.ts +2 -0
- package/src/get.ts +3 -3
package/package.json
CHANGED
package/src/Device.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { PrintableShellCommand } from "printable-shell-command";
|
|
2
|
+
import { print, type QuietOption } from "./get";
|
|
3
|
+
|
|
1
4
|
export type NumberString = string;
|
|
2
5
|
|
|
3
6
|
export interface DeviceInfoCommon {
|
|
@@ -35,13 +38,75 @@ export class Device {
|
|
|
35
38
|
constructor(public readonly info: DeviceInfoCommon) {}
|
|
36
39
|
}
|
|
37
40
|
|
|
38
|
-
|
|
41
|
+
class SingleDisplay extends Device {
|
|
42
|
+
constructor(public override readonly info: DeviceInfoCommon) {
|
|
43
|
+
super(info);
|
|
44
|
+
}
|
|
45
|
+
boolean = {
|
|
46
|
+
get: async (
|
|
47
|
+
settingName: "connected" | "hiDPI",
|
|
48
|
+
options: QuietOption,
|
|
49
|
+
): Promise<boolean> => {
|
|
50
|
+
switch (
|
|
51
|
+
(
|
|
52
|
+
await print(
|
|
53
|
+
new PrintableShellCommand("betterdisplaycli", [
|
|
54
|
+
"get",
|
|
55
|
+
`--name=${this.info.name}`,
|
|
56
|
+
`--${settingName}`,
|
|
57
|
+
]),
|
|
58
|
+
{ argumentLineWrapping: "inline" },
|
|
59
|
+
options,
|
|
60
|
+
).text()
|
|
61
|
+
).trim()
|
|
62
|
+
) {
|
|
63
|
+
case "on": {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
case "off": {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
default:
|
|
70
|
+
throw new Error("Invalid value") as never;
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
set: async (
|
|
75
|
+
setting: "connected" | "hiDPI",
|
|
76
|
+
on: boolean,
|
|
77
|
+
options: QuietOption,
|
|
78
|
+
): Promise<void> => {
|
|
79
|
+
await print(
|
|
80
|
+
new PrintableShellCommand("betterdisplaycli", [
|
|
81
|
+
"set",
|
|
82
|
+
`--name=${this.info.name}`,
|
|
83
|
+
`--${setting}=${on ? "on" : "off"}`,
|
|
84
|
+
]),
|
|
85
|
+
{ argumentLineWrapping: "inline" },
|
|
86
|
+
options,
|
|
87
|
+
).shellOut();
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
toggle: async (
|
|
91
|
+
settingName: "connected" | "hiDPI",
|
|
92
|
+
options: QuietOption,
|
|
93
|
+
): Promise<void> => {
|
|
94
|
+
await this.boolean.set(
|
|
95
|
+
settingName,
|
|
96
|
+
await this.boolean.get(settingName, options),
|
|
97
|
+
options,
|
|
98
|
+
);
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export class Display extends SingleDisplay {
|
|
39
104
|
constructor(public override readonly info: DisplayInfo) {
|
|
40
105
|
super(info);
|
|
41
106
|
}
|
|
42
107
|
}
|
|
43
108
|
|
|
44
|
-
export class VirtualScreen extends
|
|
109
|
+
export class VirtualScreen extends SingleDisplay {
|
|
45
110
|
constructor(public override readonly info: VirtualScreenInfo) {
|
|
46
111
|
super(info);
|
|
47
112
|
}
|
package/src/get.test.ts
CHANGED
package/src/get.ts
CHANGED
|
@@ -7,11 +7,11 @@ import {
|
|
|
7
7
|
type VirtualScreen,
|
|
8
8
|
} from "./Device";
|
|
9
9
|
|
|
10
|
-
interface QuietOption {
|
|
10
|
+
export interface QuietOption {
|
|
11
11
|
quiet?: boolean;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
function print(
|
|
14
|
+
export function print(
|
|
15
15
|
command: PrintableShellCommand,
|
|
16
16
|
printOptions?: Parameters<PrintableShellCommand["print"]>[0],
|
|
17
17
|
quietOptions?: QuietOption,
|
|
@@ -50,7 +50,7 @@ export async function getAllDevices(
|
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
export async function connectAllDisplays(options
|
|
53
|
+
export async function connectAllDisplays(options?: QuietOption): Promise<void> {
|
|
54
54
|
await print(
|
|
55
55
|
new PrintableShellCommand("betterdisplaycli", [
|
|
56
56
|
["perform", "--connectAllDisplays"],
|