testing ags
This commit is contained in:
79
home/core/gui/ags/services/brightness.js
Normal file
79
home/core/gui/ags/services/brightness.js
Normal file
@@ -0,0 +1,79 @@
|
||||
import { Service, Utils } from "../imports.js";
|
||||
import Gio from "gi://Gio";
|
||||
import GLib from "gi://GLib";
|
||||
|
||||
const clamp = (num, min, max) => Math.min(Math.max(num, min), max);
|
||||
|
||||
class BrightnessService extends Service {
|
||||
static {
|
||||
Service.register(
|
||||
this,
|
||||
{ "screen-changed": ["float"] },
|
||||
{ "screen-value": ["float", "rw"] },
|
||||
);
|
||||
}
|
||||
|
||||
#screenValue = 0;
|
||||
|
||||
#interface = Utils.exec("sh -c 'ls -w1 /sys/class/backlight | head -1'");
|
||||
#path = `/sys/class/backlight/${this.#interface}`;
|
||||
#brightness = `${this.#path}/brightness`;
|
||||
|
||||
#max = Number(Utils.readFile(`${this.#path}/max_brightness`));
|
||||
|
||||
get screen_value() {
|
||||
return this.#screenValue;
|
||||
}
|
||||
|
||||
set screen_value(percent) {
|
||||
percent = clamp(percent, 0, 1);
|
||||
this.#screenValue = percent;
|
||||
|
||||
const file = Gio.File.new_for_path(this.#brightness);
|
||||
const string = `${Math.round(percent * this.#max)}`;
|
||||
|
||||
new Promise((resolve, _) => {
|
||||
file.replace_contents_bytes_async(
|
||||
new GLib.Bytes(new TextEncoder().encode(string)),
|
||||
null,
|
||||
false,
|
||||
Gio.FileCreateFlags.NONE,
|
||||
null,
|
||||
(self, res) => {
|
||||
try {
|
||||
self.replace_contents_finish(res);
|
||||
resolve(self);
|
||||
} catch (error) {
|
||||
print(error);
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.#updateScreenValue();
|
||||
Utils.monitorFile(this.#brightness, () => this.#onChange());
|
||||
}
|
||||
|
||||
#updateScreenValue() {
|
||||
this.#screenValue = Number(Utils.readFile(this.#brightness)) / this.#max;
|
||||
}
|
||||
|
||||
#onChange() {
|
||||
this.#updateScreenValue();
|
||||
|
||||
this.notify("screen-value");
|
||||
this.emit("screen-changed", this.#screenValue);
|
||||
}
|
||||
|
||||
connectWidget(widget, callback, event = "screen-changed") {
|
||||
super.connectWidget(widget, callback, event);
|
||||
}
|
||||
}
|
||||
|
||||
const service = new BrightnessService();
|
||||
|
||||
export default service;
|
||||
65
home/core/gui/ags/services/osd.js
Normal file
65
home/core/gui/ags/services/osd.js
Normal file
@@ -0,0 +1,65 @@
|
||||
import { Audio, Icons, Service, Utils } from "../imports.js";
|
||||
import { audioIcon, micIcon } from "../utils/audio.js";
|
||||
import Brightness from "./brightness.js";
|
||||
|
||||
class Indicator extends Service {
|
||||
static {
|
||||
Service.register(this, {
|
||||
popup: ["jsobject", "boolean"],
|
||||
});
|
||||
}
|
||||
|
||||
#delay = 1500;
|
||||
#count = 0;
|
||||
|
||||
popup(value, label, icon, showProgress = true) {
|
||||
const props = {
|
||||
value,
|
||||
label,
|
||||
icon,
|
||||
showProgress,
|
||||
};
|
||||
this.emit("popup", props, true);
|
||||
this.#count++;
|
||||
Utils.timeout(this.#delay, () => {
|
||||
this.#count--;
|
||||
|
||||
if (this.#count === 0) {
|
||||
this.emit("popup", props, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
bluetooth(addr) {
|
||||
this.popup(0, getBluetoothDevice(addr), Icons.bluetooth.active, false);
|
||||
}
|
||||
|
||||
speaker() {
|
||||
this.popup(
|
||||
Audio.speaker?.volume ?? 0,
|
||||
Audio.speaker?.description ?? "",
|
||||
audioIcon(),
|
||||
);
|
||||
}
|
||||
|
||||
mic() {
|
||||
this.popup(
|
||||
Audio.microphone?.volume || 0,
|
||||
Audio.microphone?.description || "",
|
||||
micIcon(),
|
||||
);
|
||||
}
|
||||
|
||||
display() {
|
||||
// brightness is async, so lets wait a bit
|
||||
Utils.timeout(10, () =>
|
||||
this.popup(Brightness.screenValue, "Brightness", Icons.brightness),
|
||||
);
|
||||
}
|
||||
|
||||
connect(event = "popup", callback) {
|
||||
return super.connect(event, callback);
|
||||
}
|
||||
}
|
||||
|
||||
export default new Indicator();
|
||||
Reference in New Issue
Block a user