#!/bin/sh

if [ $# -lt 1 ]; then
    echo "Usage: launch_xdg_portal [portal_name]
    [portal_name] can be either 'wlr', 'gtk', 'gnome' or 'kde'"
    exit
fi

portal_binary="/usr/libexec/xdg-desktop-portal-${1}"
[ ! -f "${portal_binary}" ] && echo "${portal_binary} file is invalid." && exit 1

if [ -n "$(pgrep -x "${portal_binary}")" ]; then
    exec ${portal_binary} -r
else
    exec ${portal_binary}
fi
