mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 18:34:46 +00:00
feat: enhance uninstall with launch items and login items cleanup
- Add automatic cleanup of LaunchAgents/Daemons (Issue #315) - Support both system and user-level launch paths - Add Login Items cleanup (fixing broken entries like CodexBar) - Improve Homebrew uninstall logging visibility - Update security audit and tests
This commit is contained in:
@@ -88,6 +88,40 @@ stop_launch_services() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Remove macOS Login Items for an app
|
||||
remove_login_item() {
|
||||
local app_name="$1"
|
||||
local bundle_id="$2"
|
||||
|
||||
# Skip if no identifiers provided
|
||||
[[ -z "$app_name" && -z "$bundle_id" ]] && return 0
|
||||
|
||||
# Strip .app suffix if present (login items don't include it)
|
||||
local clean_name="${app_name%.app}"
|
||||
|
||||
# Remove from Login Items using index-based deletion (handles broken items)
|
||||
if [[ -n "$clean_name" ]]; then
|
||||
osascript <<-EOF 2>/dev/null || true
|
||||
tell application "System Events"
|
||||
try
|
||||
set itemCount to count of login items
|
||||
-- Delete in reverse order to avoid index shifting
|
||||
repeat with i from itemCount to 1 by -1
|
||||
try
|
||||
set itemName to name of login item i
|
||||
if itemName is "$clean_name" then
|
||||
delete login item i
|
||||
end if
|
||||
end try
|
||||
end repeat
|
||||
end try
|
||||
end tell
|
||||
EOF
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
# Remove files (handles symlinks, optional sudo).
|
||||
remove_file_list() {
|
||||
local file_list="$1"
|
||||
@@ -364,6 +398,9 @@ batch_uninstall_applications() {
|
||||
[[ -n "$system_files" ]] && has_system_files="true"
|
||||
stop_launch_services "$bundle_id" "$has_system_files"
|
||||
|
||||
# Remove from Login Items
|
||||
remove_login_item "$app_name" "$bundle_id"
|
||||
|
||||
if ! force_kill_app "$app_name" "$app_path"; then
|
||||
reason="still running"
|
||||
fi
|
||||
@@ -371,15 +408,20 @@ batch_uninstall_applications() {
|
||||
# Remove the application only if not running.
|
||||
if [[ -z "$reason" ]]; then
|
||||
if [[ "$is_brew_cask" == "true" && -n "$cask_name" ]]; then
|
||||
# Use brew uninstall --cask with progress indicator
|
||||
local brew_output_file=$(mktemp)
|
||||
# Stop spinner before brew output
|
||||
if [[ -t 1 ]]; then
|
||||
stop_inline_spinner
|
||||
fi
|
||||
|
||||
# Use brew uninstall --cask - show output directly
|
||||
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" 2>&1; then
|
||||
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
|
||||
# Fallback to manual cleanup
|
||||
[[ -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
|
||||
|
||||
Reference in New Issue
Block a user