[AGS] Bar: Done (WiFi still missing, will be added at some later point)
This commit is contained in:
82
config/astal/util/brightness.ts
Normal file
82
config/astal/util/brightness.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
import GObject, { register, property } from "astal/gobject"
|
||||
import { monitorFile, readFileAsync } from "astal/file"
|
||||
import { exec, execAsync } from "astal/process"
|
||||
|
||||
const get = (args: string) => Number(exec(`brightnessctl ${args}`))
|
||||
const screen = exec(`bash -c "ls -w1 /sys/class/backlight | head -1"`)
|
||||
const kbd = exec(`bash -c "ls -w1 /sys/class/leds | head -1"`)
|
||||
|
||||
@register({ GTypeName: "Brightness" })
|
||||
export default class Brightness extends GObject.Object {
|
||||
static instance: Brightness
|
||||
static get_default() {
|
||||
if (!this.instance)
|
||||
this.instance = new Brightness()
|
||||
|
||||
return this.instance
|
||||
}
|
||||
|
||||
#kbdMax = get(`--device ${kbd} max`)
|
||||
#kbd = get(`--device ${kbd} get`)
|
||||
#screenMax = get("max")
|
||||
#screen = get("get") / (get("max") || 1)
|
||||
#screenAvailable = false
|
||||
|
||||
@property(Boolean)
|
||||
get screenAvailable() { return this.#screenAvailable }
|
||||
|
||||
@property(Number)
|
||||
get kbd() { return this.#kbd }
|
||||
|
||||
set kbd(value) {
|
||||
if (value < 0 || value > this.#kbdMax)
|
||||
return
|
||||
|
||||
execAsync(`brightnessctl -d ${kbd} s ${value} -q`).then(() => {
|
||||
this.#kbd = value
|
||||
this.notify("kbd")
|
||||
})
|
||||
}
|
||||
|
||||
@property(Number)
|
||||
get screen() { return this.#screen }
|
||||
|
||||
set screen(percent) {
|
||||
if (percent < 0)
|
||||
percent = 0
|
||||
|
||||
if (percent > 1)
|
||||
percent = 1
|
||||
|
||||
execAsync(`brightnessctl set ${Math.floor(percent * 100)}% -q`).then(() => {
|
||||
this.#screen = percent
|
||||
this.notify("screen")
|
||||
})
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
|
||||
const screenPath = `/sys/class/backlight/${screen}/brightness`
|
||||
const kbdPath = `/sys/class/leds/${kbd}/brightness`
|
||||
|
||||
monitorFile(screenPath, async f => {
|
||||
const v = await readFileAsync(f)
|
||||
this.#screen = Number(v) / this.#screenMax
|
||||
this.notify("screen")
|
||||
})
|
||||
|
||||
monitorFile(kbdPath, async f => {
|
||||
const v = await readFileAsync(f)
|
||||
this.#kbd = Number(v) / this.#kbdMax
|
||||
this.notify("kbd")
|
||||
})
|
||||
|
||||
// Check if there is a screen available
|
||||
try {
|
||||
get( 'g -c backlight' );
|
||||
} catch ( _ ) {
|
||||
this.#screenAvailable = false;
|
||||
}
|
||||
}
|
||||
}
|
4
config/astal/util/colours.scss
Normal file
4
config/astal/util/colours.scss
Normal file
@@ -0,0 +1,4 @@
|
||||
$fg-color: #{"@theme_fg_color"};
|
||||
$bg-color: #{"@theme_bg_color"};
|
||||
$accent-color: #202050;
|
||||
$accent-color-2: #202080;
|
3
config/astal/util/state.ts
Normal file
3
config/astal/util/state.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { Variable } from "astal";
|
||||
|
||||
export const quickActionsState = Variable( false );
|
Reference in New Issue
Block a user