mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 15:04:42 +00:00
Tighten dock removal and add brew uninstall fallback
This commit is contained in:
@@ -177,9 +177,6 @@ remove_apps_from_dock() {
|
|||||||
local changed=false
|
local changed=false
|
||||||
for target in "${targets[@]}"; do
|
for target in "${targets[@]}"; do
|
||||||
local app_path="$target"
|
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
|
# Normalize path for comparison - realpath might fail if app is already deleted
|
||||||
local full_path
|
local full_path
|
||||||
full_path=$(cd "$(dirname "$app_path")" 2> /dev/null && pwd || echo "")
|
full_path=$(cd "$(dirname "$app_path")" 2> /dev/null && pwd || echo "")
|
||||||
@@ -194,16 +191,14 @@ remove_apps_from_dock() {
|
|||||||
|
|
||||||
local url
|
local url
|
||||||
url=$(/usr/libexec/PlistBuddy -c "Print :persistent-apps:$i:tile-data:file-data:_CFURLString" "$plist" 2> /dev/null || echo "")
|
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)
|
# Match by full path only to avoid removing apps with the same label.
|
||||||
if [[ "$label" == "$app_name" ]] || [[ "$url" == *"$app_name.app"* ]]; then
|
if [[ -n "$full_path" && "$url" == *"$full_path"* ]]; then
|
||||||
# Double check path if possible to avoid false positives for similarly named apps
|
if /usr/libexec/PlistBuddy -c "Delete :persistent-apps:$i" "$plist" 2> /dev/null; then
|
||||||
if [[ -n "$full_path" && "$url" == *"$full_path"* ]] || [[ "$label" == "$app_name" ]]; then
|
changed=true
|
||||||
if /usr/libexec/PlistBuddy -c "Delete :persistent-apps:$i" "$plist" 2> /dev/null; then
|
# After deletion, current index i now points to the next item
|
||||||
changed=true
|
continue
|
||||||
# After deletion, current index i now points to the next item
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
((i++))
|
((i++))
|
||||||
|
|||||||
@@ -373,15 +373,21 @@ batch_uninstall_applications() {
|
|||||||
if [[ "$is_brew_cask" == "true" && -n "$cask_name" ]]; then
|
if [[ "$is_brew_cask" == "true" && -n "$cask_name" ]]; then
|
||||||
# Use brew uninstall --cask with progress indicator
|
# Use brew uninstall --cask with progress indicator
|
||||||
local brew_output_file=$(mktemp)
|
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
|
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
|
if [[ "$needs_sudo" == true ]]; then
|
||||||
safe_sudo_remove "$app_path" || reason="remove failed"
|
safe_sudo_remove "$app_path" || reason="remove failed"
|
||||||
else
|
else
|
||||||
safe_remove "$app_path" true || reason="remove failed"
|
safe_remove "$app_path" true || reason="remove failed"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
rm -f "$brew_output_file"
|
|
||||||
elif [[ "$needs_sudo" == true ]]; then
|
elif [[ "$needs_sudo" == true ]]; then
|
||||||
if ! safe_sudo_remove "$app_path"; then
|
if ! safe_sudo_remove "$app_path"; then
|
||||||
local app_owner=$(get_file_owner "$app_path")
|
local app_owner=$(get_file_owner "$app_path")
|
||||||
|
|||||||
Reference in New Issue
Block a user