Repository navigation
fix(browser): support wrapped Exec commands in browser and webapp launchers - #11728
harshithnadig wants to merge 2 commits into
Conversation
…nchers - Parse and preserve complete Exec command line from desktop files instead of slicing off first whitespace token - Properly substitute %u / %U field codes with URL argument or omit when empty - Correctly position private browsing flag for both native and containerized browsers - Enhance app focus pattern resolution to match flatpak IDs and wrapped binaries - Add automated regression tests in launch-browser-test.sh Fixes omacom#11718
Automated AI review
Outcome: The Exec parser splits quoted arguments, and installed Flatpak browsers are still not found. Quoted Exec arguments are split
Suggested change: Reproducer (fails at d87d9f8)Save as #!/bin/bash
set -euo pipefail
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
test_tmp=$(mktemp -d)
trap 'rm -rf "$test_tmp"' EXIT
mock_bin="$test_tmp/bin"
test_home="$test_tmp/home"
mkdir -p "$mock_bin" "$test_home/.local/share/applications"
# Log one argument per line, so argument boundaries are visible.
cat >"$mock_bin/systemd-run" <<'SH'
#!/bin/bash
printf '%s\n' "$@" >"$OMARCHY_TEST_LAUNCH"
SH
cp "$mock_bin/systemd-run" "$mock_bin/setsid"
cat >"$mock_bin/xdg-settings" <<'SH'
#!/bin/bash
echo chromium.desktop
SH
cat >"$mock_bin/omarchy-hyprland-focus-app" <<'SH'
#!/bin/bash
exit 0
SH
chmod +x "$mock_bin"/*
# Desktop Entry spec, "The Exec key": an argument containing a space is quoted
# in whole and passed to the program as one argument.
cat >"$test_home/.local/share/applications/chromium.desktop" <<'EOF'
[Desktop Entry]
Exec="/opt/Example Browser/chromium" "--user-data-dir=/tmp/Example Profile" %U
EOF
problems=""
for launcher in omarchy-launch-browser omarchy-launch-webapp; do
log="$test_tmp/$launcher"
HOME="$test_home" PATH="$mock_bin:$PATH" OMARCHY_TEST_LAUNCH="$log" \
bash "$ROOT/bin/$launcher" "https://example.test/quoted"
if ! grep -Fxq -- '/opt/Example Browser/chromium' "$log" ||
! grep -Fxq -- '--user-data-dir=/tmp/Example Profile' "$log"; then
problems+="$launcher ran:"$'\n'"$(sed -n '/^--$/,$p' "$log" | tail -n +2)"$'\n'
fi
done
[[ -z $problems ]] || fail "launchers keep quoted Exec arguments whole" "$problems"
pass "launchers keep quoted Exec arguments whole"Output at With the suggested change it prints Installed Flatpak browsers are not foundFlatpak exports entries to Suggested change: also search Reproducer (fails at d87d9f8)Save as #!/bin/bash
set -euo pipefail
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
test_tmp=$(mktemp -d)
trap 'rm -rf "$test_tmp"' EXIT
mock_bin="$test_tmp/bin"
test_home="$test_tmp/home"
# Flatpak exports desktop files here (added to XDG_DATA_DIRS), not to
# ~/.local/share/applications.
exports="$test_home/.local/share/flatpak/exports/share/applications"
mkdir -p "$mock_bin" "$exports"
cat >"$mock_bin/systemd-run" <<'SH'
#!/bin/bash
printf '%s\n' "$@" >"$OMARCHY_TEST_LAUNCH"
SH
cat >"$mock_bin/xdg-settings" <<'SH'
#!/bin/bash
echo org.mozilla.firefox.desktop
SH
cat >"$mock_bin/omarchy-hyprland-focus-app" <<'SH'
#!/bin/bash
exit 0
SH
chmod +x "$mock_bin"/*
# The Exec line Flatpak writes for an exported Firefox.
cat >"$exports/org.mozilla.firefox.desktop" <<'EOF2'
[Desktop Entry]
Exec=/usr/bin/flatpak run --branch=stable --arch=x86_64 --command=firefox --file-forwarding org.mozilla.firefox @@u %u @@
EOF2
launch_log="$test_tmp/launch"
# Flatpak's env.d adds its export dirs to XDG_DATA_DIRS the same way.
HOME="$test_home" PATH="$mock_bin:$PATH" OMARCHY_TEST_LAUNCH="$launch_log" \
XDG_DATA_DIRS="$test_home/.local/share/flatpak/exports/share:/usr/local/share:/usr/share" \
bash "$ROOT/bin/omarchy-launch-browser" --private "https://example.test/private"
command=$(sed -n '/^--$/{n;p;q}' "$launch_log")
[[ $command == /usr/bin/flatpak ]] ||
fail "browser launcher runs the Exec of an exported Flatpak browser" "$(sed -n '/^--$/,$p' "$launch_log")"
pass "browser launcher runs the Exec of an exported Flatpak browser"Output at What import sys, tempfile
sys.path.insert(1, "/usr/share/uwsm/modules") # where the uwsm package installs its modules
from xdg.DesktopEntry import DesktopEntry
from uwsm.main import gen_entry_args
# What `uwsm-app -- org.mozilla.firefox.desktop --private-window <url>` expands to.
with tempfile.NamedTemporaryFile("w", suffix=".desktop") as entry:
entry.write("[Desktop Entry]\nType=Application\nName=Firefox\n"
"Exec=/usr/bin/flatpak run --branch=stable --arch=x86_64 --command=firefox "
"--file-forwarding org.mozilla.firefox @@u %u @@\n")
entry.flush()
command, instances = gen_entry_args(DesktopEntry(entry.name), ["--private-window", "https://example.test/private"])
for args in instances:
print(command, *args)Output (uwsm 0.26.7-1, python-pyxdg 0.28-7): Looking the entry up through More findingsConflicts with Checked resolution: Private flag is picked from the whole Exec line. The Mozilla/ DetailsVerified:
Optional notes:
Other open PRs for this issue
Review informationTest scope: Source and sandbox tests with stubs at AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check. Opt out: To stop receiving these reviews, reply to this comment saying so. |
|
Reviewed against The bug is real and still on
I compared the four fixes, and so did Codex at medium effort, which reviewed them separately and was not given my conclusion. It is a second reading, but its independence is not guaranteed. We agree that #12533 is the one to take forward. It is the smallest change, it keeps every caller argument and the existing private-flag probe and focus behaviour for native browsers, and it tests both launchers. It still has to be ported onto This waits on the maintainer to choose between the competing fixes. Nothing is asked of you right now. If #12533 lands, it covers what this pull request set out to fix. |
|
Thank you for this, @harshithnadig. #12533 fixes the same problem in a way the review judged better, so this is closed in favour of it. If it does not cover your case, please say so there. Closed at the maintainer's request. The review comment above has the details; it was done by Claude Opus 5.5 with Codex Medium as a second opinion, whose agreement is not independent. |
What problem does this solve?
Fixes #11718.
When a default web browser's
.desktopentry has a wrappedExec=command (such as Flatpaks likeExec=/usr/bin/flatpak run org.mozilla.firefox %uor wrapper scripts likeExec=/usr/bin/env python3 /path/to/browser.py %u),omarchy-launch-browserandomarchy-launch-webappstripped away everything after the first whitespace token via:This reduced the command to bare
/usr/bin/flatpakor/usr/bin/envwith no subcommands or arguments. Becausesystemd-runrouted stdout/stderr to null, keybindings likeSUPER+SHIFT+RETURN,SUPER+SHIFT+B, and URL openings silently failed with zero feedback.How is it solved?
Exec=line respecting quotes, maintaining wrapper commands, subcommands, and flags.%uor%Uwith the target URL when present, or omits them when launching empty.--private-window,--inprivate, or--incognitoin front of the URL parameter for both native and containerized browsers.bin/omarchy-launch-webappwith matching command line preservation.test/shell.d/launch-browser-test.shverifying flatpak wrapped commands and private browsing flags.