#!/bin/bash

# sleep for a little while to avoid duplicate startup
function autostart()
{
    local LOCAL_DISPLAY=$DISPLAY
    if [ -n "$LOCAL_DISPLAY" ];then
        /usr/bin/fcitx -d
    else
        sleep 2
        autostart
    fi
}

autostart
sleep 2

# Test whether fcitx is running correctly with dbus...
fcitx-remote > /dev/null 2>&1

if [ $? = "1" ]; then
    echo "Fcitx seems is not running"
    /usr/bin/fcitx -d
else
    echo "Fcitx is running correctly."
fi
