Skip to content
Snippets Groups Projects
Commit 0ee33d5f authored by Xenhat Hex's avatar Xenhat Hex Committed by Rye Mutt
Browse files

!52 takeover: Fix shellcheck warnings.

Various fixes and edits. Spaces in SLURL are broken atm.

Revert quoting change in handler files

Additional protocol handler tweaks
This commit is mostly about refining the messages sent to the log.
No functional changes.
parent 3b18e297
No related branches found
No related tags found
No related merge requests found
...@@ -3,28 +3,24 @@ ...@@ -3,28 +3,24 @@
# Send a URL of the form secondlife://... to any running viewer, if not, launch Alchemy viewer. # 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 "Got SLURL: ${sl_url}"
if [ -z "${sl_url}" ]; then
echo "Usage: $0 secondlife:// ..." echo "Usage: $0 secondlife:// ..."
exit exit
fi fi
RUN_PATH=$(dirname "$0" || echo .) run_path=$(dirname "$0" || echo .)
#ch "${RUN_PATH}"
#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 #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
LIST=$(dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListNames 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
SERVICE="com.secondlife.ViewerAppAPIService" #Name of Second Life DBus service. This should be the same across all viewers.
if echo "$LIST" | grep -q "$SERVICE"; then
echo "Second Life running, sending to DBus..."; echo "Second Life running, sending to DBus...";
exec dbus-send --type=method_call --dest=$SERVICE /com/secondlife/ViewerAppAPI com.secondlife.ViewerAppAPI.GoSLURL string:"$1" exec dbus-send --type=method_call --dest="${service_name}" /com/secondlife/ViewerAppAPI com.secondlife.ViewerAppAPI.GoSLURL string:"${sl_url}"
else else
echo "Second Life not running, launching new instance..."; echo "Second Life not running, launching new instance...";
cd "${RUN_PATH}"/.. cd "${run_path}"/.. || exit
#Go to .sh location (/etc), then up a directory to the viewer location #Go to .sh location (/etc), then up a directory to the viewer location
#exec ./alchemy -url \'"${URL}"\' exec ./alchemy -url "${sl_url}"
exec ./alchemy -url ${URL}
#Remove some of the wrapping around the URL, as this was breaking the handover upon startup
fi fi
...@@ -4,33 +4,46 @@ ...@@ -4,33 +4,46 @@
# URLs of the form secondlife://... # URLs of the form secondlife://...
# #
HANDLER="$1" desired_handler="$1"
RUN_PATH=$(dirname "$0" || echo .) print() {
cd "${RUN_PATH}/.." log_prefix="RegisterSLProtocol:"
echo -e "${log_prefix} $*"
}
run_path=$(dirname "$0" || echo .)
cd "${run_path}/.." || exit
if [ -z "$HANDLER" ]; then if [ -z "${desired_handler}" ]; then
#HANDLER="$RUN_PATH/etc/handle_secondlifeprotocol.sh" #desired_handler="$run_path/etc/handle_secondlifeprotocol.sh"
HANDLER="$(pwd)/etc/handle_secondlifeprotocol.sh" desired_handler="$(pwd)/etc/handle_secondlifeprotocol.sh"
fi fi
# Register handler for GNOME-aware apps print "Requested Handler: ${desired_handler}"
LLGCONFTOOL=gconftool-2
if which ${LLGCONFTOOL} >/dev/null; then # Register handler for gconf-aware apps
(${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. # TODO: use dconf or another modern alternative
else gconftool=$(command -v "${LLGCONFTOOL:=gconftool-2}")
echo Warning: Did not register secondlife:// handler with GNOME: ${LLGCONFTOOL} not found. if [[ -z "${gconftool}" ]]; then
print "gconf not found, skipped. (This is good)"
else
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 secondlife:// handler with (deprecated) gconf."
else
print "Failed to register secondlife:// handler with (deprecated) gconf."
fi
fi fi
# Register handler for KDE-aware apps # Register handler for KDE-aware apps
for LLKDECONFIG in kde-config kde4-config; do for kdeconfig in ${LLKDECONFIG} kf5-config kde4-config kde-config; do
if [ $(which $LLKDECONFIG) ]; then if command -v "${kdeconfig}" >/dev/null 2>&1; then
LLKDEPROTODIR=$($LLKDECONFIG --path services | cut -d ':' -f 1) kde_protocols_folder=$("${kdeconfig}" --path services | cut -d ':' -f 1)
if [ -d "$LLKDEPROTODIR" ]; then mkdir -p "${kde_protocols_folder}"
LLKDEPROTOFILE=${LLKDEPROTODIR}/secondlife.protocol if [ -d "${kde_protocols_folder}" ]; then
cat > ${LLKDEPROTOFILE} <<EOF || echo Warning: Did not register secondlife:// handler with KDE: Could not write ${LLKDEPROTOFILE} kde_proto_file=${kde_protocols_folder}/secondlife.protocol
kde_handler_string="
[Protocol] [Protocol]
exec=${HANDLER} '%u' exec=${desired_handler} %u
protocol=secondlife protocol=secondlife
input=none input=none
output=none output=none
...@@ -39,49 +52,67 @@ listing= ...@@ -39,49 +52,67 @@ listing=
reading=false reading=false
writing=false writing=false
makedir=false makedir=false
deleting=false deleting=false"
EOF if echo "${kde_handler_string}" > "${kde_proto_file}"; then
print "Registered secondlife:// handler with KDE"
success=1
else
print 'Warning: Did not register secondlife:// handler with KDE: Could not write '"${kde_proto_file}"
fi
else else
echo Warning: Did not register secondlife:// handler with KDE: Directory $LLKDEPROTODIR does not exist. print 'Warning: Did not register secondlife:// handler with KDE: Directory '"${kde_protocols_folder}"' does not exist.'
fi fi
fi # else
# print "Warning: KDE-Config binary '${kdeconfig}' not found"
fi
done done
if [[ -z "${success}" ]]; then
#Check if xdg-mime is present, if so, use it to register new protocol. print "Warning: secondlife:// protocol not registered with KDE: could not find any configuration utility. You can still register the application manually by editing ${HOME}/.local/share/mimeapps.list"
fi
# if [[ -n "${FALLBACK}" ]]; then
#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 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) urlhandler=$(xdg-mime query default x-scheme-handler/secondlife)
localappdir="$HOME/.local/share/applications" localappdir="$HOME/.local/share/applications"
newhandler="handle_secondlifeprotocol.desktop" newhandler="handle_secondlifeprotocol.desktop"
cat >"$localappdir/$newhandler" <<EOFnew || echo Warning: Did not register secondlife:// handler with xdg-mime: Could not write $newhandler handlerpath="$localappdir/$newhandler"
print "New handler file: ${handlerpath}"
cat >"${handlerpath}" <<EOFnew || print Warning: Did not register secondlife:// handler with xdg-mime: Could not write $newhandler
[Desktop Entry] [Desktop Entry]
Version=1.5 Version=1.5
Name="Second Life URL handler" Name="Second Life URL handler"
Comment="secondlife:// URL handler" Comment="secondlife:// URL handler"
Type=Application Type=Application
Exec=$HANDLER %u Exec=$desired_handler %u
Terminal=false Terminal=false
StartupNotify=false StartupNotify=false
NoDisplay=true NoDisplay=true
MimeType=x-scheme-handler/secondlife MimeType=x-scheme-handler/secondlife
EOFnew EOFnew
if [ -z $urlhandler ]; then # TODO: use absolute path for the desktop file
echo No SLURL handler currently registered, creating new... # 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 else
echo Current SLURL Handler: $urlhandler - Setting new default...
#xdg-mime uninstall $localappdir/$urlhandler #xdg-mime uninstall $localappdir/$urlhandler
#Clean up handlers from other viewers #Clean up handlers from other viewers
if [ "$urlhandler" != "$newhandler" ]; then if [ "$urlhandler" != "$newhandler" ]; then
mv $localappdir/$urlhandler $localappdir/$urlhandler.bak 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
fi fi
xdg-mime default $newhandler x-scheme-handler/secondlife xdg-mime default $newhandler x-scheme-handler/secondlife
if command -v update-desktop-database > /dev/null 2>&1; then if command -v update-desktop-database > /dev/null 2>&1; then
update-desktop-database $localappdir update-desktop-database "$localappdir"
echo -e "Registered secondlife:// protocol with xdg-mime\nNew default: $(xdg-mime query default x-scheme-handler/secondlife)" print "Registered secondlife:// protocol with xdg-mime. New default: $(xdg-mime query default x-scheme-handler/secondlife)"
else else
echo Warning: Cannot update desktop database, command missing - installation may be incomplete. print "Warning: Cannot update desktop database, command missing - installation may be incomplete."
fi fi
else else
echo Warning: Did not register secondlife:// handler with xdg-mime: Package not found. print "Warning: Did not register secondlife:// handler with xdg-mime: Package not found."
fi fi
# fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment