import { Astal, Gtk, Gdk } from "astal/gtk4";
import { Variable, GLib, bind, execAsync, exec } from "astal";
import Battery from "gi://AstalBattery";
import Bluetooth from "gi://AstalBluetooth";
import Wp from "gi://AstalWp";
import Network from "gi://AstalNetwork";
import Hyprland from "gi://AstalHyprland";
import Brightness from "../service/brightness";
const network = Network.get_default();
const wifi = bind(network, "wifi");
const hypr = Hyprland.get_default();
const bluetooth = Bluetooth.get_default();
function Wifi() {
return (
{wifi.as(
(wifi) =>
wifi && (
),
)}
);
}
function Audio() {
const speaker = Wp.get_default()?.audio.defaultSpeaker!;
return (
);
}
function AudioSlider() {
const speaker = Wp.get_default()?.audio.defaultSpeaker!;
return (
{
speaker.volume = value;
}}
value={bind(speaker, "volume")}
/>
);
}
function BrightnessSlider() {
const brightness = Brightness.get_default();
return (
{
brightness.screen = value;
}}
value={bind(brightness, "screen")}
/>
);
}
function BatteryLevel() {
const bat = Battery.get_default();
return (
);
}
function Time({ format = "%H:%M - %A %e." }) {
const time = Variable("").poll(
1000,
() => GLib.DateTime.new_now_local().format(format)!,
);
return (
);
}
function IdleInhibitor() {
const icon = Variable(getIcon());
function getIcon() {
const state = exec("matcha --status");
const enabled = state.match(/on/g);
return enabled ? "my-caffeine-on-symbolic" : "my-caffeine-off-symbolic";
}
function toggle() {
exec("matcha --toggle");
icon.set(getIcon());
}
return (
);
}
function QuickSettings() {
return (
{wifi.as(
(wifi) =>
wifi && (
);
}
function Workspaces() {
return (
{bind(hypr, "workspaces").as((wss) =>
wss
.filter((ws) => !(ws.id >= -99 && ws.id <= -2)) // filter out special workspaces
.sort((a, b) => a.id - b.id)
.map((ws) => (
)),
)}
);
}
export default function Bar(monitor: Gdk.Monitor) {
const { TOP, LEFT, RIGHT } = Astal.WindowAnchor;
return (
);
}