#!/bin/bash

. /usr/bin/fly-tablet-env

#QT_IM_MODULE - Name of virtual keyboard.
#   This property is taken from /usr/share/fly-mobile/vkbd/vkbd.conf.
#   If not empty environment variable will be set.
#   fly-qml-components using this to build root component.

#FLY_LAUNCHER_SETTINGS - Path to launcher QSettings (~/.config/rusbitech/fly-launcher.conf).

#FLY_PHONE_LOW_EFFECTS - If set ColorOverlay will be invisible.
#   Rectangles will be shown instead of shadows. Using 2drenderer sets this value to true.

#FLY_PHONE_DPR - QML scale factor.
#   If not set it will be calculated based on physical dpi or taken from settings.
#   Env value overrides settings value.

#FLY_PHONE_VOLUME_CONTROL - Base amixer simple control.
#   If not set it will be autoset by launcher to Master
#   or Speaker or first control found in amixer scontrols

#FLY_PHONE_KILL_AFTER - Default 3000(ms).
#   When closing windows in pager kill(SIGTERM) is called.
#   And after 3000ms if window(app) still exists then it recieve SIGKILL(unblockable)

#FLY_PHONE_VERBOSE - Verbose mode.

if test -e /usr/share/fly-phone/vkbd/vkbd.conf; then
 export QT_IM_MODULE=`grep QT_IM_MODULE /usr/share/fly-phone/vkbd/vkbd.conf | cut -d "=" -f 2`
fi

if test -x /usr/bin/compton; then
 /usr/bin/compton --config /etc/xdg/compton.fly-mobile.conf &
else
 if test -x /usr/bin/fly-kompmgr; then
  /usr/bin/fly-kompmgr &
 fi
fi

#export QT_AUTO_SCREEN_SCALE_FACTOR=0

#export QT_VIRTUALKEYBOARD_DESKTOP_DISABLE=1 - Fixing fly-vkbd and qtvirtualkeyboard conflict.
#    Fly-vkbd doesn't autoshow in a mobile session, so it's no longer necessary.

dbus-update-activation-environment --all
#Fixed a bug that caused the qtvirtualkeyboard plugin to not open in some applications on text input focus

if /usr/share/fly-mobile/scripts/oneplus/check-is-oneplus.sh;
then
    if [ -f /etc/pulse/astra-touch.pa ] &&
       [ -f /etc/pulse/astra-touch-client.conf ];
    then
        export PULSE_SCRIPT=/etc/pulse/astra-touch.pa
        export PULSE_CLIENTCONFIG=/etc/pulse/astra-touch-client.conf

        export PULSE_PROP='media.role=multimedia'
        export PULSE_PLAYBACK_CORK_STALLED=1
        #Pulseadio optimizations

        pulseaudio --start

        export IS_ONEPLUS=1
    fi
fi
#Need for sound and microphone work on Oneplus

/usr/bin/fly-wm --rcfile $HOME/.fly/ru_RU.UTF-8.fly-wmrc.fly-mobile --execOnly fly-launcher
