1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-11 15:18:59 +00:00

Merge branch 'dev' into fix/harden-brew-uninstall

This commit is contained in:
Tw93
2026-01-15 14:00:20 +08:00
committed by GitHub
12 changed files with 132 additions and 70 deletions

View File

@@ -124,14 +124,14 @@ remove_apps_from_dock() {
local changed=false
for target in "${targets[@]}"; do
local app_path="$target"
local app_name
app_name=$(basename "$app_path" .app)
# Normalize path for comparison - realpath might fail if app is already deleted
local full_path
full_path=$(cd "$(dirname "$app_path")" 2> /dev/null && pwd || echo "")
[[ -n "$full_path" ]] && full_path="$full_path/$(basename "$app_path")"
# URL-encode the path for matching against Dock URLs (spaces -> %20)
local encoded_path="${full_path// /%20}"
# Find the index of the app in persistent-apps
local i=0
while true; do
@@ -141,16 +141,17 @@ remove_apps_from_dock() {
local url
url=$(/usr/libexec/PlistBuddy -c "Print :persistent-apps:$i:tile-data:file-data:_CFURLString" "$plist" 2> /dev/null || echo "")
[[ -z "$url" ]] && {
((i++))
continue
}
# Match by label or by path (parsing the CFURLString which is usually a file:// URL)
if [[ "$label" == "$app_name" ]] || [[ "$url" == *"$app_name.app"* ]]; then
# Double check path if possible to avoid false positives for similarly named apps
if [[ -n "$full_path" && "$url" == *"$full_path"* ]] || [[ "$label" == "$app_name" ]]; then
if /usr/libexec/PlistBuddy -c "Delete :persistent-apps:$i" "$plist" 2> /dev/null; then
changed=true
# After deletion, current index i now points to the next item
continue
fi
# Match by URL-encoded path to handle spaces in app names
if [[ -n "$encoded_path" && "$url" == *"$encoded_path"* ]]; then
if /usr/libexec/PlistBuddy -c "Delete :persistent-apps:$i" "$plist" 2> /dev/null; then
changed=true
# After deletion, current index i now points to the next item
continue
fi
fi
((i++))