diff --git a/indra/newview/linux_tools/handle_secondlifeprotocol.sh b/indra/newview/linux_tools/handle_secondlifeprotocol.sh index 53d875ee0736dcf9a2d0435c39dc8c8ba910ea6a..6038e259f850410ca5253c04fe694f66edc90fc7 100755 --- a/indra/newview/linux_tools/handle_secondlifeprotocol.sh +++ b/indra/newview/linux_tools/handle_secondlifeprotocol.sh @@ -1,17 +1,26 @@ #!/bin/bash -# Send a URL of the form secondlife://... to Second Life. +# Send a URL of the form secondlife://... to any running viewer, if not, launch Alchemy viewer. # -URL="$1" +sl_url="$*" -if [ -z "$URL" ]; then - echo Usage: $0 secondlife://... - exit +echo "Got SLURL: ${sl_url}" +if [ -z "${sl_url}" ]; then + echo "Usage: $0 secondlife:// ..." + exit fi -RUN_PATH=`dirname "$0" || echo .` -cd "${RUN_PATH}/.." - -exec ./alchemy -url \'"${URL}"\' +run_path=$(dirname "$0" || echo .) +#Poll DBus to get a list of registered services, then look through the list for the Second Life API Service - if present, this means a viewer is running, if not, then no viewer is running and a new instance should be launched +service_name="com.secondlife.ViewerAppAPIService" #Name of Second Life DBus service. This should be the same across all viewers. +if dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListNames | grep -q "${service_name}"; then + echo "Second Life running, sending to DBus..."; + exec dbus-send --type=method_call --dest="${service_name}" /com/secondlife/ViewerAppAPI com.secondlife.ViewerAppAPI.GoSLURL string:"${sl_url}" +else + echo "Second Life not running, launching new instance..."; + cd "${run_path}"/.. || exit + #Go to .sh location (/etc), then up a directory to the viewer location + exec ./alchemy -url "${sl_url}" +fi diff --git a/indra/newview/linux_tools/refresh_desktop_app_entry.sh b/indra/newview/linux_tools/refresh_desktop_app_entry.sh index 24ae0538d5a119c557129c481d8fe70aa3bad2cc..c65b58d4c9e7d4ba3297040889935eb677f6ba50 100755 --- a/indra/newview/linux_tools/refresh_desktop_app_entry.sh +++ b/indra/newview/linux_tools/refresh_desktop_app_entry.sh @@ -1,16 +1,16 @@ #!/bin/bash -SCRIPTSRC=`readlink -f "$0" || echo "$0"` -RUN_PATH=`dirname "${SCRIPTSRC}" || echo .` +SCRIPTSRC="$(readlink -f "$0" || echo "$0")" +RUN_PATH="$(dirname "${SCRIPTSRC}" || echo .)" -install_prefix=${RUN_PATH}/.. +install_prefix="${RUN_PATH}"/.. function install_desktop_entry() { - local installation_prefix="$1" - local desktop_entries_dir="$2" + local installation_prefix="${1}" + local desktop_entries_dir="${2}" - local desktop_entry="\ + local desktop_entry="\ [Desktop Entry]\n\ Name=Alchemy\n\ Comment=Client for the On-line Virtual World, Second Life\n\ @@ -23,15 +23,15 @@ StartupNotify=true\n\ StartupWMClass=Alchemy\n\ X-Desktop-File-Install-Version=3.0" - echo " - Installing menu entries in ${desktop_entries_dir}" - mkdir -vp "${desktop_entries_dir}" - echo -e $desktop_entry > "${desktop_entries_dir}/alchemy-viewer.desktop" || "Failed to install application menu!" + echo " - Installing menu entries in ${desktop_entries_dir}" + mkdir -vp "${desktop_entries_dir}" + echo -e "${desktop_entry}" > "${desktop_entries_dir}/alchemy-viewer.desktop" || "Failed to install application menu!" } if [ "$UID" == "0" ]; then - # system-wide - install_desktop_entry "$install_prefix" /usr/local/share/applications + # system-wide + install_desktop_entry "${install_prefix}" /usr/local/share/applications else - # user-specific - install_desktop_entry "$install_prefix" "$HOME/.local/share/applications" + # user-specific + install_desktop_entry "${install_prefix}" "${HOME}/.local/share/applications" fi diff --git a/indra/newview/linux_tools/register_secondlifeprotocol.sh b/indra/newview/linux_tools/register_secondlifeprotocol.sh index 7f73ce48e2dfbab549fe2388c168822499f08c1a..e1e3e9395ecead956212fc79f61086e6b08eabb1 100755 --- a/indra/newview/linux_tools/register_secondlifeprotocol.sh +++ b/indra/newview/linux_tools/register_secondlifeprotocol.sh @@ -4,45 +4,74 @@ # URLs of the form secondlife://... # -HANDLER="$1" +desired_handler="${1}" -RUN_PATH=`dirname "$0" || echo .` -cd "${RUN_PATH}/.." +print() { + log_prefix="RegisterSLProtocol:" + echo -e "${log_prefix} $*" +} +run_path=$(dirname "$0" || echo .) +cd "${run_path}/.." || exit -if [ -z "$HANDLER" ]; then - HANDLER=`pwd`/etc/handle_secondlifeprotocol.sh +if [ -z "${desired_handler}" ]; then + desired_handler="$(pwd)/etc/handle_secondlifeprotocol.sh" fi -# Register handler for GNOME-aware apps -LLGCONFTOOL=gconftool -if which ${LLGCONFTOOL} >/dev/null; then - (${LLGCONFTOOL} -s -t string /desktop/gnome/url-handlers/secondlife/command "${HANDLER} \"%s\"" && ${LLGCONFTOOL} -s -t bool /desktop/gnome/url-handlers/secondlife/enabled true) || echo Warning: Did not register secondlife:// handler with GNOME: ${LLGCONFTOOL} failed. -else - echo Warning: Did not register secondlife:// handler with GNOME: ${LLGCONFTOOL} not found. -fi +# Ensure the handle_secondlifeprotocol.sh file is executeable (otherwise, xdg-mime won't work) +chmod +x "$desired_handler" -# Register handler for KDE-aware apps -for LLKDECONFIG in kde-config kde4-config; do - if [ `which $LLKDECONFIG` ]; then - LLKDEPROTODIR=`$LLKDECONFIG --path services | cut -d ':' -f 1` - if [ -d "$LLKDEPROTODIR" ]; then - LLKDEPROTOFILE=${LLKDEPROTODIR}/secondlife.protocol - cat > ${LLKDEPROTOFILE} <<EOF || echo Warning: Did not register secondlife:// handler with KDE: Could not write ${LLKDEPROTOFILE} -[Protocol] -exec=${HANDLER} '%u' -protocol=secondlife -input=none -output=none -helper=true -listing= -reading=false -writing=false -makedir=false -deleting=false -EOF - else - echo Warning: Did not register secondlife:// handler with KDE: Directory $LLKDEPROTODIR does not exist. - fi - fi -done +# Check if xdg-mime is present, if so, use it to register new protocol. +if command -v xdg-mime query default x-scheme-handler/secondlife >/dev/null 2>&1; then + urlhandler=$(xdg-mime query default x-scheme-handler/secondlife) + localappdir="${HOME}/.local/share/applications" + newhandler="secondlifeprotocol_$(basename "$(dirname "${desired_handler}")").desktop" + handlerpath="${localappdir}/${newhandler}" + cat >"${handlerpath}" <<EOFnew || print "Warning: Did not register secondlife:// handler with xdg-mime: Could not write $newhandler"s +[Desktop Entry] +Version=1.4 +Name="Second Life URL handler" +Comment="secondlife:// URL handler" +Type=Application +Exec=$desired_handler %u +Terminal=false +StartupNotify=true +NoDisplay=true +MimeType=x-scheme-handler/secondlife +EOFnew + # TODO: use absolute path for the desktop file + # TODO: Ensure that multiple channels behave properly due to different desktop file names in /usr/share/applications/ + # TODO: Better detection of what the handler actually is, as other viewer projects may use the same filename + if [ -z "${urlhandler}" ]; then + print No SLURL handler currently registered, creating new... + else + #xdg-mime uninstall $localappdir/$urlhandler + #Clean up handlers from other viewers + if [ "${urlhandler}" != "${newhandler}" ]; then + print "Current SLURL Handler: ${urlhandler} - Setting ${newhandler} as the new default..." + mv "${localappdir}"/"${urlhandler}" "${localappdir}"/"${urlhandler}".bak + else + print "SLURL Handler has not changed, leaving as-is." + fi + fi + xdg-mime default "${newhandler}" x-scheme-handler/secondlife + if command -v update-desktop-database >/dev/null 2>&1; then + update-desktop-database "${localappdir}" + print "Registered ${desired_handler} as secondlife:// protocol handler with xdg-mime." + else + print "Warning: Cannot update desktop database, command missing - installation may be incomplete." + fi +else + print "Warning: Did not register secondlife:// handler with xdg-mime: Package not found." + # TODO: use dconf or another modern alternative + gconftool=$(command -v "${LLGCONFTOOL:=gconftool-2}") + if [[ -n "${gconftool}" ]]; then + print "=== USING DEPRECATED GCONF API ===" + if "${gconftool}" -s -t string /desktop/gnome/url-handlers/secondlife/command "${desired_handler} \"%s\"" && + ${gconftool} -s -t bool /desktop/gnome/url-handlers/secondlife/enabled true; then + print "Registered ${desired_handler} as secondlife:// handler with (deprecated) gconf." + else + print "Failed to register secondlife:// handler with (deprecated) gconf." + fi + fi +fi