mirror of
https://github.com/Theaninova/TheaninovOS.git
synced 2026-01-05 07:12:49 +00:00
ags steal
This commit is contained in:
58
desktops/hyprland/ags/scripts/brightness.js
Normal file
58
desktops/hyprland/ags/scripts/brightness.js
Normal file
@@ -0,0 +1,58 @@
|
||||
import { Service, Utils } from '../imports.js';
|
||||
const { exec, execAsync } = Utils;
|
||||
|
||||
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;
|
||||
|
||||
// the getter has to be in snake_case
|
||||
get screen_value() { return this._screenValue; }
|
||||
|
||||
// the setter has to be in snake_case too
|
||||
set screen_value(percent) {
|
||||
percent = clamp(percent, 0, 1);
|
||||
this._screenValue = percent;
|
||||
|
||||
Utils.execAsync(`brightnessctl s ${percent * 100}% -q`)
|
||||
.then(() => {
|
||||
// signals has to be explicity emitted
|
||||
this.emit('screen-changed', percent);
|
||||
this.notify('screen-value');
|
||||
|
||||
// or use Service.changed(propName: string) which does the above two
|
||||
// this.changed('screen');
|
||||
})
|
||||
.catch(print);
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
const current = Number(exec('brightnessctl g'));
|
||||
const max = Number(exec('brightnessctl m'));
|
||||
this._screenValue = current / max;
|
||||
}
|
||||
|
||||
// overwriting connectWidget method, let's you
|
||||
// change the default event that widgets connect to
|
||||
connectWidget(widget, callback, event = 'screen-changed') {
|
||||
super.connectWidget(widget, callback, event);
|
||||
}
|
||||
}
|
||||
|
||||
// the singleton instance
|
||||
const service = new BrightnessService();
|
||||
|
||||
// make it global for easy use with cli
|
||||
globalThis.brightness = service;
|
||||
|
||||
// export to use in other modules
|
||||
export default service;
|
||||
Reference in New Issue
Block a user