#!/bin/bash
##################################################################
#                                                                #
#  Use this startup script to load all depending conkies.        #
#  If for some reason one of the conkies is not loaded, all      #
#  conkies will be unloaded.                                     #
#                                                                #
#  Do not change filenames or window titles of the conkies!      #
#  Always use the .conky extention!                              #
#  The scripts depend heavy on them!                             #
#                                                                #
#  Scripted by Koentje   (remon@cobrasoft.nl)                    #
#                                                                #
#  PLEASE DO NOT EDIT THIS SCRIPT !!!                            #
#                                                 version: 2.6   #
##################################################################

# Get real path to working folder
  scrpath=$(readlink -f $0)
  workdir=$(dirname $scrpath)
  cd "$workdir"


#source "./player.ini"


# Check if independencies are installed
  if [ "$(which conky)" = "" ]; then echo -e "\e[31mERROR\e[m 'conky' not installed!  DUH!!!\n"; exit 1; fi


# Get all *.conky files into array
  while read -r files
  do
      conkies+=("${files##*/}")
  done< <(find "$workdir" -maxdepth 1 -type f -name "*.conky" | sort)


# Number of conkies
  for index in ${!conkies[@]}; do
      nr_conkies=$(echo "$index")
  done
  nr_conkies=$((nr_conkies+1))


# Load all conkies
z=1
function load_conkies() {
    echo -e "\n\e[33m  -- Conky Spectrum Bass v$(cat ./spectrum-bass.conky | grep 'version=' | awk -F'=' '{print $2}') -- \n\e[m"
    touch "./tempfiles/load_conkies"
    for conky in "${conkies[@]}"
    do
        echo -e "loading: $z/$nr_conkies  \e[32m$conky\e[m"
        if [ "$z" -lt "$nr_conkies" ]; then
          conky -c "$conky" &
          sleep 1
        else
          conky -c "$conky"
          ./stop
        fi
      z=$((z+1))
    done
    z=1
}


# Kill all conkies
function kill_conkies() {
   ./stop
}

load_conkies
