#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)

# Minimal OS variable loading for performance
. /etc/profile.d/001-functions

#tocon "Configuring display..."

### Variables may need to be device specific here.
BRIGHTNESS=$(get_setting system.brightness)
if [[ -z ${BRIGHTNESS} ]]
then
  BRIGHTNESS="6"
fi

# Ensure user doesn't get "locked out" with super low brightness
if [[ "${BRIGHTNESS}" = "0" ]]
then
  BRIGHTNESS=1
fi

brightness set ${BRIGHTNESS}

### Set the aspect ratio in ES.
ASPECT=$(get_aspect_ratio)

ES_CONFIG="/storage/.config/emulationstation/es_settings.cfg"
ES_ASPECT="${ASPECT/:/-}"
if [ "$(grep subset.aspect-ratio ${ES_CONFIG})" ]
then
  sed -i 's|<string name="subset.aspect-ratio".*$|<string name="subset.aspect-ratio" value="'${ES_ASPECT}'"/>|g' ${ES_CONFIG}
else
  sed -i '/<\/config>/i \\t<string name="subset.aspect-ratio" value="'${ES_ASPECT}'"/>' ${ES_CONFIG}
fi

