sane-open: special-case how i open .desktop files to be compatible with portals
This commit is contained in:
parent
e63e359417
commit
15a5afd2c4
|
@ -16,6 +16,6 @@
|
|||
"xdg-utils"
|
||||
];
|
||||
|
||||
mime.associations."application/x-desktop" = "sane-open-application.desktop";
|
||||
mime.associations."application/x-desktop" = "sane-open-desktop.desktop";
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
})
|
||||
];
|
||||
|
|
|
@ -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"
|
||||
;;
|
||||
|
|
Loading…
Reference in New Issue
Block a user