#!/bin/bash
TARGET_DIR="$1"
ROOM_NAME="$2"

if [ -z "$TARGET_DIR" ]; then
    exit 1
fi

# Wait and loop endlessly checking for newly created or modified files
inotifywait -m -e close_write -e moved_to "$TARGET_DIR" | while read -r path action file; do
    # Check if user has notifications turned on
    NOTIF_STATUS=$(python3 -c 'import json, os; f=os.path.expanduser("~/.config/ys/config.json"); print(json.load(open(f))["notifications"]) if os.path.exists(f) else print("True")' 2>/dev/null)
    
    if [ "$NOTIF_STATUS" != "False" ]; then
        notify-send "YS Sandbox: $ROOM_NAME" "🆕 File updated: $file" --icon=dialog-information
    fi
done

