diff --git a/lib/core/common.sh b/lib/core/common.sh index d34e415..0b4e6b8 100755 --- a/lib/core/common.sh +++ b/lib/core/common.sh @@ -177,9 +177,6 @@ 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 "") @@ -194,16 +191,14 @@ 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 full path only to avoid removing apps with the same label. + if [[ -n "$full_path" && "$url" == *"$full_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++)) diff --git a/lib/uninstall/batch.sh b/lib/uninstall/batch.sh index 1d7e0ee..4b8c90b 100755 --- a/lib/uninstall/batch.sh +++ b/lib/uninstall/batch.sh @@ -373,15 +373,21 @@ batch_uninstall_applications() { if [[ "$is_brew_cask" == "true" && -n "$cask_name" ]]; then # Use brew uninstall --cask with progress indicator local brew_output_file=$(mktemp) + local brew_failed=false if ! run_with_timeout 120 brew uninstall --cask "$cask_name" > "$brew_output_file" 2>&1; then - # Fallback to manual removal if brew fails + brew_failed=true + log_warning "brew uninstall failed for $app_name, falling back to manual cleanup" + fi + rm -f "$brew_output_file" + if [[ "$brew_failed" == "true" ]]; then + [[ -z "$related_files" ]] && related_files=$(find_app_files "$bundle_id" "$app_name") + [[ -z "$system_files" ]] && system_files=$(find_app_system_files "$bundle_id" "$app_name") if [[ "$needs_sudo" == true ]]; then safe_sudo_remove "$app_path" || reason="remove failed" else safe_remove "$app_path" true || reason="remove failed" fi fi - rm -f "$brew_output_file" elif [[ "$needs_sudo" == true ]]; then if ! safe_sudo_remove "$app_path"; then local app_owner=$(get_file_owner "$app_path")