#!/bin/sh
set -eu

mkdir -p "${XDG_RUNTIME_DIR:-/tmp/runtime-wechat}"
chmod 700 "${XDG_RUNTIME_DIR:-/tmp/runtime-wechat}" 2>/dev/null || true
xdg-user-dirs-update >/dev/null 2>&1 || true

until xdpyinfo -display "${DISPLAY:-:1}" >/dev/null 2>&1; do
  sleep 0.3
done

if [ -x /opt/wechat/wechat ]; then
  cd /opt/wechat
  exec /opt/wechat/wechat
fi

if command -v wechat >/dev/null 2>&1; then
  exec wechat
fi

echo "Linux WeChat executable not found" >&2
exit 1
