#!/bin/bash

# SearxNG install hooks — wait for settings.yml, apply theme, restart.

searxng_install_post_start()
{
    local app_name="$1"

    local searxng_timeout=10
    local searxng_counter=0
    while [ ! -f "$containers_dir$app_name/searxng-data/settings.yml" ]; do
        if [ "$searxng_counter" -ge "$searxng_timeout" ]; then
            isNotice "File not found after 10 seconds. Exiting..."
            return 0
        fi
        isNotice "Waiting for the file to appear..."
        read -t 1
        searxng_counter=$((searxng_counter + 1))
    done

    local result
    result=$(runFileOp sed -i "s/simple_style: auto/simple_style: $CFG_SEARXNG_THEME/" "$containers_dir$app_name/searxng-data/settings.yml")
    checkSuccess "Changing from light mode to dark mode to avoid eye strain installs"

    dockerComposeRestart $app_name
}
