ags(control-center/quickactions): better code and stuff

This commit is contained in:
retrozinndev
2025-04-14 18:33:12 -03:00
parent 453605afca
commit fe56d3e9ad
+21 -18
View File
@@ -1,18 +1,20 @@
import { execAsync, Process, Variable } from "astal"; import { exec, execAsync, GLib, Variable } from "astal";
import { Gtk, Widget } from "astal/gtk3"; import { Gtk, Widget } from "astal/gtk3";
import AstalHyprland from "gi://AstalHyprland"; import AstalHyprland from "gi://AstalHyprland";
import { Windows } from "../../windows";
const hostname: string = Process.exec("cat /etc/hostname") || "GNU/Linux"; const uptime = new Variable<string>("Just turned on").poll(1000,
const uptime = new Variable<string>("Just turned on") () => exec("uptime -p").replace(/^up /, "")
.poll(1000, () => { );
return Process.exec("uptime -p").replace(/^up /, "")
})();
function LockButton(): Widget.Button { function LockButton(): Widget.Button {
return new Widget.Button({ return new Widget.Button({
className: "nf", className: "nf",
label: "󰌾", label: "󰌾",
onClick: () => AstalHyprland.get_default().dispatch("exec", "hyprlock") onClick: () => {
Windows.close("control-center");
AstalHyprland.get_default().dispatch("exec", "hyprlock");
}
} as Widget.ButtonProps) } as Widget.ButtonProps)
} }
@@ -22,7 +24,7 @@ function ColorPickerButton(): Widget.Button {
label: "󰴱", label: "󰴱",
onClick: () => AstalHyprland.get_default().dispatch( onClick: () => AstalHyprland.get_default().dispatch(
"exec", "exec",
"sh $HOME/.config/eww/scripts/color-picker.sh" "sh $HOME/.config/hypr/scripts/color-picker.sh"
) )
} as Widget.ButtonProps) } as Widget.ButtonProps)
} }
@@ -31,10 +33,11 @@ function ScreenshotButton(): Widget.Button {
return new Widget.Button({ return new Widget.Button({
className: "nf", className: "nf",
label: "󰹑", label: "󰹑",
onClick: () => Process.exec_async( onClick: () => execAsync(
"bash -c 'hyprshot -m region -o $HOME/Screenshots'", `hyprshot -m region -o ${GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES) ?
() => {} `${GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES)}/Screenshots`
) : `${GLib.get_home_dir()}/Screenshots`
}`)
} as Widget.ButtonProps); } as Widget.ButtonProps);
} }
@@ -42,9 +45,9 @@ function SelectWallpaperButton(): Widget.Button {
return new Widget.Button({ return new Widget.Button({
className: "nf", className: "nf",
label: "󰸉", label: "󰸉",
onClick: () => Process.exec_async( onClick: () => execAsync(
"bash -c 'sh $HOME/.config/hypr/scripts/change-wallpaper.sh'", `sh ${GLib.get_user_config_dir() || `${GLib.get_home_dir()}/.config`
() => {} }/hypr/scripts/change-wallpaper.sh`
) )
} as Widget.ButtonProps); } as Widget.ButtonProps);
} }
@@ -53,7 +56,7 @@ function LogoutButton(): Widget.Button {
return new Widget.Button({ return new Widget.Button({
className: "nf", className: "nf",
label: "󰗽", label: "󰗽",
onClick: () => execAsync("astal open logout-menu") onClick: () => Windows.open("logout-menu")
} as Widget.ButtonProps); } as Widget.ButtonProps);
} }
@@ -69,12 +72,12 @@ export const QuickActions = () => new Widget.Box({
new Widget.Label({ new Widget.Label({
className: "hostname", className: "hostname",
xalign: 0, xalign: 0,
label: hostname.toString() label: GLib.get_host_name()
} as Widget.LabelProps), } as Widget.LabelProps),
new Widget.Label({ new Widget.Label({
className: "uptime", className: "uptime",
xalign: 0, xalign: 0,
label: uptime.as((uptime: string) => `󱡢 ${uptime}`) label: uptime().as((uptime: string) => `󱡢 ${uptime}`)
} as Widget.LabelProps) } as Widget.LabelProps)
] ]
} as Widget.BoxProps), } as Widget.BoxProps),