#!/system/bin/sh
# action.sh – check thermal props and call clean.sh with typing effect

CLEAN_SCRIPT="/data/adb/modules/RaiRin-AI/cortex/cache/clear.sh"
TMP="/data/local/tmp/RaiRin-AI/tempstate"

# ===== Function for typing effect =====
type_echo() {
    text="$1"
    for i in $(seq 1 ${#text}); do
        printf "%s" "${text:$((i-1)):1}"
        sleep 0.03
    done
    printf "\n"
}

# ===== Run clean.sh =====
echo "======================================="
type_echo "Running cache cleaner..."
if [ -f "$CLEAN_SCRIPT" ]; then
    "$CLEAN_SCRIPT"
    type_echo "Cache successfully cleaned!"
else
    type_echo "clean.sh not found at $CLEAN_SCRIPT"
fi
echo "======================================="

# ===== Check thermal properties =====
type_echo "Checking thermal properties, please wait..."
echo "======================================="
sleep 2
getprop | grep thermal
echo "======================================="

# ===== Check tempstate =====
if [ -f "$TMP" ]; then
    STATE=$(cat "$TMP")
    if [ "$STATE" = "1" ]; then
        type_echo "Thermal Status: DISABLED [High Temperature State]"
    else
        type_echo "Thermal Status: ENABLED [Low Temperature State]"
    fi
else
    type_echo "tempstate file not found at $TMP"
fi
echo "======================================="