#!/bin/sh # ─< Check if the given command exists silently >───────────────────────────────────────── command_exists() { command -v "$@" >/dev/null 2>&1 } pkill swaync # Paths and configuration SCRIPTS_DIR="$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" } # Initialize system modules initialize_modules() { # ─< hyprpanel, waybar, gBar >──────────────────────────────────────────────────────────── bar="hyprpanel" modules=" copyq nwg-look swww $bar wob redshift " for module in $modules; do if command_exists "$module"; then log_notify "low" "$module" "Initializing..." case $module in waybar | flameshot) pkill "$module" 2>/dev/null "$module" & ;; hyprpanel) hyprpanel & ;; 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 & ;; swww) swww-daemon & if ! swww query; then swww init fi ;; redshift) pkill redshift 2>/dev/null sh "$SCRIPTS_DIR/redshift.sh" ;; wob) fifo="/tmp/$HYPRLAND_INSTANCE_SIGNATURE.wob" rm -f "$fifo" mkfifo "$fifo" tail -f "$fifo" | wob & ;; esac else log_notify "critical" "ERROR" "$module not found!" fi sleep 0.5 done log_notify "normal" "INFO" "System modules initialized." } # Start polkit authentication agent initialize_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 initialize_xdg_portals() { 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 } envS() { terminals="ghostty wezterm kitty" for envTerminal in "$terminals"; do if command_exists $envTerminal; then export HYPR_TERMINAL="$envTerminal" log_notify "normal" "Terminal" "..is set to $envTerminal" break fi done } # Main initialization function main() { sleep 0.5 initialize_xdg_portals initialize_modules initialize_polkit envS } main