sane-open: special-case how i open .desktop files to be compatible with portals

This commit is contained in:
Colin 2024-05-12 19:46:03 +00:00
parent e63e359417
commit 15a5afd2c4
3 changed files with 33 additions and 3 deletions

View File

@ -16,6 +16,6 @@
"xdg-utils"
];
mime.associations."application/x-desktop" = "sane-open-application.desktop";
mime.associations."application/x-desktop" = "sane-open-desktop.desktop";
};
}

View File

@ -11,9 +11,10 @@ static-nix-shell.mkBash {
];
desktopItems = [
(makeDesktopItem {
name = "sane-open-application";
exec = "sane-open --application %f";
name = "sane-open-desktop";
exec = "sane-open --desktop-file %f";
desktopName = ".desktop launcher";
mimeTypes = [ "application/x-desktop" ];
noDisplay = true;
})
];

View File

@ -83,6 +83,32 @@ open_file() {
--method org.freedesktop.portal.OpenURI.OpenFile \
'' 3 "{'ask': <false>}"
}
open_desktopFile() {
log "open_desktopFile: '$1'"
# open_application (i.e. the DynamicLauncher portal) only understands applications by their
# .desktop filename (relative to ~/.local/share/applications) -- not by their full path.
# therefore, see if this .desktop file is equivalent to anything in ~/.local/share/applications.
local path="$1"
if [[ "${path:0:1}" != "/" ]]; then
path="$PWD/$path"
fi
if [[ "$path" == $HOME/.local/share/applications/*.desktop ]]; then
open_application "$(basename "$path")"
return
fi
# the given path doesn't exist in ~/.local/share/applications: check if it's a symlink which
# derefs to an application
local target="$(readlink "$path")"
if [ -z "$target" ]; then
log "open_desktopFile: '$path' does not deref to anything in ~/.local/share/applications: don't know how to launch"
exit 1
fi
if [[ "${target:0:1}" != "/" ]]; then
target="$(dirname "$path")/$target"
fi
open_desktopFile "$target"
}
isLandscape() {
@ -143,6 +169,9 @@ while [ $# -gt 0 ]; do
"--application")
resourceType="application"
;;
"--desktop-file")
resourceType="desktopFile"
;;
"--file")
resourceType="file"
;;