rofi: fix files to be opened with xdg-open

This commit is contained in:
Colin 2024-02-27 21:20:12 +00:00
parent c8035abddf
commit 715de37954
3 changed files with 45 additions and 4 deletions

View File

@ -16,6 +16,7 @@ configuration {
directory: "/home";
/* display-name: text to prepend in combi mode */
display-name: "/";
/* `command` is the prefix to prepend (along with a space) *before* passing it off to `run-command` */
command: "xdg-open";
}
drun {
@ -28,8 +29,8 @@ configuration {
/* combi-display-format: "{text}"; */
combi-display-format: "{mode}{text}";
/* launch applications via xdg-desktop-portal */
run-command: "gdbus call --session --timeout 10 --dest org.freedesktop.portal.Desktop --object-path /org/freedesktop/portal/desktop --method org.freedesktop.portal.DynamicLauncher.Launch {app_id}.desktop {}";
/* launch applications via my own launcher, which directs them through to xdg-desktop-portal */
run-command: "rofi-run-command '{app_id}.desktop' {cmd}";
drun-use-desktop-cache: true;
}

View File

@ -50,8 +50,7 @@
};
suggestedPrograms = [
"xdg-utils"
"gdbus"
"rofi-run-command"
];
sandbox.method = "bwrap";
@ -78,4 +77,18 @@
".cache/rofi"
];
};
sane.programs.rofi-run-command = {
packageUnwrapped = pkgs.static-nix-shell.mkBash {
pname = "rofi-run-command";
srcRoot = ./.;
pkgs = [ "glib" "xdg-utils" ];
};
sandbox.enable = false; #< trivial script, and all our deps are sandboxed
suggestedPrograms = [
"gdbus"
"xdg-utils"
];
};
}

View File

@ -0,0 +1,27 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p glib -p xdg-utils
# use:
# rofi-run-command <handler>.desktop [cmd [args ...]]
# if a non-empty desktop file is provided, we'll just launch that.
# else, if the cmd is `xdg-open`, then we'll treat `args` as a URI and forward that to xdg-open.
# nothing else is as-yet supported.
desktop="$1"
shift
binary="$1"
shift
binArgs=("$@")
if [ "$desktop" != .desktop ]; then
exec gdbus call --session --timeout 10 \
--dest org.freedesktop.portal.Desktop \
--object-path /org/freedesktop/portal/desktop \
--method org.freedesktop.portal.DynamicLauncher.Launch \
"$desktop" {}
elif [ "$binary" = "xdg-open" ]; then
exec xdg-open "$@"
fi
printf "no .desktop file, and unexpected binary; not invoking: %s %s" "$binary" "${binArgs[*]}" > /dev/null
exit 1