#!/bin/bash

# This file is sourced by /etc/X11/fly-dm/Xsession, not executed.

echo fly misc setup  `date '+%F %T.%3N'`

#export GTK_USE_PORTAL=1

#by A.Kovalenko (BT-10204)
if [ -d /parsecfs ]; then
 rm -f /run/user/$(id -u)/pulse/native
fi

IS_TOUCH=
fly-wmfunc FLYWM_GET_TOUCHSCREEN > /dev/null
if [ $? -eq "0" ]; then
 IS_TOUCH=yes
 export MOZ_USE_XINPUT2=1
fi

if [ -f /etc/X11/fly-dm/dpi ]; then
  hdpi=`cat /etc/X11/fly-dm/dpi`
  if [ ! -z "$hdpi" ]; then
    if [ "$hdpi" -gt "120" ]; then
      export QT_AUTO_SCREEN_SCALE_FACTOR=1
      export QT_ENABLE_HIGHDPI_SCALING=1
    fi
  fi
fi

#alex: check free space (optional)
/usr/bin/fly-dm-check-space.sh "$HOME"

#alex: check home rights at the first start
if [ -z $FLY_KIOSK_CONFIG_DIR ]; then
  if [ ! -d $HOME/.fly ]; then
    mkdir $HOME/test
    if [ ! -d $HOME/test ]; then
      if [ "$LANG" = "ru_RU.UTF-8" ]; then
        HOME_CAPTION="Внимание"
        HOME_MESSAGE="Ваш домашний каталог защищен от записи.\nВсе результаты будут утрачены после выхода."
        HOME_ERR="Не задана XDG_RUNTIME_DIR"
      else
        HOME_CAPTION="Attention"
        HOME_MESSAGE="You home directory is not writable.\nAll results will be lost after exit."
        HOME_ERR="XDG_RUNTIME_DIR is undefined"
      fi
      if [ ! -z $XDG_RUNTIME_DIR ]; then
        export HOME=$XDG_RUNTIME_DIR
        fly-dialog --caption "$HOME_CAPTION" --error "$HOME_MESSAGE"
      else
        fly-dialog --caption "$HOME_CAPTION" --error "$HOME_ERR"
        mkdir /tmp/$USER
        export XDG_RUNTIME_DIR=/tmp/$USER
        export HOME=/tmp/$USER
      fi
    else
      rmdir $HOME/test
    fi
  fi
fi

echo fly misc setup finished  `date '+%F %T.%3N'`
