@domicile-desktop/system-backlight 0.0.0-placeholder → 1.0.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/LICENSE +21 -0
- package/README.md +69 -0
- package/dist/auto-brightness-curve.d.ts +7 -0
- package/dist/auto-brightness-curve.js +16 -0
- package/dist/auto-brightness.d.ts +17 -0
- package/dist/auto-brightness.js +77 -0
- package/dist/every.d.ts +4 -0
- package/dist/every.js +7 -0
- package/dist/fixture.d.ts +11 -0
- package/dist/fixture.js +108 -0
- package/dist/host-ambient-light.d.ts +10 -0
- package/dist/host-ambient-light.js +35 -0
- package/dist/host-backlight.d.ts +14 -0
- package/dist/host-backlight.js +42 -0
- package/dist/learned-offset.d.ts +12 -0
- package/dist/learned-offset.js +36 -0
- package/dist/raw-for.d.ts +8 -0
- package/dist/raw-for.js +14 -0
- package/dist/react.d.ts +19 -0
- package/dist/react.js +30 -0
- package/dist/read-backlight.d.ts +24 -0
- package/dist/read-backlight.js +64 -0
- package/dist/set-brightness.d.ts +29 -0
- package/dist/set-brightness.js +76 -0
- package/dist/shared-backlight.d.ts +19 -0
- package/dist/shared-backlight.js +25 -0
- package/dist/watch-ambient-light.d.ts +16 -0
- package/dist/watch-ambient-light.js +136 -0
- package/dist/watch-brightness.d.ts +30 -0
- package/dist/watch-brightness.js +164 -0
- package/package.json +89 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Connor Prussin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# @domicile-desktop/system-backlight
|
|
2
|
+
|
|
3
|
+
Screen brightness for a Domicile shell, on the `files`, `processes` and `dbus`
|
|
4
|
+
namespaces of the [`Domicile`](/packages/chrome-sdk/src/desktop/desktop.ts) a
|
|
5
|
+
shell is handed. See
|
|
6
|
+
[SHELL-SYSTEM-ACCESS.md](/docs/SHELL-SYSTEM-ACCESS.md).
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { brightnessSetter } from "@domicile-desktop/system-backlight/set-brightness";
|
|
12
|
+
import { watchBrightness } from "@domicile-desktop/system-backlight/watch-brightness";
|
|
13
|
+
|
|
14
|
+
const watch = await watchBrightness(domicile, (level) => show(level));
|
|
15
|
+
const set = brightnessSetter(domicile);
|
|
16
|
+
await set(0.5);
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
- `readBacklight` (`./read-backlight`): the preferred device under
|
|
20
|
+
`/sys/class/backlight`: firmware, then platform, then raw, in systemd's
|
|
21
|
+
order; ties by name. `None` without one.
|
|
22
|
+
- `watchBrightness`: the level (0 to 1) now and on each change of a whole
|
|
23
|
+
percent. Re-reads on each `udevadm monitor` uevent and every two minutes.
|
|
24
|
+
- `brightnessSetter`: sets a level through logind's
|
|
25
|
+
`org.freedesktop.login1.Session.SetBrightness`. Never sets zero, which turns
|
|
26
|
+
most panels off. Sends one level at a time; a level superseded while waiting
|
|
27
|
+
resolves `SetOutcome.Superseded`.
|
|
28
|
+
- `watchAmbientLight` (`./watch-ambient-light`): the room's light in lux, now
|
|
29
|
+
and on each change, from iio-sensor-proxy (`net.hadess.SensorProxy`).
|
|
30
|
+
Claims the sensor until `stop`, and again after a compositor restart. `None`
|
|
31
|
+
without a sensor or without iio-sensor-proxy.
|
|
32
|
+
- Every call resolves a `Result<…, SystemError>`. A level that is not a number
|
|
33
|
+
throws.
|
|
34
|
+
|
|
35
|
+
## Automatic brightness
|
|
36
|
+
|
|
37
|
+
- `./auto-brightness`: `runAutoBrightness(backlight, light)` follows the
|
|
38
|
+
room's light until stopped, as macOS does. No React. The curve
|
|
39
|
+
(`./auto-brightness-curve`) and the user's learned offset
|
|
40
|
+
(`./learned-offset`, in `localStorage`) are beside it. See the
|
|
41
|
+
[brightness module](../manganese-bar-module-brightness/README.md#automatic-brightness-and-night-light)
|
|
42
|
+
for the rules.
|
|
43
|
+
- `./host-ambient-light`: the ambient light sensor as callbacks.
|
|
44
|
+
- `./host-backlight` and `./shared-backlight`: the level as callbacks, and
|
|
45
|
+
shared among readers so a level the user chose wins over an automatic one.
|
|
46
|
+
|
|
47
|
+
## React
|
|
48
|
+
|
|
49
|
+
`./react`, for a shell on [`@domicile-desktop/react`](../react/README.md):
|
|
50
|
+
|
|
51
|
+
- `useBacklightLevel()`, `useHasBacklight()`: `undefined` until read.
|
|
52
|
+
- `useAutoBrightness(domicile, enabled)`: runs automatic brightness while
|
|
53
|
+
mounted and enabled. Mount it once, on the desktop's page.
|
|
54
|
+
- `deskBacklight(domicile)`, `deskBacklightHardware(domicile)`: the shared
|
|
55
|
+
watches, one per desktop.
|
|
56
|
+
|
|
57
|
+
## Requirements
|
|
58
|
+
|
|
59
|
+
- `udevadm` on the compositor's `PATH` (systemd).
|
|
60
|
+
- A logind session.
|
|
61
|
+
- For ambient light, iio-sensor-proxy (`hardware.sensor.iio.enable` on
|
|
62
|
+
NixOS).
|
|
63
|
+
- Watching and setting work while the desktop is locked, so a lock screen can
|
|
64
|
+
adjust the brightness ([LOCK.md](/docs/LOCK.md)).
|
|
65
|
+
|
|
66
|
+
## Testing
|
|
67
|
+
|
|
68
|
+
`bun run turbo test --filter @domicile-desktop/system-backlight`. Tests answer
|
|
69
|
+
the system calls from files recorded on a ThinkPad (`src/fake-system.ts`).
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The level, 0 to 1, for `lux` of light, moved by `offset`: dim in the dark,
|
|
3
|
+
* about half at 100 lux, full in daylight.
|
|
4
|
+
*/
|
|
5
|
+
export declare const brightnessFor: (lux: number, offset: number) => number;
|
|
6
|
+
/** The offset that makes {@link brightnessFor} give `level` at `lux`. */
|
|
7
|
+
export declare const offsetFor: (lux: number, level: number) => number;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// The brightness automatic brightness asks for in a room's light, and how a
|
|
2
|
+
// level the user chose moves it.
|
|
3
|
+
/** The level in the dark, with nothing learned. */
|
|
4
|
+
const IN_THE_DARK = 0.1;
|
|
5
|
+
/** How much each tenfold of light adds. 10,000 lux, daylight, is full. */
|
|
6
|
+
const PER_DECADE = 0.225;
|
|
7
|
+
/** The dimmest level asked for; zero turns most panels off. */
|
|
8
|
+
const DIMMEST = 0.01;
|
|
9
|
+
/**
|
|
10
|
+
* The level, 0 to 1, for `lux` of light, moved by `offset`: dim in the dark,
|
|
11
|
+
* about half at 100 lux, full in daylight.
|
|
12
|
+
*/
|
|
13
|
+
export const brightnessFor = (lux, offset) => Math.min(1, Math.max(DIMMEST, curve(lux) + offset));
|
|
14
|
+
/** The offset that makes {@link brightnessFor} give `level` at `lux`. */
|
|
15
|
+
export const offsetFor = (lux, level) => level - curve(lux);
|
|
16
|
+
const curve = (lux) => IN_THE_DARK + PER_DECADE * Math.log10(1 + Math.max(0, lux));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Every } from "./every";
|
|
2
|
+
import type { AmbientLight } from "./host-ambient-light";
|
|
3
|
+
import type { SharedBacklight } from "./shared-backlight";
|
|
4
|
+
/** What {@link runAutoBrightness} stores the learned offset with. */
|
|
5
|
+
export type OffsetStore = {
|
|
6
|
+
learned: () => number;
|
|
7
|
+
learn: (offset: number) => void;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Follows the room's light with the backlight until the returned function
|
|
11
|
+
* stops it, as macOS does: the level eases toward the curve's, and a level the
|
|
12
|
+
* user chose moves the curve, so the next room keeps their preference.
|
|
13
|
+
*
|
|
14
|
+
* Small changes in the light are ignored, so the screen does not flicker with
|
|
15
|
+
* the sensor's noise. Does nothing without a sensor or a backlight.
|
|
16
|
+
*/
|
|
17
|
+
export declare const runAutoBrightness: (backlight: SharedBacklight, light: AmbientLight, every?: Every, store?: OffsetStore) => (() => void);
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { brightnessFor, offsetFor } from "./auto-brightness-curve";
|
|
2
|
+
import { everyInterval } from "./every";
|
|
3
|
+
import { learnedOffset, learnOffset } from "./learned-offset";
|
|
4
|
+
/** The most one step of a ramp moves the level. */
|
|
5
|
+
const STEP = 0.01;
|
|
6
|
+
/** How often a ramp steps: from dark to full in about ten seconds. */
|
|
7
|
+
const STEP_MS = 100;
|
|
8
|
+
/** How far the room's level must move from the screen's before it follows. */
|
|
9
|
+
const HYSTERESIS = 0.03;
|
|
10
|
+
const localOffset = {
|
|
11
|
+
learn: learnOffset,
|
|
12
|
+
learned: learnedOffset,
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Follows the room's light with the backlight until the returned function
|
|
16
|
+
* stops it, as macOS does: the level eases toward the curve's, and a level the
|
|
17
|
+
* user chose moves the curve, so the next room keeps their preference.
|
|
18
|
+
*
|
|
19
|
+
* Small changes in the light are ignored, so the screen does not flicker with
|
|
20
|
+
* the sensor's noise. Does nothing without a sensor or a backlight.
|
|
21
|
+
*/
|
|
22
|
+
export const runAutoBrightness = (backlight, light, every = everyInterval, store = localOffset) => {
|
|
23
|
+
const state = {
|
|
24
|
+
lux: undefined,
|
|
25
|
+
offset: store.learned(),
|
|
26
|
+
position: undefined,
|
|
27
|
+
stopRamp: undefined,
|
|
28
|
+
};
|
|
29
|
+
const stopRamp = () => {
|
|
30
|
+
state.stopRamp?.();
|
|
31
|
+
state.stopRamp = undefined;
|
|
32
|
+
};
|
|
33
|
+
const aim = () => {
|
|
34
|
+
const from = state.position ?? backlight.level.current();
|
|
35
|
+
if (state.lux !== undefined && from !== undefined) {
|
|
36
|
+
const target = brightnessFor(state.lux, state.offset);
|
|
37
|
+
if (Math.abs(target - from) >= HYSTERESIS) {
|
|
38
|
+
stopRamp();
|
|
39
|
+
state.position = from;
|
|
40
|
+
state.stopRamp = every(STEP_MS, () => {
|
|
41
|
+
const at = state.position ?? from;
|
|
42
|
+
const next = Math.abs(target - at) <= STEP
|
|
43
|
+
? target
|
|
44
|
+
: at + Math.sign(target - at) * STEP;
|
|
45
|
+
state.position = next;
|
|
46
|
+
backlight.adjust(next);
|
|
47
|
+
if (next === target) {
|
|
48
|
+
stopRamp();
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const stopLevel = backlight.level.subscribe(() => {
|
|
55
|
+
if (state.position === undefined) {
|
|
56
|
+
aim();
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
const stopChosen = backlight.chosen((level) => {
|
|
60
|
+
stopRamp();
|
|
61
|
+
state.position = level;
|
|
62
|
+
if (state.lux !== undefined) {
|
|
63
|
+
state.offset = offsetFor(state.lux, level);
|
|
64
|
+
store.learn(state.offset);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
const stopLight = light((lux) => {
|
|
68
|
+
state.lux = lux;
|
|
69
|
+
aim();
|
|
70
|
+
});
|
|
71
|
+
return () => {
|
|
72
|
+
stopRamp();
|
|
73
|
+
stopLight();
|
|
74
|
+
stopChosen();
|
|
75
|
+
stopLevel();
|
|
76
|
+
};
|
|
77
|
+
};
|
package/dist/every.d.ts
ADDED
package/dist/every.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FakeDomicileHost } from "@domicile-desktop/sdk/fake-host";
|
|
2
|
+
/** A ThinkPad's `/sys/class/backlight`, recorded, at 9 of 15. */
|
|
3
|
+
export declare const THINKPAD_BACKLIGHT: Readonly<Record<string, string>>;
|
|
4
|
+
/**
|
|
5
|
+
* Answers the backlight's system calls `fake` makes, and those that follow,
|
|
6
|
+
* until the shell asks nothing more. `files` maps a path to its contents; a
|
|
7
|
+
* directory lists the files under it. Processes start and print nothing, and
|
|
8
|
+
* logind's `SetBrightness` returns nothing. Other calls, such as the
|
|
9
|
+
* battery's, stay unanswered.
|
|
10
|
+
*/
|
|
11
|
+
export declare const answerSystemCalls: (fake: FakeDomicileHost, files: Readonly<Record<string, string>>, answered?: number) => Promise<void>;
|
package/dist/fixture.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// A machine for tests that answers the shell's system calls on a
|
|
2
|
+
// `FakeDomicileHost` from fixed files, as the compositor would.
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
/** A ThinkPad's `/sys/class/backlight`, recorded, at 9 of 15. */
|
|
5
|
+
export const THINKPAD_BACKLIGHT = {
|
|
6
|
+
"/sys/class/backlight/acpi_video0/brightness": "9\n",
|
|
7
|
+
"/sys/class/backlight/acpi_video0/max_brightness": "15\n",
|
|
8
|
+
"/sys/class/backlight/acpi_video0/type": "firmware\n",
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Answers the backlight's system calls `fake` makes, and those that follow,
|
|
12
|
+
* until the shell asks nothing more. `files` maps a path to its contents; a
|
|
13
|
+
* directory lists the files under it. Processes start and print nothing, and
|
|
14
|
+
* logind's `SetBrightness` returns nothing. Other calls, such as the
|
|
15
|
+
* battery's, stay unanswered.
|
|
16
|
+
*/
|
|
17
|
+
export const answerSystemCalls = async (fake, files, answered = 0) => {
|
|
18
|
+
const calls = fake.calls.filter(([method]) => method === "callSystem");
|
|
19
|
+
if (calls.length > answered) {
|
|
20
|
+
for (const [, id, request] of calls.slice(answered)) {
|
|
21
|
+
answer(fake, files, z.number().parse(id), z.string().parse(request));
|
|
22
|
+
}
|
|
23
|
+
await new Promise((settled) => setTimeout(settled, 0));
|
|
24
|
+
await answerSystemCalls(fake, files, calls.length);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const answer = (fake, files, id, request) => {
|
|
28
|
+
const parsed = requestSchema.safeParse(JSON.parse(request));
|
|
29
|
+
if (parsed.success) {
|
|
30
|
+
answerOne(fake, files, id, parsed.data);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const answerOne = (fake, files, id, asked) => {
|
|
34
|
+
const say = (message) => {
|
|
35
|
+
fake.dispatch("system", { data: JSON.stringify({ id, ...message }) });
|
|
36
|
+
};
|
|
37
|
+
switch (asked.call) {
|
|
38
|
+
case "read_dir": {
|
|
39
|
+
say({
|
|
40
|
+
reply: {
|
|
41
|
+
entries: Object.keys(files)
|
|
42
|
+
.filter((path) => path.startsWith(`${asked.path}/`))
|
|
43
|
+
.map((path) => path.slice(asked.path.length + 1).split("/")[0])
|
|
44
|
+
.filter((name, index, names) => names.indexOf(name) === index)
|
|
45
|
+
.map((name) => ({ file_type: "symlink", name })),
|
|
46
|
+
kind: "entries",
|
|
47
|
+
},
|
|
48
|
+
type: "system_reply",
|
|
49
|
+
});
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
case "read_file": {
|
|
53
|
+
const contents = files[asked.path];
|
|
54
|
+
say({
|
|
55
|
+
reply: contents === undefined
|
|
56
|
+
? {
|
|
57
|
+
error: { kind: "not_found", message: asked.path },
|
|
58
|
+
kind: "failed",
|
|
59
|
+
}
|
|
60
|
+
: { data: btoa(contents), kind: "read" },
|
|
61
|
+
type: "system_reply",
|
|
62
|
+
});
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
case "spawn": {
|
|
66
|
+
say({ reply: { kind: "started" }, type: "system_reply" });
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
case "kill": {
|
|
70
|
+
say({
|
|
71
|
+
end: { code: null, kind: "exited", signal: 15 },
|
|
72
|
+
type: "system_end",
|
|
73
|
+
});
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
case "dbus_call": {
|
|
77
|
+
say({
|
|
78
|
+
reply: { body: "[]", kind: "returned", signature: "" },
|
|
79
|
+
type: "system_reply",
|
|
80
|
+
});
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const UNDER_BACKLIGHT = /^\/sys\/class\/backlight(\/|$)/;
|
|
86
|
+
const requestSchema = z.discriminatedUnion("call", [
|
|
87
|
+
z.object({
|
|
88
|
+
call: z.literal("read_dir"),
|
|
89
|
+
path: z.string().regex(UNDER_BACKLIGHT),
|
|
90
|
+
}),
|
|
91
|
+
z.object({
|
|
92
|
+
call: z.literal("read_file"),
|
|
93
|
+
path: z.string().regex(UNDER_BACKLIGHT),
|
|
94
|
+
}),
|
|
95
|
+
z
|
|
96
|
+
.object({
|
|
97
|
+
argv: z.tuple([z.literal("udevadm")]).rest(z.string()),
|
|
98
|
+
call: z.literal("spawn"),
|
|
99
|
+
})
|
|
100
|
+
.loose(),
|
|
101
|
+
z.object({ call: z.literal("kill") }).loose(),
|
|
102
|
+
z
|
|
103
|
+
.object({
|
|
104
|
+
call: z.literal("dbus_call"),
|
|
105
|
+
member: z.literal("SetBrightness"),
|
|
106
|
+
})
|
|
107
|
+
.loose(),
|
|
108
|
+
]);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Domicile } from "@domicile-desktop/sdk/desktop/desktop";
|
|
2
|
+
import { watchAmbientLight } from "./watch-ambient-light";
|
|
3
|
+
/**
|
|
4
|
+
* Calls `onLux` with the room's light now and after each change, and returns
|
|
5
|
+
* what stops it. Never called on a machine without a sensor. Failures are
|
|
6
|
+
* logged.
|
|
7
|
+
*/
|
|
8
|
+
export type AmbientLight = (onLux: (lux: number) => void) => () => void;
|
|
9
|
+
/** The ambient light sensor through `domicile`'s D-Bus. */
|
|
10
|
+
export declare const hostAmbientLight: (domicile: Domicile, watch?: typeof watchAmbientLight) => AmbientLight;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { watchAmbientLight } from "./watch-ambient-light";
|
|
2
|
+
/** The ambient light sensor through `domicile`'s D-Bus. */
|
|
3
|
+
export const hostAmbientLight = (domicile, watch = watchAmbientLight) => (onLux) => {
|
|
4
|
+
const started = watch(domicile).then((result) => result.match({
|
|
5
|
+
Err: (error) => {
|
|
6
|
+
logFailure(error);
|
|
7
|
+
return undefined;
|
|
8
|
+
},
|
|
9
|
+
Ok: (found) => found.match({
|
|
10
|
+
None: () => undefined,
|
|
11
|
+
Some: (light) => {
|
|
12
|
+
readEach(light.items.getReader(), onLux).catch(logFailure);
|
|
13
|
+
return light;
|
|
14
|
+
},
|
|
15
|
+
}),
|
|
16
|
+
}));
|
|
17
|
+
return () => {
|
|
18
|
+
started
|
|
19
|
+
.then((light) => {
|
|
20
|
+
light?.stop();
|
|
21
|
+
})
|
|
22
|
+
.catch(logFailure);
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
const readEach = async (reader, onLux) => {
|
|
26
|
+
const read = await reader.read();
|
|
27
|
+
if (!read.done) {
|
|
28
|
+
onLux(read.value);
|
|
29
|
+
await readEach(reader, onLux);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const logFailure = (error) => {
|
|
33
|
+
// biome-ignore lint/suspicious/noConsole: the desk has nowhere else to say it
|
|
34
|
+
console.error("could not read the ambient light sensor", error);
|
|
35
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Domicile } from "@domicile-desktop/sdk/desktop/desktop";
|
|
2
|
+
/** The backlight as the bar's brightness item uses it. */
|
|
3
|
+
export type Backlight = {
|
|
4
|
+
/**
|
|
5
|
+
* Calls `onLevel` with the level (0 to 1) now and after each change, and
|
|
6
|
+
* returns a function that stops watching. Never called on a machine without
|
|
7
|
+
* a backlight.
|
|
8
|
+
*/
|
|
9
|
+
watch: (onLevel: (level: number) => void) => () => void;
|
|
10
|
+
/** Ask for a level from 0 to 1. The watch reports it once it is set. */
|
|
11
|
+
set: (level: number) => void;
|
|
12
|
+
};
|
|
13
|
+
/** The backlight through `domicile`'s system calls. Failures are logged. */
|
|
14
|
+
export declare const hostBacklight: (domicile: Domicile) => Backlight;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { brightnessSetter } from "./set-brightness";
|
|
2
|
+
import { watchBrightness } from "./watch-brightness";
|
|
3
|
+
/** The backlight through `domicile`'s system calls. Failures are logged. */
|
|
4
|
+
export const hostBacklight = (domicile) => {
|
|
5
|
+
const set = brightnessSetter(domicile);
|
|
6
|
+
return {
|
|
7
|
+
set: (level) => {
|
|
8
|
+
set(level)
|
|
9
|
+
.then((result) => {
|
|
10
|
+
result.match({ Err: logFailure("set"), Ok: () => undefined });
|
|
11
|
+
})
|
|
12
|
+
.catch(logFailure("set"));
|
|
13
|
+
},
|
|
14
|
+
watch: (onLevel) => {
|
|
15
|
+
const started = watchBrightness(domicile, onLevel).then((result) => result.match({
|
|
16
|
+
Err: (error) => {
|
|
17
|
+
logFailure("watch")(error);
|
|
18
|
+
return undefined;
|
|
19
|
+
},
|
|
20
|
+
Ok: (watch) => {
|
|
21
|
+
watch.ended
|
|
22
|
+
.then((ended) => {
|
|
23
|
+
ended.match({ Err: logFailure("watch"), Ok: () => undefined });
|
|
24
|
+
})
|
|
25
|
+
.catch(logFailure("watch"));
|
|
26
|
+
return watch;
|
|
27
|
+
},
|
|
28
|
+
}));
|
|
29
|
+
return () => {
|
|
30
|
+
started
|
|
31
|
+
.then((watch) => {
|
|
32
|
+
watch?.stop();
|
|
33
|
+
})
|
|
34
|
+
.catch(logFailure("watch"));
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
const logFailure = (doing) => (error) => {
|
|
40
|
+
// biome-ignore lint/suspicious/noConsole: the bar has nowhere else to say it
|
|
41
|
+
console.error(`could not ${doing} the brightness`, error);
|
|
42
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** The storage key, versioned per the persisted-state rule. */
|
|
2
|
+
export declare const OFFSET_KEY = "auto-brightness:v1";
|
|
3
|
+
/**
|
|
4
|
+
* The stored offset, or none (0) if nothing is stored.
|
|
5
|
+
*
|
|
6
|
+
* Parsed rather than cast: an unreadable value counts as nothing learned.
|
|
7
|
+
*/
|
|
8
|
+
export declare const learnedOffset: (storage?: Pick<Storage, "getItem">) => number;
|
|
9
|
+
/** Store `offset` for other pages and future loads. */
|
|
10
|
+
export declare const learnOffset: (offset: number, storage?: Pick<Storage, "setItem">) => void;
|
|
11
|
+
/** `stored` as an offset, or 0 if it is not one. */
|
|
12
|
+
export declare const parseOffset: (stored: string) => number;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// How far the user moved automatic brightness from its curve, stored locally
|
|
3
|
+
// so the desk keeps it across restarts. Every page of the desktop shares one
|
|
4
|
+
// origin, so they read the same offset.
|
|
5
|
+
/** The storage key, versioned per the persisted-state rule. */
|
|
6
|
+
export const OFFSET_KEY = "auto-brightness:v1";
|
|
7
|
+
const offsetSchema = z.object({ offset: z.number().min(-1).max(1) });
|
|
8
|
+
/**
|
|
9
|
+
* The stored offset, or none (0) if nothing is stored.
|
|
10
|
+
*
|
|
11
|
+
* Parsed rather than cast: an unreadable value counts as nothing learned.
|
|
12
|
+
*/
|
|
13
|
+
export const learnedOffset = (storage = globalThis.localStorage) => {
|
|
14
|
+
const stored = storage.getItem(OFFSET_KEY);
|
|
15
|
+
return stored === null ? 0 : parseOffset(stored);
|
|
16
|
+
};
|
|
17
|
+
/** Store `offset` for other pages and future loads. */
|
|
18
|
+
export const learnOffset = (offset, storage = globalThis.localStorage) => {
|
|
19
|
+
storage.setItem(OFFSET_KEY, JSON.stringify({ offset }));
|
|
20
|
+
};
|
|
21
|
+
/** `stored` as an offset, or 0 if it is not one. */
|
|
22
|
+
export const parseOffset = (stored) => storedOffsetSchema.safeParse(stored).data?.offset ?? 0;
|
|
23
|
+
// Invalid JSON is a parse issue, not a throw, so it is handled like any other
|
|
24
|
+
// invalid value.
|
|
25
|
+
const storedOffsetSchema = z
|
|
26
|
+
.string()
|
|
27
|
+
.transform((text, context) => {
|
|
28
|
+
try {
|
|
29
|
+
return JSON.parse(text);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
context.addIssue({ code: "custom", message: "not JSON" });
|
|
33
|
+
return z.NEVER;
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
.pipe(offsetSchema);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Backlight } from "./read-backlight";
|
|
2
|
+
/**
|
|
3
|
+
* The raw value for `level`, clamped to 0..1 and rounded.
|
|
4
|
+
*
|
|
5
|
+
* Never zero: most panels turn off at zero, leaving no visible slider to raise
|
|
6
|
+
* it again. Throws on a level that is not finite, which is a caller's bug.
|
|
7
|
+
*/
|
|
8
|
+
export declare const rawFor: ({ max }: Backlight, level: number) => number;
|
package/dist/raw-for.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The raw value for `level`, clamped to 0..1 and rounded.
|
|
3
|
+
*
|
|
4
|
+
* Never zero: most panels turn off at zero, leaving no visible slider to raise
|
|
5
|
+
* it again. Throws on a level that is not finite, which is a caller's bug.
|
|
6
|
+
*/
|
|
7
|
+
export const rawFor = ({ max }, level) => {
|
|
8
|
+
if (Number.isFinite(level)) {
|
|
9
|
+
return Math.max(1, Math.round(Math.min(1, Math.max(0, level)) * max));
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
throw new Error(`a brightness must be a number, not ${level}`);
|
|
13
|
+
}
|
|
14
|
+
};
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Result } from "@cprussin/option-result";
|
|
2
|
+
import type { SharedWatch } from "@domicile-desktop/react/shared-watch";
|
|
3
|
+
import type { Domicile } from "@domicile-desktop/sdk/desktop/desktop";
|
|
4
|
+
import type { SystemError } from "@domicile-desktop/sdk/system";
|
|
5
|
+
import type { AmbientLight } from "./host-ambient-light";
|
|
6
|
+
import type { SharedBacklight } from "./shared-backlight";
|
|
7
|
+
/** The backlight, watched once per desktop. */
|
|
8
|
+
export declare const deskBacklight: (domicile: Domicile) => SharedBacklight;
|
|
9
|
+
/** Whether the machine has a backlight, looked for once per desktop. */
|
|
10
|
+
export declare const deskBacklightHardware: (domicile: Domicile) => SharedWatch<Result<boolean, SystemError>>;
|
|
11
|
+
/** The backlight's level, 0 to 1, or `undefined` before it is read. */
|
|
12
|
+
export declare const useBacklightLevel: () => number | undefined;
|
|
13
|
+
/** Whether the machine has a backlight, or `undefined` before it was looked for. */
|
|
14
|
+
export declare const useHasBacklight: () => Result<boolean, SystemError> | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Automatic brightness for the desk while mounted and `enabled`. See
|
|
17
|
+
* {@link runAutoBrightness}. Mount it once, on the desktop's page.
|
|
18
|
+
*/
|
|
19
|
+
export declare const useAutoBrightness: (domicile: Domicile, enabled: boolean, light?: AmbientLight) => void;
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// The backlight for a React shell: one watch per desktop, however many parts
|
|
2
|
+
// read it, and automatic brightness.
|
|
3
|
+
import { perDesktop } from "@domicile-desktop/react/per-desktop";
|
|
4
|
+
import { sharedWatch } from "@domicile-desktop/react/shared-watch";
|
|
5
|
+
import { useDeskWatch } from "@domicile-desktop/react/use-shared-watch";
|
|
6
|
+
import { watchPresence } from "@domicile-desktop/react/watch-presence";
|
|
7
|
+
import { useEffect } from "react";
|
|
8
|
+
import { runAutoBrightness } from "./auto-brightness";
|
|
9
|
+
import { hostAmbientLight } from "./host-ambient-light";
|
|
10
|
+
import { hostBacklight } from "./host-backlight";
|
|
11
|
+
import { readBacklight } from "./read-backlight";
|
|
12
|
+
import { sharedBacklight } from "./shared-backlight";
|
|
13
|
+
/** The backlight, watched once per desktop. */
|
|
14
|
+
export const deskBacklight = perDesktop((domicile) => sharedBacklight(hostBacklight(domicile)));
|
|
15
|
+
/** Whether the machine has a backlight, looked for once per desktop. */
|
|
16
|
+
export const deskBacklightHardware = perDesktop((domicile) => sharedWatch((onPresent) => watchPresence(async () => (await readBacklight(domicile)).map((found) => found.isSome()), onPresent)));
|
|
17
|
+
/** The backlight's level, 0 to 1, or `undefined` before it is read. */
|
|
18
|
+
export const useBacklightLevel = () => useDeskWatch((domicile) => deskBacklight(domicile).level);
|
|
19
|
+
/** Whether the machine has a backlight, or `undefined` before it was looked for. */
|
|
20
|
+
export const useHasBacklight = () => useDeskWatch(deskBacklightHardware);
|
|
21
|
+
/**
|
|
22
|
+
* Automatic brightness for the desk while mounted and `enabled`. See
|
|
23
|
+
* {@link runAutoBrightness}. Mount it once, on the desktop's page.
|
|
24
|
+
*/
|
|
25
|
+
export const useAutoBrightness = (domicile, enabled, light) => {
|
|
26
|
+
const backlight = deskBacklight(domicile);
|
|
27
|
+
useEffect(() => enabled
|
|
28
|
+
? runAutoBrightness(backlight, light ?? hostAmbientLight(domicile))
|
|
29
|
+
: undefined, [backlight, domicile, enabled, light]);
|
|
30
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Option, Result } from "@cprussin/option-result";
|
|
2
|
+
import type { Files } from "@domicile-desktop/sdk/desktop/files";
|
|
3
|
+
import type { SystemError } from "@domicile-desktop/sdk/system";
|
|
4
|
+
/** The calls {@link readBacklight} makes. */
|
|
5
|
+
export type SysfsHost = {
|
|
6
|
+
readonly files: Pick<Files, "readDir" | "readText">;
|
|
7
|
+
};
|
|
8
|
+
/** One backlight device's current and maximum raw brightness. */
|
|
9
|
+
export type Backlight = {
|
|
10
|
+
/** The name under `/sys/class/backlight`, which logind takes. */
|
|
11
|
+
device: string;
|
|
12
|
+
raw: number;
|
|
13
|
+
max: number;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The backlight to show and set, or `None` if there is none.
|
|
17
|
+
*
|
|
18
|
+
* Picks the preferred type, breaking ties by name so the choice is stable.
|
|
19
|
+
* Skips a device whose files are missing or not numbers, or whose maximum is
|
|
20
|
+
* zero.
|
|
21
|
+
*/
|
|
22
|
+
export declare const readBacklight: (host: SysfsHost) => Promise<Result<Option<Backlight>, SystemError>>;
|
|
23
|
+
/** Brightness from 0 to 1. */
|
|
24
|
+
export declare const levelOf: ({ max, raw }: Backlight) => number;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Reads the screen's backlight from `/sys/class/backlight`.
|
|
2
|
+
import { Err, None, Ok, Some } from "@cprussin/option-result";
|
|
3
|
+
import { SystemErrorKind } from "@domicile-desktop/sdk/system";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
/** Sysfs directory listing every backlight. */
|
|
6
|
+
const BACKLIGHT = "/sys/class/backlight";
|
|
7
|
+
/**
|
|
8
|
+
* Backlight types, preferred first, in systemd's order. A firmware interface
|
|
9
|
+
* knows the panel's curve; a raw one drives the same panel without it.
|
|
10
|
+
*/
|
|
11
|
+
const KINDS = ["firmware", "platform", "raw"];
|
|
12
|
+
/** The files read from each device, in the order `readOne` takes them. */
|
|
13
|
+
const FILES = ["type", "max_brightness", "brightness"];
|
|
14
|
+
/**
|
|
15
|
+
* The backlight to show and set, or `None` if there is none.
|
|
16
|
+
*
|
|
17
|
+
* Picks the preferred type, breaking ties by name so the choice is stable.
|
|
18
|
+
* Skips a device whose files are missing or not numbers, or whose maximum is
|
|
19
|
+
* zero.
|
|
20
|
+
*/
|
|
21
|
+
export const readBacklight = async (host) => (await host.files.readDir(BACKLIGHT)).match({
|
|
22
|
+
Err: async (error) => error.kind === SystemErrorKind.NotFound ? Ok(None()) : Err(error),
|
|
23
|
+
Ok: async (entries) => collected(await Promise.all(entries
|
|
24
|
+
.map(({ name }) => name)
|
|
25
|
+
.toSorted()
|
|
26
|
+
.map((device) => readOne(host, device)))).map((devices) => firstSome(KINDS.map((kind) => firstSome(devices.map((device) => device.andThen((read) => read.kind === kind ? Some(read.backlight) : None())))))),
|
|
27
|
+
});
|
|
28
|
+
/** Brightness from 0 to 1. */
|
|
29
|
+
export const levelOf = ({ max, raw }) => raw / max;
|
|
30
|
+
const readOne = async (host, device) => collected(await Promise.all(FILES.map((file) => readFile(host, device, file)))).map(([kind, max, raw]) => {
|
|
31
|
+
const parsed = deviceSchema.safeParse({
|
|
32
|
+
kind: present(kind),
|
|
33
|
+
max: present(max),
|
|
34
|
+
raw: present(raw),
|
|
35
|
+
});
|
|
36
|
+
return parsed.success
|
|
37
|
+
? Some({
|
|
38
|
+
backlight: {
|
|
39
|
+
device,
|
|
40
|
+
max: parsed.data.max,
|
|
41
|
+
raw: Math.min(parsed.data.raw, parsed.data.max),
|
|
42
|
+
},
|
|
43
|
+
kind: parsed.data.kind,
|
|
44
|
+
})
|
|
45
|
+
: None();
|
|
46
|
+
});
|
|
47
|
+
/** A file of `device`, trimmed, or `None` if it is missing. */
|
|
48
|
+
const readFile = async (host, device, file) => (await host.files.readText(`${BACKLIGHT}/${device}/${file}`)).match({
|
|
49
|
+
Err: (error) => error.kind === SystemErrorKind.NotFound ? Ok(None()) : Err(error),
|
|
50
|
+
Ok: (text) => Ok(Some(text.trim())),
|
|
51
|
+
});
|
|
52
|
+
const count = z
|
|
53
|
+
.string()
|
|
54
|
+
.regex(/^\d+$/)
|
|
55
|
+
.transform((digits) => Number.parseInt(digits, 10));
|
|
56
|
+
const deviceSchema = z.object({
|
|
57
|
+
kind: z.enum(KINDS),
|
|
58
|
+
max: count.refine((max) => max > 0),
|
|
59
|
+
raw: count,
|
|
60
|
+
});
|
|
61
|
+
/** Every value, or the first error. */
|
|
62
|
+
const collected = (results) => results.reduce((all, next) => all.andThen((values) => next.map((value) => [...values, value])), Ok([]));
|
|
63
|
+
const present = (text) => text?.match({ None: () => undefined, Some: (value) => value });
|
|
64
|
+
const firstSome = (options) => options.reduce((found, next) => found.or(next), None());
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Result } from "@cprussin/option-result";
|
|
2
|
+
import type { Dbus } from "@domicile-desktop/sdk/desktop/dbus";
|
|
3
|
+
import type { SystemError } from "@domicile-desktop/sdk/system";
|
|
4
|
+
import type { SysfsHost } from "./read-backlight";
|
|
5
|
+
export declare enum SetOutcome {
|
|
6
|
+
/** logind set it. */
|
|
7
|
+
Set = 0,
|
|
8
|
+
/** A newer level was asked for before this one was sent. */
|
|
9
|
+
Superseded = 1,
|
|
10
|
+
NoBacklight = 2
|
|
11
|
+
}
|
|
12
|
+
/** The calls {@link brightnessSetter} makes. */
|
|
13
|
+
export type SetterHost = SysfsHost & {
|
|
14
|
+
readonly dbus: Pick<Dbus, "call">;
|
|
15
|
+
};
|
|
16
|
+
/** Sets the backlight to a level from 0 to 1, and says how it went. */
|
|
17
|
+
export type SetBrightness = (level: number) => Promise<Result<SetOutcome, SystemError>>;
|
|
18
|
+
/**
|
|
19
|
+
* A function that sets the preferred backlight to a level from 0 to 1.
|
|
20
|
+
*
|
|
21
|
+
* - Reads the device again for each level, since the raw scale is the
|
|
22
|
+
* device's and it may have gone away.
|
|
23
|
+
* - Never sets zero; see `rawFor`.
|
|
24
|
+
* - Sends one level at a time. A dragged slider asks many times while logind
|
|
25
|
+
* answers once, so only the newest level waiting is sent and the others
|
|
26
|
+
* resolve {@link SetOutcome.Superseded}.
|
|
27
|
+
* - A level that is not a number rejects.
|
|
28
|
+
*/
|
|
29
|
+
export declare const brightnessSetter: (host: SetterHost) => SetBrightness;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Sets the screen's backlight through logind.
|
|
2
|
+
//
|
|
3
|
+
// `/sys/class/backlight/*/brightness` is writable only by root. logind's
|
|
4
|
+
// `Session.SetBrightness` lets the session's owner set it without a udev rule
|
|
5
|
+
// or a setuid helper.
|
|
6
|
+
import { Ok } from "@cprussin/option-result";
|
|
7
|
+
import { Bus } from "@domicile-desktop/sdk/system";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import { rawFor } from "./raw-for";
|
|
10
|
+
import { readBacklight } from "./read-backlight";
|
|
11
|
+
export var SetOutcome;
|
|
12
|
+
(function (SetOutcome) {
|
|
13
|
+
/** logind set it. */
|
|
14
|
+
SetOutcome[SetOutcome["Set"] = 0] = "Set";
|
|
15
|
+
/** A newer level was asked for before this one was sent. */
|
|
16
|
+
SetOutcome[SetOutcome["Superseded"] = 1] = "Superseded";
|
|
17
|
+
SetOutcome[SetOutcome["NoBacklight"] = 2] = "NoBacklight";
|
|
18
|
+
})(SetOutcome || (SetOutcome = {}));
|
|
19
|
+
/**
|
|
20
|
+
* A function that sets the preferred backlight to a level from 0 to 1.
|
|
21
|
+
*
|
|
22
|
+
* - Reads the device again for each level, since the raw scale is the
|
|
23
|
+
* device's and it may have gone away.
|
|
24
|
+
* - Never sets zero; see `rawFor`.
|
|
25
|
+
* - Sends one level at a time. A dragged slider asks many times while logind
|
|
26
|
+
* answers once, so only the newest level waiting is sent and the others
|
|
27
|
+
* resolve {@link SetOutcome.Superseded}.
|
|
28
|
+
* - A level that is not a number rejects.
|
|
29
|
+
*/
|
|
30
|
+
export const brightnessSetter = (host) => {
|
|
31
|
+
const queue = { pending: undefined, sending: false };
|
|
32
|
+
return (level) => {
|
|
33
|
+
if (queue.sending) {
|
|
34
|
+
queue.pending?.settle(Ok(SetOutcome.Superseded));
|
|
35
|
+
return new Promise((settle, fail) => {
|
|
36
|
+
queue.pending = { fail, level, settle };
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
queue.sending = true;
|
|
41
|
+
return sendFrom(host, queue, level);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
/** Send `level`, then whatever waits behind it. */
|
|
46
|
+
const sendFrom = async (host, queue, level) => {
|
|
47
|
+
try {
|
|
48
|
+
return await send(host, level);
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
const next = queue.pending;
|
|
52
|
+
queue.pending = undefined;
|
|
53
|
+
if (next === undefined) {
|
|
54
|
+
queue.sending = false;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
sendFrom(host, queue, next.level).then(next.settle, next.fail);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const send = async (host, level) => (await readBacklight(host)).andThenAsync(async (read) => read.match({
|
|
62
|
+
None: async () => Ok(SetOutcome.NoBacklight),
|
|
63
|
+
Some: async (backlight) => (await host.dbus.call({
|
|
64
|
+
body: ["backlight", backlight.device, rawFor(backlight, level)],
|
|
65
|
+
bus: Bus.System,
|
|
66
|
+
destination: "org.freedesktop.login1",
|
|
67
|
+
interface: "org.freedesktop.login1.Session",
|
|
68
|
+
member: "SetBrightness",
|
|
69
|
+
path: "/org/freedesktop/login1/session/auto",
|
|
70
|
+
signature: "ssu",
|
|
71
|
+
})).map(({ body }) => {
|
|
72
|
+
returnsNothing.parse(body);
|
|
73
|
+
return SetOutcome.Set;
|
|
74
|
+
}),
|
|
75
|
+
}));
|
|
76
|
+
const returnsNothing = z.tuple([]);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { SharedWatch } from "@domicile-desktop/react/shared-watch";
|
|
2
|
+
import type { Backlight } from "./host-backlight";
|
|
3
|
+
/** The backlight's level, shared, and the ways to change it. */
|
|
4
|
+
export type SharedBacklight = {
|
|
5
|
+
/** 0 to 1. Never reported on a machine without a backlight. */
|
|
6
|
+
level: SharedWatch<number>;
|
|
7
|
+
/** Ask for a level from 0 to 1 the user chose. `level` reports it once it is set. */
|
|
8
|
+
set: (level: number) => void;
|
|
9
|
+
/** Ask for a level automatic brightness chose. */
|
|
10
|
+
adjust: (level: number) => void;
|
|
11
|
+
/** Hear each level the user chose with `set`. Returns what stops it. */
|
|
12
|
+
chosen: (listener: (level: number) => void) => () => void;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* `backlight`, watched once for every reader. `set` and `adjust` share its
|
|
16
|
+
* one setter, so a level the user chose is never overtaken by an older
|
|
17
|
+
* automatic one.
|
|
18
|
+
*/
|
|
19
|
+
export declare const sharedBacklight: (backlight: Backlight) => SharedBacklight;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { sharedWatch } from "@domicile-desktop/react/shared-watch";
|
|
2
|
+
/**
|
|
3
|
+
* `backlight`, watched once for every reader. `set` and `adjust` share its
|
|
4
|
+
* one setter, so a level the user chose is never overtaken by an older
|
|
5
|
+
* automatic one.
|
|
6
|
+
*/
|
|
7
|
+
export const sharedBacklight = (backlight) => {
|
|
8
|
+
const listeners = new Set();
|
|
9
|
+
return {
|
|
10
|
+
adjust: backlight.set,
|
|
11
|
+
chosen: (listener) => {
|
|
12
|
+
listeners.add(listener);
|
|
13
|
+
return () => {
|
|
14
|
+
listeners.delete(listener);
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
level: sharedWatch(backlight.watch),
|
|
18
|
+
set: (level) => {
|
|
19
|
+
backlight.set(level);
|
|
20
|
+
for (const listener of listeners) {
|
|
21
|
+
listener(level);
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Option, Result } from "@cprussin/option-result";
|
|
2
|
+
import type { Dbus } from "@domicile-desktop/sdk/desktop/dbus";
|
|
3
|
+
import type { Listening, SystemError } from "@domicile-desktop/sdk/system";
|
|
4
|
+
/** The calls {@link watchAmbientLight} makes. */
|
|
5
|
+
export type SensorBus = {
|
|
6
|
+
readonly dbus: Pick<Dbus, "call" | "match">;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The light level as the first item, then after each change, or `None` on a
|
|
10
|
+
* machine without a sensor or without iio-sensor-proxy.
|
|
11
|
+
*
|
|
12
|
+
* The level is in lux, or in the sensor's own units on a sensor that reports
|
|
13
|
+
* no lux. Claims the sensor, which keeps it reading, until `stop`. Claims it
|
|
14
|
+
* again after a compositor restart, whose bus connection held the claim.
|
|
15
|
+
*/
|
|
16
|
+
export declare const watchAmbientLight: (bus: SensorBus) => Promise<Result<Option<Listening<number>>, SystemError>>;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// The ambient light sensor, from iio-sensor-proxy over the system bus, for
|
|
2
|
+
// automatic brightness. See https://gitlab.freedesktop.org/hadess/iio-sensor-proxy.
|
|
3
|
+
import { Err, None, Ok, Some } from "@cprussin/option-result";
|
|
4
|
+
import { Bus, ListenedKind, SystemErrorKind, } from "@domicile-desktop/sdk/system";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
const PROXY = "net.hadess.SensorProxy";
|
|
7
|
+
const PATH = "/net/hadess/SensorProxy";
|
|
8
|
+
const PROPERTIES = "org.freedesktop.DBus.Properties";
|
|
9
|
+
const NO_SERVICE = "org.freedesktop.DBus.Error.ServiceUnknown";
|
|
10
|
+
/**
|
|
11
|
+
* The light level as the first item, then after each change, or `None` on a
|
|
12
|
+
* machine without a sensor or without iio-sensor-proxy.
|
|
13
|
+
*
|
|
14
|
+
* The level is in lux, or in the sensor's own units on a sensor that reports
|
|
15
|
+
* no lux. Claims the sensor, which keeps it reading, until `stop`. Claims it
|
|
16
|
+
* again after a compositor restart, whose bus connection held the claim.
|
|
17
|
+
*/
|
|
18
|
+
export const watchAmbientLight = async (bus) => (await bus.dbus.match({
|
|
19
|
+
bus: Bus.System,
|
|
20
|
+
interface: PROPERTIES,
|
|
21
|
+
member: "PropertiesChanged",
|
|
22
|
+
path: PATH,
|
|
23
|
+
sender: PROXY,
|
|
24
|
+
})).andThenAsync(async (changes) => (await readSensors(bus)).match({
|
|
25
|
+
Err: (error) => Promise.resolve(stopped(changes, error)),
|
|
26
|
+
Ok: async (read) => {
|
|
27
|
+
if (read.HasAmbientLight.value) {
|
|
28
|
+
return (await claimedLevel(bus)).match({
|
|
29
|
+
Err: (error) => {
|
|
30
|
+
changes.stop();
|
|
31
|
+
return Err(error);
|
|
32
|
+
},
|
|
33
|
+
Ok: (level) => Ok(Some({
|
|
34
|
+
ended: changes.ended,
|
|
35
|
+
items: changes.items.pipeThrough(levels(bus, level)),
|
|
36
|
+
stop: () => {
|
|
37
|
+
changes.stop();
|
|
38
|
+
release(bus);
|
|
39
|
+
},
|
|
40
|
+
})),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
changes.stop();
|
|
45
|
+
return Ok(None());
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
}));
|
|
49
|
+
/** `changes` stopped: no sensor when iio-sensor-proxy is not there. */
|
|
50
|
+
const stopped = (changes, error) => {
|
|
51
|
+
changes.stop();
|
|
52
|
+
return error.kind === SystemErrorKind.Dbus &&
|
|
53
|
+
error.message.startsWith(NO_SERVICE)
|
|
54
|
+
? Ok(None())
|
|
55
|
+
: Err(error);
|
|
56
|
+
};
|
|
57
|
+
const variantSchema = z.object({ signature: z.string(), value: z.unknown() });
|
|
58
|
+
const sensorsSchema = z.tuple([
|
|
59
|
+
z.looseObject({
|
|
60
|
+
HasAmbientLight: z.object({ value: z.boolean() }),
|
|
61
|
+
LightLevel: z.object({ value: z.number() }),
|
|
62
|
+
}),
|
|
63
|
+
]);
|
|
64
|
+
const propertiesChangedSchema = z.tuple([
|
|
65
|
+
z.string(),
|
|
66
|
+
z.record(z.string(), variantSchema),
|
|
67
|
+
z.array(z.string()),
|
|
68
|
+
]);
|
|
69
|
+
const changedLevelSchema = z.object({ value: z.number() }).optional();
|
|
70
|
+
const call = (bus, member) => bus.dbus.call({
|
|
71
|
+
bus: Bus.System,
|
|
72
|
+
destination: PROXY,
|
|
73
|
+
interface: PROXY,
|
|
74
|
+
member,
|
|
75
|
+
path: PATH,
|
|
76
|
+
});
|
|
77
|
+
const readSensors = async (bus) => (await bus.dbus.call({
|
|
78
|
+
body: [PROXY],
|
|
79
|
+
bus: Bus.System,
|
|
80
|
+
destination: PROXY,
|
|
81
|
+
interface: PROPERTIES,
|
|
82
|
+
member: "GetAll",
|
|
83
|
+
path: PATH,
|
|
84
|
+
signature: "s",
|
|
85
|
+
})).map(({ body }) => sensorsSchema.parse(body)[0]);
|
|
86
|
+
/** Claims the sensor, then reads the level it measured since. */
|
|
87
|
+
const claimedLevel = async (bus) => (await call(bus, "ClaimLight")).andThenAsync(async () => (await readSensors(bus)).map((read) => read.LightLevel.value));
|
|
88
|
+
const release = (bus) => {
|
|
89
|
+
call(bus, "ReleaseLight")
|
|
90
|
+
.then((result) => {
|
|
91
|
+
result.match({
|
|
92
|
+
Err: logRelease,
|
|
93
|
+
Ok: () => undefined,
|
|
94
|
+
});
|
|
95
|
+
})
|
|
96
|
+
.catch(logRelease);
|
|
97
|
+
};
|
|
98
|
+
const logRelease = (error) => {
|
|
99
|
+
// biome-ignore lint/suspicious/noConsole: a background release has no caller to tell
|
|
100
|
+
console.error("could not release the ambient light sensor", error);
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Each level, starting from `level`. After a compositor restart the sensor is
|
|
104
|
+
* claimed and read again; a claim the next restart ends waits for the restart
|
|
105
|
+
* after it.
|
|
106
|
+
*/
|
|
107
|
+
const levels = (bus, level) => new TransformStream({
|
|
108
|
+
start: (controller) => {
|
|
109
|
+
controller.enqueue(level);
|
|
110
|
+
},
|
|
111
|
+
transform: async (heard, controller) => {
|
|
112
|
+
switch (heard.kind) {
|
|
113
|
+
case ListenedKind.Heard: {
|
|
114
|
+
const [iface, changed] = propertiesChangedSchema.parse(heard.item.body);
|
|
115
|
+
const changedLevel = changedLevelSchema.parse(changed.LightLevel);
|
|
116
|
+
if (iface === PROXY && changedLevel !== undefined) {
|
|
117
|
+
controller.enqueue(changedLevel.value);
|
|
118
|
+
}
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
case ListenedKind.Missed: {
|
|
122
|
+
(await claimedLevel(bus)).match({
|
|
123
|
+
Err: (error) => {
|
|
124
|
+
if (error.kind !== SystemErrorKind.CompositorGone) {
|
|
125
|
+
controller.error(error);
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
Ok: (claimed) => {
|
|
129
|
+
controller.enqueue(claimed);
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Result } from "@cprussin/option-result";
|
|
2
|
+
import type { Processes } from "@domicile-desktop/sdk/desktop/processes";
|
|
3
|
+
import type { SystemError } from "@domicile-desktop/sdk/system";
|
|
4
|
+
import type { SysfsHost } from "./read-backlight";
|
|
5
|
+
/** The calls {@link watchBrightness} makes. */
|
|
6
|
+
export type WatchHost = SysfsHost & {
|
|
7
|
+
readonly processes: Pick<Processes, "spawn">;
|
|
8
|
+
};
|
|
9
|
+
export type BrightnessWatch = {
|
|
10
|
+
stop: () => void;
|
|
11
|
+
/** `Ok` after {@link BrightnessWatch.stop}, `Err` if the watch broke. */
|
|
12
|
+
ended: Promise<Result<"stopped", SystemError>>;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Calls `onLevel` with the backlight's level from 0 to 1, now and after each
|
|
16
|
+
* change.
|
|
17
|
+
*
|
|
18
|
+
* - Reports only a move of a whole percent, since the slider shows no finer.
|
|
19
|
+
* - Never called on a machine without a backlight. A backlight that goes away
|
|
20
|
+
* and comes back is reported again.
|
|
21
|
+
* - Runs `udevadm` from the compositor's `PATH`. Works while the desktop is
|
|
22
|
+
* locked.
|
|
23
|
+
* - Runs `udevadm` again under the next compositor when the compositor exits,
|
|
24
|
+
* and reads then. See "A compositor restart" in
|
|
25
|
+
* docs/architecture/ENGINE-FORK.md.
|
|
26
|
+
*/
|
|
27
|
+
export declare const watchBrightness: (host: WatchHost, onLevel: (level: number) => void, every?: typeof everyInterval) => Promise<Result<BrightnessWatch, SystemError>>;
|
|
28
|
+
/** Calls `tick` every `ms`, until the returned function is called. */
|
|
29
|
+
declare const everyInterval: (ms: number, tick: () => void) => (() => void);
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// Watches the screen's backlight.
|
|
2
|
+
//
|
|
3
|
+
// inotify sees no change to a file under `/sys`, so the watch runs
|
|
4
|
+
// `udevadm monitor` and reads the backlight again on each kernel uevent.
|
|
5
|
+
import { Err, Ok } from "@cprussin/option-result";
|
|
6
|
+
import { SystemErrorKind } from "@domicile-desktop/sdk/system";
|
|
7
|
+
import { levelOf, readBacklight } from "./read-backlight";
|
|
8
|
+
/** Prints a line for each backlight uevent. */
|
|
9
|
+
const UDEVADM = [
|
|
10
|
+
"udevadm",
|
|
11
|
+
"monitor",
|
|
12
|
+
"--kernel",
|
|
13
|
+
"--subsystem-match=backlight",
|
|
14
|
+
];
|
|
15
|
+
/** How often to read again without a uevent: firmware keys may send none. */
|
|
16
|
+
const BACKSTOP_MS = 120_000;
|
|
17
|
+
/**
|
|
18
|
+
* Calls `onLevel` with the backlight's level from 0 to 1, now and after each
|
|
19
|
+
* change.
|
|
20
|
+
*
|
|
21
|
+
* - Reports only a move of a whole percent, since the slider shows no finer.
|
|
22
|
+
* - Never called on a machine without a backlight. A backlight that goes away
|
|
23
|
+
* and comes back is reported again.
|
|
24
|
+
* - Runs `udevadm` from the compositor's `PATH`. Works while the desktop is
|
|
25
|
+
* locked.
|
|
26
|
+
* - Runs `udevadm` again under the next compositor when the compositor exits,
|
|
27
|
+
* and reads then. See "A compositor restart" in
|
|
28
|
+
* docs/architecture/ENGINE-FORK.md.
|
|
29
|
+
*/
|
|
30
|
+
export const watchBrightness = async (host, onLevel, every = everyInterval) => (await host.processes.spawn(UDEVADM)).map((udevadm) => {
|
|
31
|
+
const watch = {
|
|
32
|
+
failure: undefined,
|
|
33
|
+
reading: Promise.resolve(),
|
|
34
|
+
shown: undefined,
|
|
35
|
+
stopped: false,
|
|
36
|
+
udevadm,
|
|
37
|
+
};
|
|
38
|
+
const reread = () => {
|
|
39
|
+
watch.reading = watch.reading.then(() => readOnce(host, watch, onLevel));
|
|
40
|
+
};
|
|
41
|
+
reread();
|
|
42
|
+
const stopClock = every(BACKSTOP_MS, reread);
|
|
43
|
+
return {
|
|
44
|
+
ended: ended(host, watch, reread, stopClock),
|
|
45
|
+
stop: () => {
|
|
46
|
+
watch.stopped = true;
|
|
47
|
+
watch.udevadm.kill();
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
/** Calls `tick` every `ms`, until the returned function is called. */
|
|
52
|
+
const everyInterval = (ms, tick) => {
|
|
53
|
+
const id = setInterval(tick, ms);
|
|
54
|
+
return () => {
|
|
55
|
+
clearInterval(id);
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
const readOnce = async (host, watch, onLevel) => {
|
|
59
|
+
const read = await readBacklight(host);
|
|
60
|
+
if (!watch.stopped && watch.failure === undefined) {
|
|
61
|
+
read.match({
|
|
62
|
+
// udevadm ends with it, and the read after the next one starts stands in.
|
|
63
|
+
Err: (error) => {
|
|
64
|
+
if (error.kind !== SystemErrorKind.CompositorGone) {
|
|
65
|
+
watch.failure = error;
|
|
66
|
+
watch.udevadm.kill();
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
Ok: (backlight) => {
|
|
70
|
+
const level = backlight.map(levelOf);
|
|
71
|
+
const shown = level.match({
|
|
72
|
+
None: () => undefined,
|
|
73
|
+
Some: (now) => Math.round(now * 100),
|
|
74
|
+
});
|
|
75
|
+
if (shown !== watch.shown) {
|
|
76
|
+
watch.shown = shown;
|
|
77
|
+
level.match({ None: () => undefined, Some: onLevel });
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Reads `udevadm`'s lines until it exits, then says why it did. One the
|
|
85
|
+
* compositor took with it is started again.
|
|
86
|
+
*/
|
|
87
|
+
const ended = async (host, watch, reread, stopClock) => {
|
|
88
|
+
let exit;
|
|
89
|
+
for (;;) {
|
|
90
|
+
await eachLine(watch.udevadm.stdout, (line) => {
|
|
91
|
+
if (line.startsWith("KERNEL[")) {
|
|
92
|
+
reread();
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
exit = await watch.udevadm.exited;
|
|
96
|
+
if (watch.stopped || watch.failure !== undefined || !isGone(exit)) {
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
const next = await respawn(host);
|
|
100
|
+
const running = next.match({
|
|
101
|
+
Err: (error) => {
|
|
102
|
+
exit = Err(error);
|
|
103
|
+
return false;
|
|
104
|
+
},
|
|
105
|
+
Ok: (udevadm) => {
|
|
106
|
+
watch.udevadm = udevadm;
|
|
107
|
+
if (watch.stopped) {
|
|
108
|
+
udevadm.kill();
|
|
109
|
+
}
|
|
110
|
+
reread();
|
|
111
|
+
return true;
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
if (!running) {
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
stopClock();
|
|
119
|
+
await watch.reading;
|
|
120
|
+
if (watch.failure !== undefined) {
|
|
121
|
+
return Err(watch.failure);
|
|
122
|
+
}
|
|
123
|
+
else if (watch.stopped) {
|
|
124
|
+
return Ok("stopped");
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
return exit.andThen((exited) => Err(unexpectedExit(exited)));
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
const eachLine = async (stream, onLine) => {
|
|
131
|
+
const reader = stream.getReader();
|
|
132
|
+
const decoder = new TextDecoder();
|
|
133
|
+
let unfinished = "";
|
|
134
|
+
for (;;) {
|
|
135
|
+
const { done, value } = await reader.read();
|
|
136
|
+
if (done) {
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
const lines = (unfinished + decoder.decode(value, { stream: true })).split("\n");
|
|
140
|
+
unfinished = lines.pop() ?? "";
|
|
141
|
+
for (const line of lines) {
|
|
142
|
+
onLine(line);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
/** udevadm under the next compositor, past any that exits before it starts. */
|
|
147
|
+
const respawn = async (host) => {
|
|
148
|
+
for (;;) {
|
|
149
|
+
const next = await host.processes.spawn(UDEVADM);
|
|
150
|
+
if (!isGone(next)) {
|
|
151
|
+
return next;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
const isGone = (answer) => answer.match({
|
|
156
|
+
Err: (error) => error.kind === SystemErrorKind.CompositorGone,
|
|
157
|
+
Ok: () => false,
|
|
158
|
+
});
|
|
159
|
+
const unexpectedExit = ({ code, signal }) => ({
|
|
160
|
+
kind: SystemErrorKind.Other,
|
|
161
|
+
message: code === undefined
|
|
162
|
+
? `udevadm monitor was killed by signal ${signal}`
|
|
163
|
+
: `udevadm monitor exited with code ${code}`,
|
|
164
|
+
});
|
package/package.json
CHANGED
|
@@ -1,10 +1,95 @@
|
|
|
1
1
|
{
|
|
2
|
+
"dependencies": {
|
|
3
|
+
"@cprussin/option-result": "^2.0.1",
|
|
4
|
+
"@domicile-desktop/react": "0.0.0",
|
|
5
|
+
"@domicile-desktop/sdk": "1.0.0",
|
|
6
|
+
"zod": "^4.5.4"
|
|
7
|
+
},
|
|
8
|
+
"description": "Screen brightness for a Domicile shell: reads /sys/class/backlight, watches it and sets it through logind, and reads the ambient light sensor through iio-sensor-proxy, on @domicile-desktop/sdk/system.",
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"@cprussin/tsconfig": "^5.0.0",
|
|
11
|
+
"@domicile-desktop/test-support": "0.0.1",
|
|
12
|
+
"@types/bun": "^1.4.2",
|
|
13
|
+
"@types/react": "^19.2.18",
|
|
14
|
+
"react": "^19.2.8",
|
|
15
|
+
"typescript": "^7.0.2"
|
|
16
|
+
},
|
|
17
|
+
"engines": {
|
|
18
|
+
"bun": ">=1.4.2",
|
|
19
|
+
"node": ">=24"
|
|
20
|
+
},
|
|
21
|
+
"exports": {
|
|
22
|
+
"./read-backlight": {
|
|
23
|
+
"types": "./dist/read-backlight.d.ts",
|
|
24
|
+
"default": "./dist/read-backlight.js"
|
|
25
|
+
},
|
|
26
|
+
"./set-brightness": {
|
|
27
|
+
"types": "./dist/set-brightness.d.ts",
|
|
28
|
+
"default": "./dist/set-brightness.js"
|
|
29
|
+
},
|
|
30
|
+
"./watch-ambient-light": {
|
|
31
|
+
"types": "./dist/watch-ambient-light.d.ts",
|
|
32
|
+
"default": "./dist/watch-ambient-light.js"
|
|
33
|
+
},
|
|
34
|
+
"./watch-brightness": {
|
|
35
|
+
"types": "./dist/watch-brightness.d.ts",
|
|
36
|
+
"default": "./dist/watch-brightness.js"
|
|
37
|
+
},
|
|
38
|
+
"./react": {
|
|
39
|
+
"types": "./dist/react.d.ts",
|
|
40
|
+
"default": "./dist/react.js"
|
|
41
|
+
},
|
|
42
|
+
"./shared-backlight": {
|
|
43
|
+
"types": "./dist/shared-backlight.d.ts",
|
|
44
|
+
"default": "./dist/shared-backlight.js"
|
|
45
|
+
},
|
|
46
|
+
"./fixture": {
|
|
47
|
+
"types": "./dist/fixture.d.ts",
|
|
48
|
+
"default": "./dist/fixture.js"
|
|
49
|
+
},
|
|
50
|
+
"./auto-brightness": {
|
|
51
|
+
"types": "./dist/auto-brightness.d.ts",
|
|
52
|
+
"default": "./dist/auto-brightness.js"
|
|
53
|
+
},
|
|
54
|
+
"./auto-brightness-curve": {
|
|
55
|
+
"types": "./dist/auto-brightness-curve.d.ts",
|
|
56
|
+
"default": "./dist/auto-brightness-curve.js"
|
|
57
|
+
},
|
|
58
|
+
"./learned-offset": {
|
|
59
|
+
"types": "./dist/learned-offset.d.ts",
|
|
60
|
+
"default": "./dist/learned-offset.js"
|
|
61
|
+
},
|
|
62
|
+
"./host-ambient-light": {
|
|
63
|
+
"types": "./dist/host-ambient-light.d.ts",
|
|
64
|
+
"default": "./dist/host-ambient-light.js"
|
|
65
|
+
},
|
|
66
|
+
"./host-backlight": {
|
|
67
|
+
"types": "./dist/host-backlight.d.ts",
|
|
68
|
+
"default": "./dist/host-backlight.js"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"files": [
|
|
72
|
+
"dist/**"
|
|
73
|
+
],
|
|
74
|
+
"license": "MIT",
|
|
2
75
|
"name": "@domicile-desktop/system-backlight",
|
|
3
|
-
"
|
|
4
|
-
|
|
76
|
+
"peerDependencies": {
|
|
77
|
+
"react": "^19.2.8"
|
|
78
|
+
},
|
|
79
|
+
"private": false,
|
|
80
|
+
"publishConfig": {
|
|
81
|
+
"access": "public"
|
|
82
|
+
},
|
|
5
83
|
"repository": {
|
|
84
|
+
"directory": "packages/system-backlight",
|
|
6
85
|
"type": "git",
|
|
7
86
|
"url": "git+https://github.com/cprussin/domicile.git"
|
|
8
87
|
},
|
|
9
|
-
"
|
|
10
|
-
|
|
88
|
+
"scripts": {
|
|
89
|
+
"build": "tsc -p tsconfig.build.json",
|
|
90
|
+
"test:types": "tsc --noEmit",
|
|
91
|
+
"test:unit": "bun test"
|
|
92
|
+
},
|
|
93
|
+
"type": "module",
|
|
94
|
+
"version": "1.0.0"
|
|
95
|
+
}
|