#!/bin/sh

#locate the original xdg-open we use as fallback
XDG_OPEN=${WSW_ORIGINAL_XDG_OPEN}
if test -z "$XDG_OPEN"
then
	if test -x "/usr/local/bin/xdg-open"
	then
		XDG_OPEN="/usr/local/bin/xdg-open"
	elif test -x "/usr/bin/xdg-open"
	then
		XDG_OPEN="/usr/bin/xdg-open"
	else
		echo cannot find original xdg-open
		exit 1
	fi
fi

if test -e "$WSW_XDG_OPEN"
then
	if test -n "${WSW_SESSION_ID}"
	then
		if test $# -eq 1
		then
			python "$WSW_XDG_OPEN" "$WSW_SESSION_ID" "$1"
			e=$?
			echo "server_xdg_open returned $e"
			if [ $e == 0 ]; then
				exit 0
			fi
		fi
	fi
fi

exec $XDG_OPEN $@
