🔧 chore(app): use new createSubscription() with secureBaseBinding() to notify brightness on-screen display

This commit is contained in:
retrozinndev
2025-09-28 15:13:13 -03:00
parent 087bafb2c0
commit 3c919c9bc9
2 changed files with 18 additions and 22 deletions
+9 -20
View File
@@ -22,12 +22,12 @@ import { Wallpaper } from "./modules/wallpaper";
import { Stylesheet } from "./modules/stylesheet"; import { Stylesheet } from "./modules/stylesheet";
import { Clipboard } from "./modules/clipboard"; import { Clipboard } from "./modules/clipboard";
import { Gdk, Gtk } from "ags/gtk4"; import { Gdk, Gtk } from "ags/gtk4";
import { createRoot, getScope, Scope } from "ags"; import { createBinding, createRoot, getScope, Scope } from "ags";
import { OSDModes, triggerOSD } from "./window/osd"; import { OSDModes, triggerOSD } from "./window/osd";
import { programArgs, programInvocationName } from "system"; import { programArgs, programInvocationName } from "system";
import { setConsoleLogDomain } from "console"; import { setConsoleLogDomain } from "console";
import { initPlayer } from "./modules/media"; import { initPlayer } from "./modules/media";
import { encoder } from "./modules/utils"; import { createSubscription, encoder, secureBaseBinding } from "./modules/utils";
import { exec } from "ags/process"; import { exec } from "ags/process";
import { Backlights } from "./modules/backlight"; import { Backlights } from "./modules/backlight";
import GObject, { register } from "ags/gobject"; import GObject, { register } from "ags/gobject";
@@ -295,25 +295,14 @@ you should use the socket in the XDG_RUNTIME_DIR/colorshell.sock for a faster re
) )
); );
// dinamically connect to default backlight (if there's any) createSubscription(
let lastDefaultBk: Backlights.Backlight|null = null; secureBaseBinding<Backlights.Backlight>(
this.#connections.set(Backlights.getDefault(), createBinding(Backlights.getDefault(), "default"),
Backlights.getDefault().connect("notify::default", (_, defaultBk: Backlights.Backlight|null) => { "brightness",
if(!lastDefaultBk) return; 100
),
if(this.#connections.has(lastDefaultBk)) () => !Windows.getDefault().isOpen("control-center") &&
lastDefaultBk.disconnect((this.#connections.get(lastDefaultBk) as number));
lastDefaultBk = null;
if(!defaultBk) return;
lastDefaultBk = defaultBk;
this.#connections.set(defaultBk, defaultBk.connect("brightness-changed", () =>
!Windows.getDefault().isOpen("control-center") &&
triggerOSD(OSDModes.brightness) triggerOSD(OSDModes.brightness)
));
})
); );
this.#connections.set(Notifications.getDefault(), [ this.#connections.set(Notifications.getDefault(), [
+8 -1
View File
@@ -246,7 +246,7 @@ export function construct<Class extends object>(klass: Class, props: Record<any,
/** open connections to gobjects that are closed when the scope /** open connections to gobjects that are closed when the scope
* is disposed * is disposed
* @experimental * @experimental types don't work correctly yet
* */ * */
export function createConnetions< export function createConnetions<
GObj extends GObject.Object, GObj extends GObject.Object,
@@ -277,6 +277,13 @@ export function createConnetions<
}); });
} }
export function createSubscription<T = any>(accessor: Accessor<T>, callback: () => void): void {
const scope = getScope();
const unsub = accessor.subscribe(callback);
scope.onCleanup(unsub);
}
export function secureBinding< export function secureBinding<
GObj extends GObject.Object, GObj extends GObject.Object,
Prop extends keyof GObj, Prop extends keyof GObj,