sane-open: add the ability to open URIs

This commit is contained in:
2024-08-01 18:50:17 +00:00
parent c07eaba873
commit 659da66106

View File

@@ -12,6 +12,8 @@ usage() {
echo "--auto-keyboard: toggle the virtual keyboard state to whatever's preferred by the app"
echo "--application <thing.desktop>: open the desktop file (by name, not path)"
echo "--file </path/to/file>: open the file using the default mime handler"
echo "--uri <uri>: open the URI using the default mime handler"
echo " e.g. --uri https://uninsane.org"
exit $1
}
@@ -84,16 +86,6 @@ open_application() {
--method org.freedesktop.portal.DynamicLauncher.Launch \
"$1" {}
}
open_file() {
# open the file, and then pass the fd to dbus
log "open_file: '$1'"
exec 3< "$1"
gdbus call --session --timeout 10 \
--dest org.freedesktop.portal.Desktop \
--object-path /org/freedesktop/portal/desktop \
--method org.freedesktop.portal.OpenURI.OpenFile \
"" 3 "{'ask': <false>}"
}
open_desktopFile() {
log "open_desktopFile: '$1'"
local target=$(tryAsDesktopFile "$1")
@@ -107,6 +99,24 @@ open_desktopFile() {
open_application "$target"
fi
}
open_file() {
# open the file, and then pass the fd to dbus
log "open_file: '$1'"
exec 3< "$1"
gdbus call --session --timeout 10 \
--dest org.freedesktop.portal.Desktop \
--object-path /org/freedesktop/portal/desktop \
--method org.freedesktop.portal.OpenURI.OpenFile \
"" 3 "{'ask': <false>}"
}
open_uri() {
log "open_uri: '$1'"
gdbus call --session --timeout 10 \
--dest org.freedesktop.portal.Desktop \
--object-path /org/freedesktop/portal/desktop \
--method org.freedesktop.portal.OpenURI.OpenURI \
"" "$1" "{'ask': <false>}"
}
# evaluate truthy and print desktop name as `FOO.desktop` if the provided file is a .desktop file suitable for open_application.
tryAsDesktopFile() {
@@ -200,6 +210,9 @@ while [ $# -gt 0 ]; do
"--file")
resourceType="file"
;;
"--uri")
resourceType="uri"
;;
*)
if [ $# -ne 0 ]; then
usage 1