From 3c919c9bc9fac336c1919eb2f0f900506f6d779d Mon Sep 17 00:00:00 2001 From: retrozinndev Date: Sun, 28 Sep 2025 15:13:13 -0300 Subject: [PATCH] :wrench: chore(app): use new `createSubscription()` with `secureBaseBinding()` to notify brightness on-screen display --- src/app.ts | 31 ++++++++++--------------------- src/modules/utils.ts | 9 ++++++++- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/app.ts b/src/app.ts index 3e4da43..fc04ac1 100644 --- a/src/app.ts +++ b/src/app.ts @@ -22,12 +22,12 @@ import { Wallpaper } from "./modules/wallpaper"; import { Stylesheet } from "./modules/stylesheet"; import { Clipboard } from "./modules/clipboard"; 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 { programArgs, programInvocationName } from "system"; import { setConsoleLogDomain } from "console"; import { initPlayer } from "./modules/media"; -import { encoder } from "./modules/utils"; +import { createSubscription, encoder, secureBaseBinding } from "./modules/utils"; import { exec } from "ags/process"; import { Backlights } from "./modules/backlight"; 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) - let lastDefaultBk: Backlights.Backlight|null = null; - this.#connections.set(Backlights.getDefault(), - Backlights.getDefault().connect("notify::default", (_, defaultBk: Backlights.Backlight|null) => { - if(!lastDefaultBk) return; - - if(this.#connections.has(lastDefaultBk)) - 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) - )); - }) + createSubscription( + secureBaseBinding( + createBinding(Backlights.getDefault(), "default"), + "brightness", + 100 + ), + () => !Windows.getDefault().isOpen("control-center") && + triggerOSD(OSDModes.brightness) ); this.#connections.set(Notifications.getDefault(), [ diff --git a/src/modules/utils.ts b/src/modules/utils.ts index 0216606..2852d6f 100644 --- a/src/modules/utils.ts +++ b/src/modules/utils.ts @@ -246,7 +246,7 @@ export function construct(klass: Class, props: Record(accessor: Accessor, callback: () => void): void { + const scope = getScope(); + const unsub = accessor.subscribe(callback); + + scope.onCleanup(unsub); +} + export function secureBinding< GObj extends GObject.Object, Prop extends keyof GObj,