sane-open: add debug logging

This commit is contained in:
2024-05-05 05:03:22 +00:00
parent a1625ea41d
commit cf3cfc5249

View File

@@ -15,6 +15,12 @@ usage() {
exit $1 exit $1
} }
log() {
if [ -n "$SANE_OPEN_DEBUG" ]; then
printf 'sane-open: %s\n' $@ >&2
fi
}
configureKeyboardFor_application() { configureKeyboardFor_application() {
case "$1" in case "$1" in
Alacritty.desktop) Alacritty.desktop)
@@ -48,6 +54,7 @@ configureKeyboardFor_file() {
} }
open_application() { open_application() {
log "open_application: '$1'"
gdbus call --session --timeout 10 \ gdbus call --session --timeout 10 \
--dest org.freedesktop.portal.Desktop \ --dest org.freedesktop.portal.Desktop \
--object-path /org/freedesktop/portal/desktop \ --object-path /org/freedesktop/portal/desktop \
@@ -56,6 +63,7 @@ open_application() {
} }
open_file() { open_file() {
# open the file, and then pass the fd to dbus # open the file, and then pass the fd to dbus
log "open_file: '$1'"
exec 3<> "$1" exec 3<> "$1"
gdbus call --session --timeout 10 \ gdbus call --session --timeout 10 \
--dest org.freedesktop.portal.Desktop \ --dest org.freedesktop.portal.Desktop \
@@ -75,11 +83,13 @@ isLandscape() {
_keyboardPid= _keyboardPid=
setKeyboard() { setKeyboard() {
if [ -z "$KEYBOARD" ]; then if [ -z "$KEYBOARD" ]; then
log "KEYBOARD is not set"
return return
fi fi
if [ -z "$_keyboardPid" ]; then if [ -z "$_keyboardPid" ]; then
_keyboardPid=$(pidof "$KEYBOARD") _keyboardPid=$(pidof "$KEYBOARD")
if [ -z "$_keyboardPid" ]; then if [ -z "$_keyboardPid" ]; then
log "KEYBOARD ($KEYBOARD) instance is not found"
return return
fi fi
fi fi
@@ -88,6 +98,7 @@ setKeyboard() {
_setKeyboard() { _setKeyboard() {
case "$1" in case "$1" in
"show") "show")
log "show keyboard $_keyboardPid"
# `env` so that we get the util-linux `kill` binary instead of bash's builtin # `env` so that we get the util-linux `kill` binary instead of bash's builtin
env kill -s USR2 "$_keyboardPid" env kill -s USR2 "$_keyboardPid"
;; ;;
@@ -95,6 +106,7 @@ _setKeyboard() {
isLandscape && _setKeyboard "hide" || _setKeyboard "show" isLandscape && _setKeyboard "hide" || _setKeyboard "show"
;; ;;
"hide") "hide")
log "hide keyboard $_keyboardPid"
env kill -s USR1 "$_keyboardPid" env kill -s USR1 "$_keyboardPid"
;; ;;
esac esac
@@ -133,8 +145,10 @@ done
if [ -z "$resourceType" ]; then if [ -z "$resourceType" ]; then
if [ -e "$HOME/.local/share/applications/$resource" ]; then if [ -e "$HOME/.local/share/applications/$resource" ]; then
log "detected resourceType=application"
resourceType=application resourceType=application
else else
log "detected resourceType=file"
resourceType=file resourceType=file
fi fi
fi fi