#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)

. /etc/profile

ui_state() {
  clear >/dev/console
  systemctl ${1} ${UI_SERVICE}
}

if [ "${UI_SERVICE}" = "weston.service" ]
then
  if [ -f "${*}" ]
  then
    RUN=$(echo ${*} | sed 's# #\\ #g')
    weston-terminal --command="${RUN}"
  else
    weston-terminal --command="${*}"
  fi
elif echo "${UI_SERVICE}" | grep "sway"; then
  if [ -f "${*}" ]
  then
    RUN=$(echo ${*} | sed 's# #\\ #g')
    foot ${RUN}  
  else
    foot ${*}
  fi
else
  ui_state stop
  clear >/dev/console
  $* >/dev/console
  if [ "$?" == 0 ]
  then
    ui_state start
    exit 0
  else
    "$*" >/dev/console
    ui_state start
    exit 0
  fi
fi

