#!/bin/bash

BASH_PATH=$(cd `dirname $0`;pwd)
LIB_PATH="${BASH_PATH}/rtl"

#export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$BASH_PATH
#export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIB_PATH

IS_BUS="1"
if [ "e`cat /etc/issue | grep "Ubuntu 20"`" != "e" ];then
    IS_BUS="0"
fi
RJJH_PARA=$@
#JEMALLOC1_PATH=$BASH_PATH/zav/libjemalloc.so.1
#JEMALLOC2_PATH=$BASH_PATH/zav/libjemalloc.so.2

if test -f $JEMALLOC1_PATH ; then
    export LD_PRELOAD=$JEMALLOC1_PATH
elif test -f $JEMALLOC2_PATH ; then
    export LD_PRELOAD=$JEMALLOC2_PATH
fi

# init essential files
if [ ! -f "${BASH_PATH}/RJJHetc/JingyunUiConfig.ini" ];then
    cp "${BASH_PATH}/JingyunUiConfig.ini" ${BASH_PATH}/RJJHetc/
fi

if [[ `command -v ibus` && $IS_BUS == "1" ]] ; then
    export GTK_IM_MODULE=ibus
    export QT_IM_MODULE=ibus
    export XMODIFIERS=@im=ibus
fi

if [[ `command -v fcitx` && $IS_BUS == "1" ]] ; then
    typewriting="-platforminputcontext fcitx"
fi

if [ -f $BASH_PATH/insinfo/desktop_path  ]; then
	desktop_path=`cat $BASH_PATH/insinfo/desktop_path | head -n1`
	if [ -f $desktop_path ]; then
		if [ -f /etc/issue ] ;then
			gio set $desktop_path metadata::trusted yes
			# 自Ubuntu 20.04开始，桌面快捷方式加白由yes变为true
			local_version=`cat /etc/issue | head -n1 | cut -b 1-12`
			if [[ "${local_version}" > "Ubuntu 20.03" ]];then
				gio set $desktop_path metadata::trusted true
			fi
		fi
	fi
fi
exec $BASH_PATH/JYNRJJH2 "$RJJH_PARA" -platform xcb "$typewriting"
