From 676d1385f194ef31d2196c2f43825e5ac385ca8f Mon Sep 17 00:00:00 2001 From: Paulo Geyer Date: Sat, 31 Oct 2026 09:11:04 -0300 Subject: [PATCH 1/7] Resolve wrapped desktop Exec= in browser and webapp launchers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Split the whole Exec line by the Desktop Entry spec's quoting and escapes, expand %c and %k, drop the other field codes and a standalone --, and launch the full argv, so env- or flatpak-wrapped entries start the real browser. The private-flag probe and window focus use the first token that is not env, an env option or assignment, or flatpak run. The entry is read from the XDG data dirs omarchy-cmd-default-browser searched, and an entry with no usable Exec= keeps the visible not-found notification. Co-authored-by: 唐鳳 --- bin/omarchy-launch-browser | 105 ++++++++++++++++++++++++---- bin/omarchy-launch-webapp | 89 +++++++++++++++++++---- test/shell.d/launch-browser-test.sh | 63 ++++++++++++++++- test/shell.d/launch-webapp-test.sh | 80 +++++++++++++++++++++ 4 files changed, 307 insertions(+), 30 deletions(-) create mode 100644 test/shell.d/launch-webapp-test.sh diff --git a/bin/omarchy-launch-browser b/bin/omarchy-launch-browser index 7f72cb96b2c8..dbd9cf9c113e 100755 --- a/bin/omarchy-launch-browser +++ b/bin/omarchy-launch-browser @@ -5,31 +5,108 @@ default_browser=$(omarchy-cmd-default-browser) -# Read Exec= from the same data dirs omarchy-cmd-default-browser searched, in -# the same order, so the command always comes from the entry that was checked. -IFS=: read -ra data_dirs <<<"${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}" -browser_exec="" -for data_dir in "${data_dirs[@]}"; do - entry="$data_dir/applications/$default_browser" - [[ -f $entry ]] || continue - browser_exec=$(sed -n 's/^Exec=\([^ ]*\).*/\1/p' "$entry" | head -1) - break -done +# Undo the escapes every desktop entry string carries. +desktop_string() { + local string=$1 char i + REPLY="" + for (( i = 0; i < ${#string}; i++ )); do + char=${string:i:1} + if [[ $char == "\\" ]]; then + (( i++ )) + case ${string:i:1} in + s) char=" " ;; + n) char=$'\n' ;; + t) char=$'\t' ;; + r) char=$'\r' ;; + "\\") char="\\" ;; + *) char="\\${string:i:1}" ;; + esac + fi + REPLY+=$char + done +} + +desktop_exec_argv() { + local desktop=$1 + local file="" line="" name data_dir + desktop_exec_argv=() + # Read Exec= from the same data dirs omarchy-cmd-default-browser searched, in + # the same order, so the command always comes from the entry that was checked. + local -a data_dirs + IFS=: read -ra data_dirs <<<"${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}" + for data_dir in "${data_dirs[@]}"; do + file="$data_dir/applications/$desktop" + [[ -f $file ]] || continue + line=$(sed -n 's/^Exec=//p' "$file" | head -1) + break + done + [[ -n $line ]] || return 1 + desktop_string "$(sed -n 's/^Name=//p' "$file" | head -1)" + name=$REPLY + + # Split the Exec line by its own quoting, expanding %c and %k, keeping %% as + # %, and dropping the other field codes. A standalone -- goes too, or the + # launcher's own options after it would be read as operands. + desktop_string "$line" + local value=$REPLY arg="" char i quoted=0 started=0 + for (( i = 0; i < ${#value}; i++ )); do + char=${value:i:1} + if [[ $char == '"' ]]; then + (( quoted = !quoted, started = 1 )) + elif [[ $char == "\\" ]] && (( quoted )); then + (( i++ )) + arg+=${value:i:1} + elif [[ $char == "%" ]]; then + (( i++ )) + case ${value:i:1} in + "%") arg+="%" started=1 ;; + c) arg+=$name started=1 ;; + k) arg+=$file started=1 ;; + esac + elif [[ $char == " " ]] && (( ! quoted )); then + if (( started )) && [[ $arg != "--" ]]; then + desktop_exec_argv+=("$arg") + fi + arg="" started=0 + else + arg+=$char started=1 + fi + done + if (( started )) && [[ $arg != "--" ]]; then + desktop_exec_argv+=("$arg") + fi + + (( ${#desktop_exec_argv[@]} > 0 )) +} # Handing an empty command to uwsm-app surfaces as "Command not found: \"\"", # which fails a keybinding silently. Say what is missing and how to fix it. -if [[ -z $browser_exec ]]; then +if ! desktop_exec_argv "$default_browser"; then echo "omarchy-launch-browser: no default browser found; set one with 'omarchy default browser '" >&2 omarchy-notification-send -u critical -g 󰖟 "$(omarchy-i18n browser.notFound)" "$(omarchy-i18n browser.notFoundHint)" exit 1 fi +browser_exec="" +skip_value=0 +for token in "${desktop_exec_argv[@]}"; do + if (( skip_value )); then + skip_value=0 + elif [[ $token == -u || $token == --unset || $token == -C || $token == --chdir ]]; then + skip_value=1 + elif [[ $token != env && $token != */env && $token != *=* && $token != -* && $token != run && $token != flatpak && $token != */flatpak ]]; then + browser_exec=$token + break + fi +done +[[ -n $browser_exec ]] || browser_exec=${desktop_exec_argv[0]} + # Only a private launch needs the browser's flag, and probing a Firefox-family # browser's --help starts the whole binary, so ordinary launches skip it and # leave their arguments as they are. private_flag="--private" if [[ " $* " == *" --private "* ]]; then - if $browser_exec --help 2>/dev/null | grep -q MOZ_LOG; then + if "$browser_exec" --help 2>/dev/null | grep -q MOZ_LOG; then private_flag="--private-window" elif [[ $browser_exec =~ edge ]]; then private_flag="--inprivate" @@ -38,10 +115,10 @@ if [[ " $* " == *" --private "* ]]; then fi fi -if ! omarchy-cmd-browser-handoff "$browser_exec" "${@/--private/$private_flag}"; then +if ! omarchy-cmd-browser-handoff "${desktop_exec_argv[@]}" "${@/--private/$private_flag}"; then systemd-run --user --quiet --collect --unit="omarchy-browser-$(date +%s%N)" \ --property=StandardOutput=null --property=StandardError=null \ - uwsm-app -- "$browser_exec" "${@/--private/$private_flag}" + uwsm-app -- "${desktop_exec_argv[@]}" "${@/--private/$private_flag}" fi url="" diff --git a/bin/omarchy-launch-webapp b/bin/omarchy-launch-webapp index 1c8c31f073dc..3ab397782a31 100755 --- a/bin/omarchy-launch-webapp +++ b/bin/omarchy-launch-webapp @@ -10,26 +10,89 @@ google-chrome* | brave* | microsoft-edge* | opera* | vivaldi* | helium*) ;; *) browser="chromium.desktop" ;; esac -# Read Exec= from the same data dirs omarchy-cmd-default-browser searched, as -# omarchy-launch-browser does, so a browser it resolved is one this can start. -IFS=: read -ra data_dirs <<<"${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}" -browser_exec="" -for data_dir in "${data_dirs[@]}"; do - entry="$data_dir/applications/$browser" - [[ -f $entry ]] || continue - browser_exec=$(sed -n 's/^Exec=\([^ ]*\).*/\1/p' "$entry" | head -1) - break -done +# Undo the escapes every desktop entry string carries. +desktop_string() { + local string=$1 char i + REPLY="" + for (( i = 0; i < ${#string}; i++ )); do + char=${string:i:1} + if [[ $char == "\\" ]]; then + (( i++ )) + case ${string:i:1} in + s) char=" " ;; + n) char=$'\n' ;; + t) char=$'\t' ;; + r) char=$'\r' ;; + "\\") char="\\" ;; + *) char="\\${string:i:1}" ;; + esac + fi + REPLY+=$char + done +} + +desktop_exec_argv() { + local desktop=$1 + local file="" line="" name data_dir + desktop_exec_argv=() + # Read Exec= from the same data dirs omarchy-cmd-default-browser searched, in + # the same order, so the command always comes from the entry that was checked. + local -a data_dirs + IFS=: read -ra data_dirs <<<"${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}" + for data_dir in "${data_dirs[@]}"; do + file="$data_dir/applications/$desktop" + [[ -f $file ]] || continue + line=$(sed -n 's/^Exec=//p' "$file" | head -1) + break + done + [[ -n $line ]] || return 1 + desktop_string "$(sed -n 's/^Name=//p' "$file" | head -1)" + name=$REPLY + + # Split the Exec line by its own quoting, expanding %c and %k, keeping %% as + # %, and dropping the other field codes. A standalone -- goes too, or the + # launcher's own options after it would be read as operands. + desktop_string "$line" + local value=$REPLY arg="" char i quoted=0 started=0 + for (( i = 0; i < ${#value}; i++ )); do + char=${value:i:1} + if [[ $char == '"' ]]; then + (( quoted = !quoted, started = 1 )) + elif [[ $char == "\\" ]] && (( quoted )); then + (( i++ )) + arg+=${value:i:1} + elif [[ $char == "%" ]]; then + (( i++ )) + case ${value:i:1} in + "%") arg+="%" started=1 ;; + c) arg+=$name started=1 ;; + k) arg+=$file started=1 ;; + esac + elif [[ $char == " " ]] && (( ! quoted )); then + if (( started )) && [[ $arg != "--" ]]; then + desktop_exec_argv+=("$arg") + fi + arg="" started=0 + else + arg+=$char started=1 + fi + done + if (( started )) && [[ $arg != "--" ]]; then + desktop_exec_argv+=("$arg") + fi + + (( ${#desktop_exec_argv[@]} > 0 )) +} # Handing an empty command to uwsm-app surfaces as "Command not found: \"\"", # which fails a keybinding silently. A web app runs in a Chromium-based # browser, so say that rather than claiming no browser is set. -if [[ -z $browser_exec ]]; then +if ! desktop_exec_argv "$browser"; then echo "omarchy-launch-webapp: web apps need a Chromium-based browser; install Chromium with 'omarchy install browser chromium'" >&2 omarchy-notification-send -u critical -g 󰖟 "$(omarchy-i18n browser.webappNeedsChromium)" "$(omarchy-i18n browser.webappNeedsChromiumHint)" exit 1 fi -if ! omarchy-cmd-browser-handoff "$browser_exec" --app="$1" "${@:2}"; then - exec setsid uwsm-app -- $browser_exec --app="$1" "${@:2}" +if ! omarchy-cmd-browser-handoff "${desktop_exec_argv[@]}" --app="$1" "${@:2}"; then + exec setsid uwsm-app -- "${desktop_exec_argv[@]}" --app="$1" "${@:2}" fi diff --git a/test/shell.d/launch-browser-test.sh b/test/shell.d/launch-browser-test.sh index e76d6cdbdcea..adef250868c7 100644 --- a/test/shell.d/launch-browser-test.sh +++ b/test/shell.d/launch-browser-test.sh @@ -37,7 +37,7 @@ exit 0 SH cat >"$mock_bin/systemd-run" <<'SH' #!/bin/bash -printf '%s\n' "$*" >"$OMARCHY_TEST_BROWSER_LAUNCH" +printf '%s\n' "$@" >"$OMARCHY_TEST_BROWSER_LAUNCH" SH cp "$mock_bin/systemd-run" "$mock_bin/uwsm-app" cat >"$mock_bin/omarchy-hyprland-focus-app" <<'SH' @@ -118,9 +118,66 @@ pass "an ordinary launch doesn't probe the browser's flags" launch --private [[ -s $help_log ]] || fail "a private launch probes the browser's private flag" -grep -F -- 'chromium --incognito' "$launch_log" >/dev/null || fail "a private launch passes the browser's private flag" +[[ $(sed '1,/^--$/d' "$launch_log") == $'chromium\n--incognito' ]] || fail "a private launch passes the browser's private flag" pass "a private launch passes the browser's private flag" +cat >"$test_home/.local/share/applications/chromium.desktop" <<'EOF' +[Desktop Entry] +Exec=/usr/bin/env LIBVA_DRIVER_NAME=iHD chromium "--profile-directory=Work Profile" --class=100%% %U +EOF + +rm -f "$focus_log" +HOME="$test_home" PATH="$mock_bin:$ROOT/bin:$PATH" HYPRLAND_INSTANCE_SIGNATURE=test \ + OMARCHY_TEST_BROWSER_LAUNCH="$launch_log" OMARCHY_TEST_BROWSER_FOCUS="$focus_log" \ + bash "$ROOT/bin/omarchy-launch-browser" "https://example.test/wrapped" + +expected=$(printf '%s\n' /usr/bin/env LIBVA_DRIVER_NAME=iHD chromium "--profile-directory=Work Profile" --class=100% https://example.test/wrapped) +[[ $(sed '1,/^--$/d' "$launch_log") == "$expected" ]] || + fail "wrapped Exec launcher runs the whole unquoted Exec line, then the URL" +grep -Fx '^chromium.*$' "$focus_log" >/dev/null || + fail "wrapped Exec launcher focuses the real browser, not env" +pass "browser launcher resolves env-wrapped desktop Exec lines" + +rm -f "$help_log" +launch --private +[[ -s $help_log ]] || fail "a wrapped private launch probes the real browser, not env" +expected=$(printf '%s\n' /usr/bin/env LIBVA_DRIVER_NAME=iHD chromium "--profile-directory=Work Profile" --class=100% --incognito) +[[ $(sed '1,/^--$/d' "$launch_log") == "$expected" ]] || + fail "a wrapped private launch passes the real browser's private flag" +pass "a wrapped private launch passes the real browser's private flag" + +cat >"$test_home/.local/share/applications/chromium.desktop" <<'EOF' +[Desktop Entry] +Name=Work\sChromium +Exec=/usr/bin/env -u BROWSER chromium --name %c -- https://start.example.test/ %U +EOF + +rm -f "$help_log" +launch --private +[[ -s $help_log ]] || fail "a private launch probes the browser behind env -u, not the name it unsets" +expected=$(printf '%s\n' /usr/bin/env -u BROWSER chromium --name "Work Chromium" https://start.example.test/ --incognito) +[[ $(sed '1,/^--$/d' "$launch_log") == "$expected" ]] || + fail "a private launch expands %c and keeps its flag an option despite the Exec line's --" +pass "a private launch finds the browser behind env options and keeps its flag an option" + +spaced_desktop="userapp-Firefox Developer Edition-U5J9W3.desktop" +cat >"$test_home/.local/share/applications/$spaced_desktop" <<'DESKTOP' +[Desktop Entry] +Exec=chromium %u +DESKTOP +cat >"$mock_bin/omarchy-cmd-default-browser" </dev/null || +[[ $(sed '1,/^--$/d' "$launch_log") == $'vivaldi\nhttps://example.test/vivaldi' ]] || fail "a browser in XDG_DATA_DIRS launches from its desktop entry" "$(cat "$launch_log")" pass "browser launcher reads Exec= from the data dirs the resolver searched" diff --git a/test/shell.d/launch-webapp-test.sh b/test/shell.d/launch-webapp-test.sh new file mode 100644 index 000000000000..3cd7f5df587a --- /dev/null +++ b/test/shell.d/launch-webapp-test.sh @@ -0,0 +1,80 @@ +#!/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" "$test_tmp/system/applications" +# Keep the resolver away from the host's own browsers and mimeapps lists. +export XDG_CONFIG_HOME="$test_home/.config" XDG_CONFIG_DIRS="$test_tmp/etc" +export XDG_DATA_HOME="$test_home/.local/share" XDG_DATA_DIRS="$test_tmp/system" + +cat >"$test_home/.local/share/applications/brave-browser.desktop" <<'EOF' +[Desktop Entry] +Exec=/usr/bin/env LIBVA_DRIVER_NAME=iHD brave "--profile-directory=Work Profile" %U +EOF + +cat >"$mock_bin/xdg-settings" <<'SH' +#!/bin/bash +echo brave-browser.desktop +SH +# The resolver only takes an entry whose command is installed. +cat >"$mock_bin/brave" <<'SH' +#!/bin/bash +exit 0 +SH +cat >"$mock_bin/setsid" <<'SH' +#!/bin/bash +exec "$@" +SH +cat >"$mock_bin/uwsm-app" <<'SH' +#!/bin/bash +printf '%s\n' "$@" >"$OMARCHY_TEST_WEBAPP_LAUNCH" +SH +chmod +x "$mock_bin"/* + +launch_log="$test_tmp/launch" +HOME="$test_home" PATH="$mock_bin:$ROOT/bin:$PATH" OMARCHY_TEST_WEBAPP_LAUNCH="$launch_log" \ + bash "$ROOT/bin/omarchy-launch-webapp" "https://discord.com/channels/@me" --start-maximized + +expected=$(printf '%s\n' -- /usr/bin/env LIBVA_DRIVER_NAME=iHD brave "--profile-directory=Work Profile" \ + --app=https://discord.com/channels/@me --start-maximized) +[[ $(<"$launch_log") == "$expected" ]] || + fail "webapp launcher runs the whole unquoted Exec line, then --app and the caller's arguments" +pass "webapp launcher resolves env-wrapped desktop Exec lines" + +cat >"$test_home/.local/share/applications/brave-browser.desktop" <<'EOF' +[Desktop Entry] +Name=Brave +Exec=brave --class=%c --desktop=%k -- %U +EOF + +HOME="$test_home" PATH="$mock_bin:$ROOT/bin:$PATH" OMARCHY_TEST_WEBAPP_LAUNCH="$launch_log" \ + bash "$ROOT/bin/omarchy-launch-webapp" "https://example.test/app" + +expected=$(printf '%s\n' -- brave --class=Brave "--desktop=$test_home/.local/share/applications/brave-browser.desktop" \ + --app=https://example.test/app) +[[ $(<"$launch_log") == "$expected" ]] || + fail "webapp launcher expands %c and %k and keeps --app ahead of the Exec line's closing --" +pass "webapp launcher expands %c and %k and keeps --app an option" + +cat >"$test_home/.local/share/applications/brave-browser Work.desktop" <<'DESKTOP' +[Desktop Entry] +Exec=brave %U +DESKTOP +cat >"$mock_bin/xdg-settings" <<'SH' +#!/bin/bash +echo "brave-browser Work.desktop" +SH + +HOME="$test_home" PATH="$mock_bin:$ROOT/bin:$PATH" OMARCHY_TEST_WEBAPP_LAUNCH="$launch_log" \ + bash "$ROOT/bin/omarchy-launch-webapp" "https://example.test/spaced" + +expected=$(printf '%s\n' -- brave --app=https://example.test/spaced) +[[ $(<"$launch_log") == "$expected" ]] || fail "webapp launcher finds a desktop id with spaces" +pass "webapp launcher finds a desktop id with spaces" From 76f5bfe893fd82b0413cbeece99d98cd72eb04a9 Mon Sep 17 00:00:00 2001 From: Omarchybot <317366263+omarchybot@users.noreply.github.com> Date: Sun, 1 Nov 2026 12:29:44 +0100 Subject: [PATCH 2/7] Move the web app launcher cases into launch-browser-test.sh launch-browser-test.sh already covers omarchy-launch-webapp, and the house rules ask for the area's existing test file rather than a new one. Co-Authored-By: Claude Opus 5.5 --- test/shell.d/launch-browser-test.sh | 50 ++++++++++++++++++ test/shell.d/launch-webapp-test.sh | 80 ----------------------------- 2 files changed, 50 insertions(+), 80 deletions(-) delete mode 100644 test/shell.d/launch-webapp-test.sh diff --git a/test/shell.d/launch-browser-test.sh b/test/shell.d/launch-browser-test.sh index adef250868c7..a14f36ff93e5 100644 --- a/test/shell.d/launch-browser-test.sh +++ b/test/shell.d/launch-browser-test.sh @@ -176,8 +176,58 @@ launch "https://example.test/spaced" [[ $(sed '1,/^--$/d' "$launch_log") == $'chromium\nhttps://example.test/spaced' ]] || fail "a desktop id with spaces launches its entry's command" pass "a desktop id with spaces launches its entry's command" + +cat >"$mock_bin/setsid" <<'SH' +#!/bin/bash +exec "$@" +SH +chmod +x "$mock_bin/setsid" +launch_webapp() { + HOME="$test_home" PATH="$mock_bin:$ROOT/bin:$PATH" OMARCHY_TEST_BROWSER_LAUNCH="$launch_log" \ + bash "$ROOT/bin/omarchy-launch-webapp" "$@" +} + +spaced_desktop="brave-browser Work.desktop" +cat >"$test_home/.local/share/applications/$spaced_desktop" <<'DESKTOP' +[Desktop Entry] +Exec=brave %U +DESKTOP +cat >"$mock_bin/omarchy-cmd-default-browser" <"$test_home/.local/share/applications/chromium.desktop" <<'EOF' +[Desktop Entry] +Exec=/usr/bin/env LIBVA_DRIVER_NAME=iHD chromium "--profile-directory=Work Profile" %U +EOF + +launch_webapp "https://discord.com/channels/@me" --start-maximized +expected=$(printf '%s\n' -- /usr/bin/env LIBVA_DRIVER_NAME=iHD chromium "--profile-directory=Work Profile" \ + --app=https://discord.com/channels/@me --start-maximized) +[[ $(<"$launch_log") == "$expected" ]] || + fail "web app launcher runs the whole Exec line, then --app and the caller's arguments" "$(cat "$launch_log")" +pass "web app launcher resolves env-wrapped desktop Exec lines" + +cat >"$test_home/.local/share/applications/chromium.desktop" <<'EOF' +[Desktop Entry] +Name=Chromium +Exec=chromium --class=%c --desktop=%k -- %U +EOF + +launch_webapp "https://example.test/app" +expected=$(printf '%s\n' -- chromium --class=Chromium "--desktop=$test_home/.local/share/applications/chromium.desktop" \ + --app=https://example.test/app) +[[ $(<"$launch_log") == "$expected" ]] || + fail "web app launcher expands %c and %k and keeps --app ahead of the Exec line's --" "$(cat "$launch_log")" +pass "web app launcher expands %c and %k and keeps --app an option" + # The resolver reads every XDG data dir, so the launcher has to read Exec= # from the same ones; a browser outside ~/.local and /usr used to resolve and # then launch an empty command. diff --git a/test/shell.d/launch-webapp-test.sh b/test/shell.d/launch-webapp-test.sh deleted file mode 100644 index 3cd7f5df587a..000000000000 --- a/test/shell.d/launch-webapp-test.sh +++ /dev/null @@ -1,80 +0,0 @@ -#!/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" "$test_tmp/system/applications" -# Keep the resolver away from the host's own browsers and mimeapps lists. -export XDG_CONFIG_HOME="$test_home/.config" XDG_CONFIG_DIRS="$test_tmp/etc" -export XDG_DATA_HOME="$test_home/.local/share" XDG_DATA_DIRS="$test_tmp/system" - -cat >"$test_home/.local/share/applications/brave-browser.desktop" <<'EOF' -[Desktop Entry] -Exec=/usr/bin/env LIBVA_DRIVER_NAME=iHD brave "--profile-directory=Work Profile" %U -EOF - -cat >"$mock_bin/xdg-settings" <<'SH' -#!/bin/bash -echo brave-browser.desktop -SH -# The resolver only takes an entry whose command is installed. -cat >"$mock_bin/brave" <<'SH' -#!/bin/bash -exit 0 -SH -cat >"$mock_bin/setsid" <<'SH' -#!/bin/bash -exec "$@" -SH -cat >"$mock_bin/uwsm-app" <<'SH' -#!/bin/bash -printf '%s\n' "$@" >"$OMARCHY_TEST_WEBAPP_LAUNCH" -SH -chmod +x "$mock_bin"/* - -launch_log="$test_tmp/launch" -HOME="$test_home" PATH="$mock_bin:$ROOT/bin:$PATH" OMARCHY_TEST_WEBAPP_LAUNCH="$launch_log" \ - bash "$ROOT/bin/omarchy-launch-webapp" "https://discord.com/channels/@me" --start-maximized - -expected=$(printf '%s\n' -- /usr/bin/env LIBVA_DRIVER_NAME=iHD brave "--profile-directory=Work Profile" \ - --app=https://discord.com/channels/@me --start-maximized) -[[ $(<"$launch_log") == "$expected" ]] || - fail "webapp launcher runs the whole unquoted Exec line, then --app and the caller's arguments" -pass "webapp launcher resolves env-wrapped desktop Exec lines" - -cat >"$test_home/.local/share/applications/brave-browser.desktop" <<'EOF' -[Desktop Entry] -Name=Brave -Exec=brave --class=%c --desktop=%k -- %U -EOF - -HOME="$test_home" PATH="$mock_bin:$ROOT/bin:$PATH" OMARCHY_TEST_WEBAPP_LAUNCH="$launch_log" \ - bash "$ROOT/bin/omarchy-launch-webapp" "https://example.test/app" - -expected=$(printf '%s\n' -- brave --class=Brave "--desktop=$test_home/.local/share/applications/brave-browser.desktop" \ - --app=https://example.test/app) -[[ $(<"$launch_log") == "$expected" ]] || - fail "webapp launcher expands %c and %k and keeps --app ahead of the Exec line's closing --" -pass "webapp launcher expands %c and %k and keeps --app an option" - -cat >"$test_home/.local/share/applications/brave-browser Work.desktop" <<'DESKTOP' -[Desktop Entry] -Exec=brave %U -DESKTOP -cat >"$mock_bin/xdg-settings" <<'SH' -#!/bin/bash -echo "brave-browser Work.desktop" -SH - -HOME="$test_home" PATH="$mock_bin:$ROOT/bin:$PATH" OMARCHY_TEST_WEBAPP_LAUNCH="$launch_log" \ - bash "$ROOT/bin/omarchy-launch-webapp" "https://example.test/spaced" - -expected=$(printf '%s\n' -- brave --app=https://example.test/spaced) -[[ $(<"$launch_log") == "$expected" ]] || fail "webapp launcher finds a desktop id with spaces" -pass "webapp launcher finds a desktop id with spaces" From 5a0be242b88e29b433a914aba6f4bb6064ae0403 Mon Sep 17 00:00:00 2001 From: Omarchybot <317366263+omarchybot@users.noreply.github.com> Date: Sun, 1 Nov 2026 12:30:19 +0100 Subject: [PATCH 3/7] Drop the spaced desktop id launcher cases quattro already reads Exec= from the quoted entry path, so both cases pass with its launchers and guard nothing this change touches. Co-Authored-By: Claude Opus 5.5 --- test/shell.d/launch-browser-test.sh | 33 ----------------------------- 1 file changed, 33 deletions(-) diff --git a/test/shell.d/launch-browser-test.sh b/test/shell.d/launch-browser-test.sh index a14f36ff93e5..2f45aa030925 100644 --- a/test/shell.d/launch-browser-test.sh +++ b/test/shell.d/launch-browser-test.sh @@ -160,23 +160,6 @@ expected=$(printf '%s\n' /usr/bin/env -u BROWSER chromium --name "Work Chromium" fail "a private launch expands %c and keeps its flag an option despite the Exec line's --" pass "a private launch finds the browser behind env options and keeps its flag an option" -spaced_desktop="userapp-Firefox Developer Edition-U5J9W3.desktop" -cat >"$test_home/.local/share/applications/$spaced_desktop" <<'DESKTOP' -[Desktop Entry] -Exec=chromium %u -DESKTOP -cat >"$mock_bin/omarchy-cmd-default-browser" <"$mock_bin/setsid" <<'SH' #!/bin/bash exec "$@" @@ -187,22 +170,6 @@ launch_webapp() { bash "$ROOT/bin/omarchy-launch-webapp" "$@" } -spaced_desktop="brave-browser Work.desktop" -cat >"$test_home/.local/share/applications/$spaced_desktop" <<'DESKTOP' -[Desktop Entry] -Exec=brave %U -DESKTOP -cat >"$mock_bin/omarchy-cmd-default-browser" <"$test_home/.local/share/applications/chromium.desktop" <<'EOF' [Desktop Entry] Exec=/usr/bin/env LIBVA_DRIVER_NAME=iHD chromium "--profile-directory=Work Profile" %U From 8f563445a73caed61841a746a0c8b8485fdf30ef Mon Sep 17 00:00:00 2001 From: Omarchybot <317366263+omarchybot@users.noreply.github.com> Date: Sun, 1 Nov 2026 14:36:43 +0100 Subject: [PATCH 4/7] Name a Flatpak browser's private flag from its app id A Flatpak entry's browser is its app id, which is no command on the host, so probing it for --help found nothing and a private Flatpak Firefox got --incognito and opened a normal window. The flag now comes from the app id. The browser inside an env -S string is found too, rather than probing env itself. Co-Authored-By: Raj-Jagadeesh-A-P Co-Authored-By: Claude Opus 5.5 --- bin/omarchy-launch-browser | 45 ++++++++++++++++++++++------- test/shell.d/launch-browser-test.sh | 30 +++++++++++++++++++ 2 files changed, 64 insertions(+), 11 deletions(-) diff --git a/bin/omarchy-launch-browser b/bin/omarchy-launch-browser index dbd9cf9c113e..b9be900e2a08 100755 --- a/bin/omarchy-launch-browser +++ b/bin/omarchy-launch-browser @@ -87,26 +87,49 @@ if ! desktop_exec_argv "$default_browser"; then exit 1 fi -browser_exec="" -skip_value=0 -for token in "${desktop_exec_argv[@]}"; do - if (( skip_value )); then - skip_value=0 - elif [[ $token == -u || $token == --unset || $token == -C || $token == --chdir ]]; then - skip_value=1 - elif [[ $token != env && $token != */env && $token != *=* && $token != -* && $token != run && $token != flatpak && $token != */flatpak ]]; then +# The browser is what an env or flatpak wrapper runs, including inside an +# env -S string; a Flatpak's is its app id, which is no command on the host. +browser_exec="" flatpak_app="" +tokens=("${desktop_exec_argv[@]}") +for (( i = 0; i < ${#tokens[@]}; i++ )); do + token=${tokens[i]} + case $token in + -u | --unset | -C | --chdir) (( i++ )) ;; + -S | --split-string | -S?* | --split-string=*) + if [[ $token == "-S" || $token == "--split-string" ]]; then + split_value=${tokens[i + 1]} + rest=("${tokens[@]:i+2}") + else + split_value=${token#--split-string=} + split_value=${split_value#-S} + rest=("${tokens[@]:i+1}") + fi + read -ra split <<<"$split_value" + tokens=("${tokens[@]:0:i}" "${split[@]}" "${rest[@]}") + (( i-- )) + ;; + env | */env | flatpak | */flatpak | run | -* | *=*) ;; + *) browser_exec=$token + [[ ${tokens[0]##*/} == "flatpak" ]] && flatpak_app=$token break - fi + ;; + esac done [[ -n $browser_exec ]] || browser_exec=${desktop_exec_argv[0]} # Only a private launch needs the browser's flag, and probing a Firefox-family # browser's --help starts the whole binary, so ordinary launches skip it and -# leave their arguments as they are. +# leave their arguments as they are. A Flatpak is named by its app id instead. private_flag="--private" if [[ " $* " == *" --private "* ]]; then - if "$browser_exec" --help 2>/dev/null | grep -q MOZ_LOG; then + if [[ -n $flatpak_app ]]; then + case ${flatpak_app,,} in + org.mozilla.firefox | io.gitlab.librewolf-community | app.zen_browser.zen | net.waterfox.waterfox | one.ablaze.floorp) private_flag="--private-window" ;; + com.microsoft.edge) private_flag="--inprivate" ;; + *) private_flag="--incognito" ;; + esac + elif "$browser_exec" --help 2>/dev/null | grep -q MOZ_LOG; then private_flag="--private-window" elif [[ $browser_exec =~ edge ]]; then private_flag="--inprivate" diff --git a/test/shell.d/launch-browser-test.sh b/test/shell.d/launch-browser-test.sh index 2f45aa030925..7b391cb8d929 100644 --- a/test/shell.d/launch-browser-test.sh +++ b/test/shell.d/launch-browser-test.sh @@ -160,6 +160,36 @@ expected=$(printf '%s\n' /usr/bin/env -u BROWSER chromium --name "Work Chromium" fail "a private launch expands %c and keeps its flag an option despite the Exec line's --" pass "a private launch finds the browser behind env options and keeps its flag an option" +cat >"$mock_bin/firefox" <<'SH' +#!/bin/bash +[[ $1 != "--help" ]] || { printf 'probed\n' >>"$OMARCHY_TEST_BROWSER_HELP"; echo MOZ_LOG; } +SH +chmod +x "$mock_bin/firefox" +cat >"$test_home/.local/share/applications/chromium.desktop" <<'EOF' +[Desktop Entry] +Exec=/usr/bin/env -S "MOZ_ENABLE_WAYLAND=1 firefox" %u +EOF + +rm -f "$help_log" +launch --private +[[ -s $help_log ]] || fail "a private launch probes the browser inside env -S, not env" +expected=$(printf '%s\n' /usr/bin/env -S "MOZ_ENABLE_WAYLAND=1 firefox" --private-window) +[[ $(sed '1,/^--$/d' "$launch_log") == "$expected" ]] || + fail "a private launch passes the private flag of the browser inside env -S" +pass "a private launch finds the browser inside env -S" + +cp "$mock_bin/chromium" "$mock_bin/flatpak" +cat >"$test_home/.local/share/applications/chromium.desktop" <<'EOF' +[Desktop Entry] +Exec=flatpak run --branch=stable --arch=x86_64 --command=firefox --file-forwarding org.mozilla.firefox @@u %u @@ +EOF + +launch --private +expected=$(printf '%s\n' flatpak run --branch=stable --arch=x86_64 --command=firefox --file-forwarding org.mozilla.firefox @@u @@ --private-window) +[[ $(sed '1,/^--$/d' "$launch_log") == "$expected" ]] || + fail "a private launch of a Flatpak Firefox passes --private-window from its app id" +pass "a private launch names a Flatpak browser's flag from its app id" + cat >"$mock_bin/setsid" <<'SH' #!/bin/bash exec "$@" From 6a713fcdbfd83f13a60fb17db62dff5adea2400b Mon Sep 17 00:00:00 2001 From: Omarchybot <317366263+omarchybot@users.noreply.github.com> Date: Sun, 1 Nov 2026 14:46:58 +0100 Subject: [PATCH 5/7] Honor env -S quoting and find a Flatpak behind env Splitting the env -S string on whitespace took a quoted value apart, so "LABEL='Work Browser' firefox" settled on Browser' rather than firefox. xargs splits it with the same quoting env uses. A Flatpak run through env also missed the app id path, since only a leading flatpak was recognised. Assignments and empty words are skipped before flatpak is looked for, so FLATPAK=/usr/bin/flatpak or env -S "" does not stop the search. Co-Authored-By: Codex Medium Co-Authored-By: muse-wonder via pi, thinking high Co-Authored-By: Claude Opus 5.5 --- bin/omarchy-launch-browser | 9 +++++---- test/shell.d/launch-browser-test.sh | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/bin/omarchy-launch-browser b/bin/omarchy-launch-browser index b9be900e2a08..993919ef820f 100755 --- a/bin/omarchy-launch-browser +++ b/bin/omarchy-launch-browser @@ -89,7 +89,7 @@ fi # The browser is what an env or flatpak wrapper runs, including inside an # env -S string; a Flatpak's is its app id, which is no command on the host. -browser_exec="" flatpak_app="" +browser_exec="" flatpak_app="" flatpak=0 tokens=("${desktop_exec_argv[@]}") for (( i = 0; i < ${#tokens[@]}; i++ )); do token=${tokens[i]} @@ -104,14 +104,15 @@ for (( i = 0; i < ${#tokens[@]}; i++ )); do split_value=${split_value#-S} rest=("${tokens[@]:i+1}") fi - read -ra split <<<"$split_value" + mapfile -t split < <(xargs -r -n1 printf '%s\n' <<<"$split_value" 2>/dev/null) tokens=("${tokens[@]:0:i}" "${split[@]}" "${rest[@]}") (( i-- )) ;; - env | */env | flatpak | */flatpak | run | -* | *=*) ;; + "" | *=* | env | */env | run | -*) ;; + flatpak | */flatpak) flatpak=1 ;; *) browser_exec=$token - [[ ${tokens[0]##*/} == "flatpak" ]] && flatpak_app=$token + (( flatpak )) && flatpak_app=$token break ;; esac diff --git a/test/shell.d/launch-browser-test.sh b/test/shell.d/launch-browser-test.sh index 7b391cb8d929..ed01787e02a3 100644 --- a/test/shell.d/launch-browser-test.sh +++ b/test/shell.d/launch-browser-test.sh @@ -167,13 +167,13 @@ SH chmod +x "$mock_bin/firefox" cat >"$test_home/.local/share/applications/chromium.desktop" <<'EOF' [Desktop Entry] -Exec=/usr/bin/env -S "MOZ_ENABLE_WAYLAND=1 firefox" %u +Exec=/usr/bin/env -S "LABEL='Work Browser' MOZ_ENABLE_WAYLAND=1 firefox" %u EOF rm -f "$help_log" launch --private [[ -s $help_log ]] || fail "a private launch probes the browser inside env -S, not env" -expected=$(printf '%s\n' /usr/bin/env -S "MOZ_ENABLE_WAYLAND=1 firefox" --private-window) +expected=$(printf '%s\n' /usr/bin/env -S "LABEL='Work Browser' MOZ_ENABLE_WAYLAND=1 firefox" --private-window) [[ $(sed '1,/^--$/d' "$launch_log") == "$expected" ]] || fail "a private launch passes the private flag of the browser inside env -S" pass "a private launch finds the browser inside env -S" @@ -181,11 +181,11 @@ pass "a private launch finds the browser inside env -S" cp "$mock_bin/chromium" "$mock_bin/flatpak" cat >"$test_home/.local/share/applications/chromium.desktop" <<'EOF' [Desktop Entry] -Exec=flatpak run --branch=stable --arch=x86_64 --command=firefox --file-forwarding org.mozilla.firefox @@u %u @@ +Exec=/usr/bin/env GDK_BACKEND=wayland flatpak run --branch=stable --arch=x86_64 --command=firefox --file-forwarding org.mozilla.firefox @@u %u @@ EOF launch --private -expected=$(printf '%s\n' flatpak run --branch=stable --arch=x86_64 --command=firefox --file-forwarding org.mozilla.firefox @@u @@ --private-window) +expected=$(printf '%s\n' /usr/bin/env GDK_BACKEND=wayland flatpak run --branch=stable --arch=x86_64 --command=firefox --file-forwarding org.mozilla.firefox @@u @@ --private-window) [[ $(sed '1,/^--$/d' "$launch_log") == "$expected" ]] || fail "a private launch of a Flatpak Firefox passes --private-window from its app id" pass "a private launch names a Flatpak browser's flag from its app id" From 8f7869933c4de0a43b8e60083aa04be48ff82df4 Mon Sep 17 00:00:00 2001 From: Omarchybot <317366263+omarchybot@users.noreply.github.com> Date: Wed, 18 Nov 2026 10:09:14 +0100 Subject: [PATCH 6/7] Share desktop Exec parsing and validate env-wrapped browsers Resolve browser availability from the same parsed argv used by the launchers, honoring PATH assignments while retaining wrapper checks for Flatpak and env options. This folds #17134's resolver fix and shared-helper pattern into #12533 without discarding desktop arguments. Stop the assignment scan at env options, including --split-string=, so they retain their previous availability behavior. Co-Authored-By: sundarshahi Co-Authored-By: GPT-6 High Co-Authored-By: Opus 5.5 High --- bin/omarchy-cmd-browser-exec | 78 +++++++++++++++++++++ bin/omarchy-cmd-default-browser | 32 ++++++--- bin/omarchy-launch-browser | 74 +------------------ bin/omarchy-launch-webapp | 74 +------------------ test/shell.d/default-browser-lookup-test.sh | 26 ++++++- 5 files changed, 126 insertions(+), 158 deletions(-) create mode 100755 bin/omarchy-cmd-browser-exec diff --git a/bin/omarchy-cmd-browser-exec b/bin/omarchy-cmd-browser-exec new file mode 100755 index 000000000000..01e7ef62dba3 --- /dev/null +++ b/bin/omarchy-cmd-browser-exec @@ -0,0 +1,78 @@ +#!/bin/bash + +# omarchy:summary=Shared desktop-entry Exec parsing for browser commands (source this file) +# omarchy:hidden=true + +# Undo the escapes every desktop entry string carries. +desktop_string() { + local string=$1 char i + REPLY="" + for (( i = 0; i < ${#string}; i++ )); do + char=${string:i:1} + if [[ $char == "\\" ]]; then + (( i++ )) + case ${string:i:1} in + s) char=" " ;; + n) char=$'\n' ;; + t) char=$'\t' ;; + r) char=$'\r' ;; + "\\") char="\\" ;; + *) char="\\${string:i:1}" ;; + esac + fi + REPLY+=$char + done +} + +desktop_exec_argv() { + local desktop=$1 + local file="" line="" name data_dir + desktop_exec_argv=() + # Read Exec= from the same data dirs omarchy-cmd-default-browser searched, in + # the same order, so the command always comes from the entry that was checked. + local -a data_dirs + IFS=: read -ra data_dirs <<<"${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}" + for data_dir in "${data_dirs[@]}"; do + file="$data_dir/applications/$desktop" + [[ -f $file ]] || continue + line=$(sed -n 's/^Exec=//p' "$file" | head -1) + break + done + [[ -n $line ]] || return 1 + desktop_string "$(sed -n 's/^Name=//p' "$file" | head -1)" + name=$REPLY + + # Split the Exec line by its own quoting, expanding %c and %k, keeping %% as + # %, and dropping the other field codes. A standalone -- goes too, or the + # launcher's own options after it would be read as operands. + desktop_string "$line" + local value=$REPLY arg="" char i quoted=0 started=0 + for (( i = 0; i < ${#value}; i++ )); do + char=${value:i:1} + if [[ $char == '"' ]]; then + (( quoted = !quoted, started = 1 )) + elif [[ $char == "\\" ]] && (( quoted )); then + (( i++ )) + arg+=${value:i:1} + elif [[ $char == "%" ]]; then + (( i++ )) + case ${value:i:1} in + "%") arg+="%" started=1 ;; + c) arg+=$name started=1 ;; + k) arg+=$file started=1 ;; + esac + elif [[ $char == " " ]] && (( ! quoted )); then + if (( started )) && [[ $arg != "--" ]]; then + desktop_exec_argv+=("$arg") + fi + arg="" started=0 + else + arg+=$char started=1 + fi + done + if (( started )) && [[ $arg != "--" ]]; then + desktop_exec_argv+=("$arg") + fi + + (( ${#desktop_exec_argv[@]} > 0 )) +} diff --git a/bin/omarchy-cmd-default-browser b/bin/omarchy-cmd-default-browser index 65e153a7de14..bc0373f6146c 100755 --- a/bin/omarchy-cmd-default-browser +++ b/bin/omarchy-cmd-default-browser @@ -11,20 +11,30 @@ IFS=: read -ra data_dirs <<<"${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIR IFS=: read -ra config_dirs <<<"${XDG_CONFIG_HOME:-$HOME/.config}:${XDG_CONFIG_DIRS:-/etc/xdg}" IFS=: read -ra desktops <<<"${XDG_CURRENT_DESKTOP:-}" -# Installed means the command of the entry the launchers will read, the first -# one found, still resolves: an entry of Omarchy's own can outlive the browser -# it launched. +source "$OMARCHY_PATH/bin/omarchy-cmd-browser-exec" + +# An env prefix can outlive its browser; check that browser on the PATH the +# entry supplies, while leaving Flatpak app IDs to their installed wrapper. installed() { - local data_dir command + local command assignment path=$PATH i=0 + local -a desktop_exec_argv + desktop_exec_argv "$1" || return 1 + command=${desktop_exec_argv[0]} - for data_dir in "${data_dirs[@]}"; do - [[ -r $data_dir/applications/$1 ]] || continue - command=$(sed -n 's/^Exec=\([^ ]*\).*/\1/p' "$data_dir/applications/$1" | head -1) - [[ -n $command ]] && command -v "$command" >/dev/null - return - done + if [[ $command == "env" || $command == */env ]]; then + i=1 + while [[ ${desktop_exec_argv[i]:-} == *=* && ${desktop_exec_argv[i]} != -* ]]; do + assignment=${desktop_exec_argv[i]} + [[ $assignment == PATH=* ]] && path=${assignment#PATH=} + (( i++ )) + done + # Option-bearing env wrappers keep their existing availability check. + if [[ ${desktop_exec_argv[i]:-} != -* ]]; then + command=${desktop_exec_argv[i]:-} + fi + fi - return 1 + [[ -n $command ]] && PATH=$path type -P "$command" >/dev/null } for config_dir in "${config_dirs[@]}"; do diff --git a/bin/omarchy-launch-browser b/bin/omarchy-launch-browser index 993919ef820f..90d38913ff0d 100755 --- a/bin/omarchy-launch-browser +++ b/bin/omarchy-launch-browser @@ -5,79 +5,7 @@ default_browser=$(omarchy-cmd-default-browser) -# Undo the escapes every desktop entry string carries. -desktop_string() { - local string=$1 char i - REPLY="" - for (( i = 0; i < ${#string}; i++ )); do - char=${string:i:1} - if [[ $char == "\\" ]]; then - (( i++ )) - case ${string:i:1} in - s) char=" " ;; - n) char=$'\n' ;; - t) char=$'\t' ;; - r) char=$'\r' ;; - "\\") char="\\" ;; - *) char="\\${string:i:1}" ;; - esac - fi - REPLY+=$char - done -} - -desktop_exec_argv() { - local desktop=$1 - local file="" line="" name data_dir - desktop_exec_argv=() - # Read Exec= from the same data dirs omarchy-cmd-default-browser searched, in - # the same order, so the command always comes from the entry that was checked. - local -a data_dirs - IFS=: read -ra data_dirs <<<"${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}" - for data_dir in "${data_dirs[@]}"; do - file="$data_dir/applications/$desktop" - [[ -f $file ]] || continue - line=$(sed -n 's/^Exec=//p' "$file" | head -1) - break - done - [[ -n $line ]] || return 1 - desktop_string "$(sed -n 's/^Name=//p' "$file" | head -1)" - name=$REPLY - - # Split the Exec line by its own quoting, expanding %c and %k, keeping %% as - # %, and dropping the other field codes. A standalone -- goes too, or the - # launcher's own options after it would be read as operands. - desktop_string "$line" - local value=$REPLY arg="" char i quoted=0 started=0 - for (( i = 0; i < ${#value}; i++ )); do - char=${value:i:1} - if [[ $char == '"' ]]; then - (( quoted = !quoted, started = 1 )) - elif [[ $char == "\\" ]] && (( quoted )); then - (( i++ )) - arg+=${value:i:1} - elif [[ $char == "%" ]]; then - (( i++ )) - case ${value:i:1} in - "%") arg+="%" started=1 ;; - c) arg+=$name started=1 ;; - k) arg+=$file started=1 ;; - esac - elif [[ $char == " " ]] && (( ! quoted )); then - if (( started )) && [[ $arg != "--" ]]; then - desktop_exec_argv+=("$arg") - fi - arg="" started=0 - else - arg+=$char started=1 - fi - done - if (( started )) && [[ $arg != "--" ]]; then - desktop_exec_argv+=("$arg") - fi - - (( ${#desktop_exec_argv[@]} > 0 )) -} +source "$OMARCHY_PATH/bin/omarchy-cmd-browser-exec" # Handing an empty command to uwsm-app surfaces as "Command not found: \"\"", # which fails a keybinding silently. Say what is missing and how to fix it. diff --git a/bin/omarchy-launch-webapp b/bin/omarchy-launch-webapp index 9213d8f21422..64670903acc1 100755 --- a/bin/omarchy-launch-webapp +++ b/bin/omarchy-launch-webapp @@ -11,79 +11,7 @@ chromium* | google-chrome* | brave* | microsoft-edge* | opera* | vivaldi* | heli *) browsers=(google-chrome.desktop chromium.desktop) ;; esac -# Undo the escapes every desktop entry string carries. -desktop_string() { - local string=$1 char i - REPLY="" - for (( i = 0; i < ${#string}; i++ )); do - char=${string:i:1} - if [[ $char == "\\" ]]; then - (( i++ )) - case ${string:i:1} in - s) char=" " ;; - n) char=$'\n' ;; - t) char=$'\t' ;; - r) char=$'\r' ;; - "\\") char="\\" ;; - *) char="\\${string:i:1}" ;; - esac - fi - REPLY+=$char - done -} - -desktop_exec_argv() { - local desktop=$1 - local file="" line="" name data_dir - desktop_exec_argv=() - # Read Exec= from the same data dirs omarchy-cmd-default-browser searched, in - # the same order, so the command always comes from the entry that was checked. - local -a data_dirs - IFS=: read -ra data_dirs <<<"${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}" - for data_dir in "${data_dirs[@]}"; do - file="$data_dir/applications/$desktop" - [[ -f $file ]] || continue - line=$(sed -n 's/^Exec=//p' "$file" | head -1) - break - done - [[ -n $line ]] || return 1 - desktop_string "$(sed -n 's/^Name=//p' "$file" | head -1)" - name=$REPLY - - # Split the Exec line by its own quoting, expanding %c and %k, keeping %% as - # %, and dropping the other field codes. A standalone -- goes too, or the - # launcher's own options after it would be read as operands. - desktop_string "$line" - local value=$REPLY arg="" char i quoted=0 started=0 - for (( i = 0; i < ${#value}; i++ )); do - char=${value:i:1} - if [[ $char == '"' ]]; then - (( quoted = !quoted, started = 1 )) - elif [[ $char == "\\" ]] && (( quoted )); then - (( i++ )) - arg+=${value:i:1} - elif [[ $char == "%" ]]; then - (( i++ )) - case ${value:i:1} in - "%") arg+="%" started=1 ;; - c) arg+=$name started=1 ;; - k) arg+=$file started=1 ;; - esac - elif [[ $char == " " ]] && (( ! quoted )); then - if (( started )) && [[ $arg != "--" ]]; then - desktop_exec_argv+=("$arg") - fi - arg="" started=0 - else - arg+=$char started=1 - fi - done - if (( started )) && [[ $arg != "--" ]]; then - desktop_exec_argv+=("$arg") - fi - - (( ${#desktop_exec_argv[@]} > 0 )) -} +source "$OMARCHY_PATH/bin/omarchy-cmd-browser-exec" for browser in "${browsers[@]}"; do desktop_exec_argv "$browser" && break diff --git a/test/shell.d/default-browser-lookup-test.sh b/test/shell.d/default-browser-lookup-test.sh index 11faaf1fc940..22dd323fd2fe 100644 --- a/test/shell.d/default-browser-lookup-test.sh +++ b/test/shell.d/default-browser-lookup-test.sh @@ -38,6 +38,7 @@ echo "Exec=brave %U" >"$XDG_DATA_DIRS/applications/brave-browser.desktop" # a system copy that the launchers would never read. echo "Exec=removed-browser %U" >"$XDG_DATA_HOME/applications/removed.desktop" echo "Exec=brave %U" >"$XDG_DATA_DIRS/applications/removed.desktop" +echo "Exec=env DRI_PRIME=0 removed-browser %U" >"$XDG_DATA_HOME/applications/env-removed.desktop" cat >"$XDG_CONFIG_HOME/mimeapps.list" <<'EOF' [Added Associations] @@ -45,7 +46,7 @@ x-scheme-handler/http=firefox.desktop; [Default Applications] text/html=firefox.desktop -x-scheme-handler/http=missing.desktop;removed.desktop;chromium.desktop; +x-scheme-handler/http=missing.desktop;removed.desktop;env-removed.desktop;chromium.desktop; EOF [[ $(omarchy-cmd-default-browser) == "chromium.desktop" ]] || @@ -108,3 +109,26 @@ chmod +x "$mock_bin/xdg-settings" "$mock_bin/xdg-mime" fail "default browser skips an xdg-settings answer that is not installed" "$(omarchy-cmd-default-browser)" pass "default browser checks that fallback answers are installed" + +# An env prefix may quote a value with spaces and provide its own browser PATH. +mkdir -p "$test_tmp/opt/bin" +printf '#!/bin/bash\n' >"$test_tmp/opt/bin/custom-browser" +chmod +x "$test_tmp/opt/bin/custom-browser" +echo 'Exec=env "CHROME_CONFIG_HOME=/home/alex/Browser Profiles" chromium %U' >"$XDG_DATA_HOME/applications/quoted.desktop" +echo "Exec=env PATH=$test_tmp/opt/bin:/usr/bin custom-browser %U" >"$XDG_DATA_HOME/applications/custom-path.desktop" + +# Flatpak exports name a host wrapper, not an executable for the app ID. +printf '#!/bin/bash\n' >"$mock_bin/flatpak" +chmod +x "$mock_bin/flatpak" +echo 'Exec=flatpak run org.mozilla.firefox %u' >"$XDG_DATA_HOME/applications/flatpak.desktop" + +# Equals signs in env options must not turn those options into assignments. +echo 'Exec=env "--split-string=A=1 firefox" %u' >"$XDG_DATA_HOME/applications/env-options.desktop" + +for entry in quoted.desktop custom-path.desktop flatpak.desktop env-options.desktop; do + printf '[Default Applications]\nx-scheme-handler/http=%s\n' "$entry" >"$XDG_CONFIG_HOME/mimeapps.list" + [[ $(omarchy-cmd-default-browser) == "$entry" ]] || + fail "default browser accepts $entry" "$(omarchy-cmd-default-browser)" +done + +pass "default browser checks quoted env prefixes, their PATH and Flatpak wrappers" From 378e9ed547650b5163daf9c7bbb0847b2beb07d9 Mon Sep 17 00:00:00 2001 From: Omarchybot <317366263+omarchybot@users.noreply.github.com> Date: Wed, 25 Nov 2026 07:11:15 +0100 Subject: [PATCH 7/7] Make the CRLF launcher check independent of the session environment The launcher focuses only when HYPRLAND_INSTANCE_SIGNATURE is set. Give the mocked focus check its own signature and clear the earlier focus log, so it exercises the declared class in plain shells as well as compositor sessions. Co-Authored-By: GPT-6 (reasoning effort not exposed) Co-Authored-By: Opus 5.5 High --- test/shell.d/launch-browser-test.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/shell.d/launch-browser-test.sh b/test/shell.d/launch-browser-test.sh index 31bfeebdf117..f79cf141538d 100644 --- a/test/shell.d/launch-browser-test.sh +++ b/test/shell.d/launch-browser-test.sh @@ -146,7 +146,8 @@ launch --private pass "a private launch passes the browser's private flag" printf '[Desktop Entry]\r\nName=Work Chromium\r\nExec=chromium --name %%c %%U\r\nStartupWMClass=chromium-crlf\r\n' >"$test_home/.local/share/applications/chromium.desktop" -launch "https://example.test/crlf" +rm -f "$focus_log" +HYPRLAND_INSTANCE_SIGNATURE=test launch "https://example.test/crlf" expected=$(printf '%s\n' chromium --name "Work Chromium" https://example.test/crlf) [[ $(sed '1,/^--$/d' "$launch_log") == "$expected" ]] || fail "a CRLF entry passes its decoded name and URL without carriage returns" "$(cat "$launch_log")"