mirror of
https://github.com/Theaninova/TheaninovOS.git
synced 2025-12-12 19:46:20 +00:00
refactor: make the whole thing more generic
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
import * as Utils from "resource:///com/github/Aylur/ags/utils.js";
|
||||
import Service from "resource:///com/github/Aylur/ags/service.js";
|
||||
import options from "../options.js";
|
||||
import { dependencies } from "../utils.js";
|
||||
|
||||
const KBD = options.brightnessctlKBD;
|
||||
|
||||
class Brightness extends Service {
|
||||
static {
|
||||
Service.register(
|
||||
this,
|
||||
{},
|
||||
{
|
||||
screen: ["float", "rw"],
|
||||
kbd: ["int", "rw"],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#kbd = 0;
|
||||
#kbdMax = 3;
|
||||
#screen = 0;
|
||||
|
||||
get kbd() {
|
||||
return this.#kbd;
|
||||
}
|
||||
get screen() {
|
||||
return this.#screen;
|
||||
}
|
||||
|
||||
set kbd(value) {
|
||||
if (!dependencies(["brightnessctl"])) return;
|
||||
|
||||
if (value < 0 || value > this.#kbdMax) return;
|
||||
|
||||
Utils.execAsync(`brightnessctl -d ${KBD} s ${value} -q`)
|
||||
.then(() => {
|
||||
this.#kbd = value;
|
||||
this.changed("kbd");
|
||||
})
|
||||
.catch(console.error);
|
||||
}
|
||||
|
||||
set screen(percent) {
|
||||
if (!dependencies(["gbmonctl"])) return;
|
||||
|
||||
if (percent < 0) percent = 0;
|
||||
|
||||
if (percent > 1) percent = 1;
|
||||
|
||||
Utils.execAsync(
|
||||
`gbmonctl --prop brightness -val ${Math.min(
|
||||
Math.max(Math.floor(percent * 100), 0),
|
||||
100,
|
||||
)}`,
|
||||
)
|
||||
.then(() => {
|
||||
this.#screen = percent;
|
||||
this.changed("screen");
|
||||
})
|
||||
.catch(console.error);
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
if (dependencies(["brightnessctl"])) {
|
||||
this.#kbd = Number(Utils.exec(`brightnessctl -d ${KBD} g`));
|
||||
this.#kbdMax = Number(Utils.exec(`brightnessctl -d ${KBD} m`));
|
||||
this.#screen =
|
||||
Number(Utils.exec("brightnessctl g")) /
|
||||
Number(Utils.exec("brightnessctl m"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new Brightness();
|
||||
Reference in New Issue
Block a user