#!/bin/bash

SCRIPTS_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source $SCRIPTS_DIR/config.sh

directory=$WALLPAPER_DIR
monitor=`hyprctl monitors | grep Monitor | awk '{print $2}'`

if [ -d "$directory" ]; then
    random_background=$(ls $directory/* | shuf -n 1)
	file_extension="${random_background##*.}"
	echo "File extension: $file_extension"
	notify-send "Wallpaper Switched to :" "$random_background" --icon=dialog-information -t 3000
    hyprctl hyprpaper unload all
    hyprctl hyprpaper preload $random_background
    hyprctl hyprpaper wallpaper "$monitor, $random_background"
else
	notify-send "Wallpaper Switch : Directory Not Found" "$WALLPAPER_DIR" --icon=dialog-information -t 3000
fi