Fix launcher entry removal

This commit is contained in:
David Heinemeier Hansson
2026-06-28 20:46:23 -04:00
parent 2f4fc48791
commit ba0d2a764f
6 changed files with 72 additions and 15 deletions
+24 -4
View File
@@ -20,12 +20,14 @@ if [[ $desktop_file_name != *.desktop ]]; then
desktop_file_name="$desktop_file_name.desktop" desktop_file_name="$desktop_file_name.desktop"
fi fi
user_desktop_dirs=()
desktop_dirs=() desktop_dirs=()
if [[ -n ${XDG_DATA_HOME-} ]]; then if [[ -n ${XDG_DATA_HOME-} ]]; then
desktop_dirs+=("$XDG_DATA_HOME/applications") user_desktop_dirs+=("$XDG_DATA_HOME/applications")
else else
desktop_dirs+=("$HOME/.local/share/applications") user_desktop_dirs+=("$HOME/.local/share/applications")
fi fi
desktop_dirs+=("${user_desktop_dirs[@]}")
if [[ -n ${XDG_DATA_DIRS-} ]]; then if [[ -n ${XDG_DATA_DIRS-} ]]; then
IFS=: read -ra data_dirs <<<"$XDG_DATA_DIRS" IFS=: read -ra data_dirs <<<"$XDG_DATA_DIRS"
@@ -50,17 +52,35 @@ if [[ -z $desktop_file ]]; then
exit 1 exit 1
fi fi
is_user_desktop_file() {
local dir desktop_dir
desktop_dir="${desktop_file%/*}"
for dir in "${user_desktop_dirs[@]}"; do
[[ $desktop_dir == $dir ]] && return 0
done
return 1
}
desktop_name="${desktop_file##*/}" desktop_name="${desktop_file##*/}"
desktop_name="${desktop_name%.desktop}" desktop_name="${desktop_name%.desktop}"
exec_line="$(sed -n 's/^Exec=//p' "$desktop_file" | head -1)" exec_line="$(sed -n 's/^Exec=//p' "$desktop_file" | head -1)"
if [[ $exec_line =~ omarchy-launch-webapp|omarchy-webapp-handler ]]; then if [[ $exec_line =~ omarchy-launch-webapp|omarchy-webapp-handler ]]; then
omarchy-webapp-remove "$desktop_name" OMARCHY_REMOVE_NOTIFY=false omarchy-webapp-remove "$desktop_name"
exit 0 exit 0
fi fi
if [[ $exec_line =~ (^|[[:space:]])(\$TERMINAL|xdg-terminal-exec)[[:space:]].*-e([[:space:]]|$) ]]; then if [[ $exec_line =~ (^|[[:space:]])(\$TERMINAL|xdg-terminal-exec)[[:space:]].*-e([[:space:]]|$) ]]; then
omarchy-tui-remove "$desktop_name" OMARCHY_REMOVE_NOTIFY=false omarchy-tui-remove "$desktop_name"
exit 0
fi
if is_user_desktop_file; then
display_name="${entry_name:-$desktop_name}"
rm -f "$desktop_file"
update-desktop-database "${desktop_file%/*}" &>/dev/null || true
exit 0 exit 0
fi fi
+2
View File
@@ -36,4 +36,6 @@ fi
icon_name=$(printf '%s\n' "$APP_NAME" | tr '[:upper:]' '[:lower:]' | sed 's/[^[:alnum:]]\+/-/g; s/^-//; s/-$//') icon_name=$(printf '%s\n' "$APP_NAME" | tr '[:upper:]' '[:lower:]' | sed 's/[^[:alnum:]]\+/-/g; s/^-//; s/-$//')
rm -f "$DESKTOP_DIR/$APP_NAME.desktop" rm -f "$DESKTOP_DIR/$APP_NAME.desktop"
rm -f "$ICON_DIR/$icon_name.png" "$ICON_DIR/$APP_NAME.png" "$OLD_ICON_DIR/$APP_NAME.png" rm -f "$ICON_DIR/$icon_name.png" "$ICON_DIR/$APP_NAME.png" "$OLD_ICON_DIR/$APP_NAME.png"
if [[ ${OMARCHY_REMOVE_NOTIFY:-true} != "false" ]]; then
omarchy-notification-send -g  "TUI removed" "$APP_NAME" omarchy-notification-send -g  "TUI removed" "$APP_NAME"
fi
+2
View File
@@ -37,5 +37,7 @@ icon_name=$(printf '%s\n' "$APP_NAME" | tr '[:upper:]' '[:lower:]' | sed 's/[^[:
rm -f "$DESKTOP_DIR/$APP_NAME.desktop" rm -f "$DESKTOP_DIR/$APP_NAME.desktop"
rm -f "$ICON_DIR/$icon_name.png" "$ICON_DIR/$APP_NAME.png" "$OLD_ICON_DIR/$APP_NAME.png" rm -f "$ICON_DIR/$icon_name.png" "$ICON_DIR/$APP_NAME.png" "$OLD_ICON_DIR/$APP_NAME.png"
if [[ ${OMARCHY_REMOVE_NOTIFY:-true} != "false" ]]; then
omarchy-notification-send -g  "Web app removed" "$APP_NAME" omarchy-notification-send -g  "Web app removed" "$APP_NAME"
fi
update-desktop-database "$DESKTOP_DIR" &>/dev/null update-desktop-database "$DESKTOP_DIR" &>/dev/null
-1
View File
@@ -276,7 +276,6 @@ Item {
var desktopId = String(entry.id || "") var desktopId = String(entry.id || "")
var name = root.entryName(entry) var name = root.entryName(entry)
root.cancelDelete() root.cancelDelete()
root.dismiss()
Quickshell.execDetached([root.omarchyPath + "/bin/omarchy-remove-launcher-entry", desktopId, name]) Quickshell.execDetached([root.omarchyPath + "/bin/omarchy-remove-launcher-entry", desktopId, name])
} }
+33 -8
View File
@@ -7,7 +7,7 @@ source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
tmp_dir="$(mktemp -d)" tmp_dir="$(mktemp -d)"
trap 'rm -rf "$tmp_dir"' EXIT trap 'rm -rf "$tmp_dir"' EXIT
mkdir -p "$tmp_dir/data/applications" "$tmp_dir/bin" mkdir -p "$tmp_dir/data/applications" "$tmp_dir/system/applications" "$tmp_dir/bin"
write_fake_command() { write_fake_command() {
local name="$1" local name="$1"
@@ -15,7 +15,7 @@ write_fake_command() {
cat >"$tmp_dir/bin/$name" <<SCRIPT cat >"$tmp_dir/bin/$name" <<SCRIPT
#!/bin/bash #!/bin/bash
printf '%s:%s\\n' '$prefix' "\$*" >>"\$TEST_LOG" printf '%s:%s:%s\\n' '$prefix' "\${OMARCHY_REMOVE_NOTIFY:-}" "\$*" >>"\$TEST_LOG"
SCRIPT SCRIPT
chmod +x "$tmp_dir/bin/$name" chmod +x "$tmp_dir/bin/$name"
} }
@@ -24,9 +24,21 @@ write_fake_command omarchy-webapp-remove web
write_fake_command omarchy-tui-remove tui write_fake_command omarchy-tui-remove tui
write_fake_command omarchy-launch-floating-terminal-with-presentation terminal write_fake_command omarchy-launch-floating-terminal-with-presentation terminal
cat >"$tmp_dir/bin/omarchy-notification-send" <<'SCRIPT'
#!/bin/bash
printf 'notify::%s\n' "$*" >>"$TEST_LOG"
SCRIPT
chmod +x "$tmp_dir/bin/omarchy-notification-send"
cat >"$tmp_dir/bin/update-desktop-database" <<'SCRIPT'
#!/bin/bash
:
SCRIPT
chmod +x "$tmp_dir/bin/update-desktop-database"
cat >"$tmp_dir/bin/pacman" <<'SCRIPT' cat >"$tmp_dir/bin/pacman" <<'SCRIPT'
#!/bin/bash #!/bin/bash
if [[ $1 == "-Qqo" ]]; then if [[ $1 == "-Qqo" && $2 == */native.desktop ]]; then
printf 'native-pkg\n' printf 'native-pkg\n'
fi fi
SCRIPT SCRIPT
@@ -44,28 +56,41 @@ Name=Docker
Exec=xdg-terminal-exec --app-id=TUI.tile -e lazydocker Exec=xdg-terminal-exec --app-id=TUI.tile -e lazydocker
DESKTOP DESKTOP
cat >"$tmp_dir/data/applications/native.desktop" <<'DESKTOP' cat >"$tmp_dir/system/applications/native.desktop" <<'DESKTOP'
[Desktop Entry] [Desktop Entry]
Name=Native Name=Native
Exec=native Exec=native
DESKTOP DESKTOP
cat >"$tmp_dir/data/applications/aliens.desktop" <<'DESKTOP'
[Desktop Entry]
Name=Aliens
Exec=retroarch -L /usr/lib/libretro/fbneo_libretro.so /home/example/Games/roms/fbneo/aliens.zip
DESKTOP
export TEST_LOG="$tmp_dir/log" export TEST_LOG="$tmp_dir/log"
export PATH="$tmp_dir/bin:$PATH" export PATH="$tmp_dir/bin:$PATH"
export XDG_DATA_HOME="$tmp_dir/data" export XDG_DATA_HOME="$tmp_dir/data"
export XDG_DATA_DIRS= export XDG_DATA_DIRS="$tmp_dir/system"
"$ROOT/bin/omarchy-remove-launcher-entry" Basecamp.desktop Basecamp "$ROOT/bin/omarchy-remove-launcher-entry" Basecamp.desktop Basecamp
"$ROOT/bin/omarchy-remove-launcher-entry" Docker.desktop Docker "$ROOT/bin/omarchy-remove-launcher-entry" Docker.desktop Docker
"$ROOT/bin/omarchy-remove-launcher-entry" native.desktop Native "$ROOT/bin/omarchy-remove-launcher-entry" native.desktop Native
"$ROOT/bin/omarchy-remove-launcher-entry" aliens.desktop Aliens
mapfile -t lines <"$TEST_LOG" mapfile -t lines <"$TEST_LOG"
[[ ${lines[0]} == "web:Basecamp" ]] || fail "launcher remove routes web apps by desktop name" "${lines[0]}" [[ ${lines[0]} == "web:false:Basecamp" ]] || fail "launcher remove routes web apps by desktop name" "${lines[0]}"
pass "launcher remove routes web apps by desktop name" pass "launcher remove routes web apps by desktop name"
[[ ${lines[1]} == "tui:Docker" ]] || fail "launcher remove routes TUIs by desktop name" "${lines[1]}" [[ ${lines[1]} == "tui:false:Docker" ]] || fail "launcher remove routes TUIs by desktop name" "${lines[1]}"
pass "launcher remove routes TUIs by desktop name" pass "launcher remove routes TUIs by desktop name"
[[ ${lines[2]} == "terminal:echo Uninstalling Native...; sudo pacman -Rns native-pkg" ]] || fail "launcher remove opens package uninstall flow" "${lines[2]}" [[ ${lines[2]} == "terminal::echo Uninstalling Native...; sudo pacman -Rns native-pkg" ]] || fail "launcher remove opens package uninstall flow" "${lines[2]}"
pass "launcher remove opens package uninstall flow" pass "launcher remove opens package uninstall flow"
[[ ! -e $tmp_dir/data/applications/aliens.desktop ]] || fail "launcher remove deletes user-owned desktop files"
pass "launcher remove deletes user-owned desktop files"
(( ${#lines[@]} == 3 )) || fail "launcher remove does not notify for user-owned desktop files" "$(printf '%s\n' "${lines[@]}")"
pass "launcher remove does not notify for user-owned desktop files"
+9
View File
@@ -5,7 +5,9 @@ set -euo pipefail
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
run_node_test <<'JS' run_node_test <<'JS'
const fs = require('fs')
const search = requireFromRoot('shell/plugins/launcher/LauncherSearch.js') const search = requireFromRoot('shell/plugins/launcher/LauncherSearch.js')
const launcherQml = fs.readFileSync(path.join(root, 'shell/plugins/launcher/Launcher.qml'), 'utf8')
const entries = [ const entries = [
{ {
@@ -65,4 +67,11 @@ assertEqual(acronymMatches[0], 'Google Contacts', 'short acronym matching still
const directMatches = search.sortedEntries(entries, 'obs').map(row => search.entryName(row.entry)) const directMatches = search.sortedEntries(entries, 'obs').map(row => search.entryName(row.entry))
assertEqual(directMatches[0], 'OBS Studio', 'direct app-name matching still works') assertEqual(directMatches[0], 'OBS Studio', 'direct app-name matching still works')
const confirmDeleteMatch = launcherQml.match(/function confirmDelete\(\) \{([\s\S]*?)\n \}/)
assert(confirmDeleteMatch, 'launcher confirmDelete function exists')
assert(
!confirmDeleteMatch[1].includes('root.dismiss()'),
'launcher delete keeps launcher open after confirmation'
)
JS JS