gpu: fix auto detection

This commit is contained in:
2 * r + 2 * t 2025-02-17 12:40:13 +11:00
parent 354c3446de
commit 23779bdba1

View file

@ -1,4 +1,4 @@
import { execAsync, Gio, GObject, interval, property, register } from "astal"; import { execAsync, Gio, GLib, GObject, interval, property, register } from "astal";
import { gpu as config } from "config"; import { gpu as config } from "config";
@register({ GTypeName: "Gpu" }) @register({ GTypeName: "Gpu" })
@ -24,10 +24,12 @@ export default class Gpu extends GObject.Object {
} }
update() { update() {
this.calculateUsage().then(usage => { this.calculateUsage()
this.#usage = usage; .then(usage => {
this.notify("usage"); this.#usage = usage;
}); this.notify("usage");
})
.catch(console.error);
} }
constructor() { constructor() {
@ -44,7 +46,7 @@ export default class Gpu extends GObject.Object {
let info: Gio.FileInfo | undefined | null; let info: Gio.FileInfo | undefined | null;
while ((info = enumerator?.next_file(null))) { while ((info = enumerator?.next_file(null))) {
if (/card[0-9]+/.test(info.get_name())) { if (GLib.file_test(`/sys/class/drm/${info.get_name()}/device/gpu_busy_percent`, GLib.FileTest.EXISTS)) {
this.available = true; this.available = true;
break; break;
} }