From 2dd4f2321c07f820ecad231a83029a397e2fb28c Mon Sep 17 00:00:00 2001 From: pika Date: Sun, 8 Jun 2025 10:43:01 +0200 Subject: [PATCH] wip --- .scripts/init | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100755 .scripts/init diff --git a/.scripts/init b/.scripts/init new file mode 100755 index 0000000..8f62422 --- /dev/null +++ b/.scripts/init @@ -0,0 +1,143 @@ +#!/usr/bin/env bash + +# ─< Check if the given command exists silently >───────────────────────────────────────── +command-exists() { + command -v "$@" >/dev/null 2>&1 +} + +SCRIPTS="$HOME/.config/hypr/.scripts" + +# Logging helper +log_notify() { + level="$1" # e.g., low, normal, critical + title="$2" + message="$3" + notify-send -u "$level" "$title" "$message" +} + +setup-desktop() { + # if command-exists qs; then + # qs + # else + bash "$SCRIPTS/bar" + log_notify low "Bar" "Initializing.." + # fi + + log_notify low "Wallpaper" "Initializing.." + bash "$SCRIPTS/wallpaper" + + local modules + + modules=( + "copyq" + "nwg-look" + "lxappearance" + "wob" + "redshift" + ) + + for module in "${modules[@]}"; do + if command-exists $module; then + log_notify low "$module" "Initializing.." + + case $module in + copyq) + pkill copyq 2>/dev/null + copyq --start-server + sleep 1 + if ! pgrep -x copyq >/dev/null; then + log_notify "critical" "ERROR" "CopyQ failed to start. Retrying..." + copyq --start-server + fi + ;; + lxappearance) + lxappearance >/dev/null 2>&1 & + ;; + 'nwg-look') + nwg-look -a >/dev/null 2>&1 & + ;; + # handled in $SCRIPTS/bar + # swww) + # swww-daemon & + # if ! swww query; then + # swww init + # fi + # ;; + redshift) + pkill redshift 2>/dev/null + sh "$SCRIPTS/redshift.sh" + ;; + wob) + local fifo="/tmp/$HYPRLAND_INSTANCE_SIGNATURE.wob" + rm -f "$fifo" + mkfifo "$fifo" + tail -f "$fifo" | wob & + ;; + esac + fi + done +} + +# Start polkit authentication agent +init-polkit() { + agents=" + /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1 + /usr/lib/polkit-kde-authentication-agent-1 + /usr/libexec/polkit-gnome-authentication-agent-1 + /usr/lib/x86_64-linux-gnu/libexec/polkit-kde-authentication-agent-1 + /usr/lib/policykit-1-gnome/polkit-gnome-authentication-agent-1 + /usr/lib/polkit-1/polkit-agent-helper-1 + " + + for agent in $agents; do + if [ -x "$agent" ]; then + log_notify "normal" "INFO" "Starting Polkit agent: $(basename "$agent")" + "$agent" & + return 0 + fi + done + + log_notify "low" "WARNING" "No Polkit authentication agent found. Please install one." + return 1 +} + +# Initialize XDG desktop portals +init-xdg-portal() { + xdg_hyprland="/usr/lib/xdg-desktop-portal-hyprland" + xdg_portal="/usr/lib/xdg-desktop-portal" + + if [ -x "$xdg_hyprland" ]; then + killall xdg-desktop-portal-hyprland xdg-desktop-portal-wlr xdg-desktop-portal 2>/dev/null + sleep 1 + "$xdg_hyprland" & + sleep 1 + "$xdg_portal" & + sleep 1 + dbus-update-activation-environment --systemd --all & + log_notify "normal" "INFO" "XDG desktop portals initialized." + else + log_notify "low" "WARNING" "xdg-desktop-portal-hyprland not found. Please install it." + fi +} + +main() { + if command_exists swaync; then + pkill swaync + fi + + if setup-desktop; then + log_notify "normal" "INFO" "System modules initialized." + else + log_notify "critical" "INFO" "System module initialization exited with errors.." + fi + + if [ -x "/usr/lib/hyprpolkitagent" ]; then + systemctl --user start hyprpolkitagent + else + init-polkit + fi + + init-xdg-portal +} + +main