userscripts/open_download: Flatpak compatibility

This commit is contained in:
tinywrkb 2022-01-12 14:33:47 +02:00
parent 19bbb8dc67
commit d7a4c3a24d
1 changed files with 15 additions and 6 deletions

View File

@ -103,13 +103,22 @@ fi
file="${entries[$line]}"
file="${file%%$'\t'*}"
path="$DOWNLOAD_DIR/$file"
filetype=$(xdg-mime query filetype "$path")
application=$(xdg-mime query default "$filetype")
if [ -z "$application" ] ; then
die "Do not know how to open »$file« of type $filetype"
if [ -f /.flatpak-info ]; then
# with the help of the appchooser portal, flatpak let the user select the
# app associated with a mime type after executing xdg-open.
# we can't know ahead of time which app will be launched, and the sandbox
# doesn't have access to mime types known to the host.
msg info "Opening »$file« with XDG Desktop Portal"
else
filetype=$(xdg-mime query filetype "$path")
application=$(xdg-mime query default "$filetype")
if [ -z "$application" ] ; then
die "Do not know how to open »$file« of type $filetype"
fi
msg info "Opening »$file« (of type $filetype) with ${application%.desktop}"
fi
msg info "Opening »$file« (of type $filetype) with ${application%.desktop}"
xdg-open "$path" &