mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 09:46:44 +00:00
uninstall: refine protection flow and menu filtering
This commit is contained in:
@@ -707,7 +707,13 @@ should_protect_data() {
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Most apps won't match, return early
|
# Fallback: check against the full DATA_PROTECTED_BUNDLES list
|
||||||
|
for pattern in "${DATA_PROTECTED_BUNDLES[@]}"; do
|
||||||
|
if bundle_matches_pattern "$bundle_id" "$pattern"; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -772,7 +778,8 @@ should_protect_path() {
|
|||||||
# Matches: .../Library/Group Containers/group.id/...
|
# Matches: .../Library/Group Containers/group.id/...
|
||||||
if [[ "$path" =~ /Library/Containers/([^/]+) ]] || [[ "$path" =~ /Library/Group\ Containers/([^/]+) ]]; then
|
if [[ "$path" =~ /Library/Containers/([^/]+) ]] || [[ "$path" =~ /Library/Group\ Containers/([^/]+) ]]; then
|
||||||
local bundle_id="${BASH_REMATCH[1]}"
|
local bundle_id="${BASH_REMATCH[1]}"
|
||||||
if should_protect_data "$bundle_id"; then
|
# In uninstall mode, only system components are protected; skip data protection
|
||||||
|
if [[ "${MOLE_UNINSTALL_MODE:-0}" != "1" ]] && should_protect_data "$bundle_id"; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -657,6 +657,14 @@ paginated_multi_select() {
|
|||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
"SPACE")
|
"SPACE")
|
||||||
|
# In filter mode with active text, treat space as search character
|
||||||
|
if [[ -n "$filter_text" ]]; then
|
||||||
|
filter_text+=" "
|
||||||
|
rebuild_view
|
||||||
|
cursor_pos=0
|
||||||
|
need_full_redraw=true
|
||||||
|
continue
|
||||||
|
fi
|
||||||
local idx=$((top_index + cursor_pos))
|
local idx=$((top_index + cursor_pos))
|
||||||
if [[ $idx -lt ${#view_indices[@]} ]]; then
|
if [[ $idx -lt ${#view_indices[@]} ]]; then
|
||||||
local real="${view_indices[idx]}"
|
local real="${view_indices[idx]}"
|
||||||
|
|||||||
@@ -300,18 +300,15 @@ batch_uninstall_applications() {
|
|||||||
echo -e "${PURPLE_BOLD}Files to be removed:${NC}"
|
echo -e "${PURPLE_BOLD}Files to be removed:${NC}"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Warn if user data is detected.
|
# Warn if brew cask apps are present.
|
||||||
local has_user_data=false
|
local has_brew_cask=false
|
||||||
for detail in "${app_details[@]}"; do
|
for detail in "${app_details[@]}"; do
|
||||||
IFS='|' read -r _ _ _ _ _ _ has_sensitive_data <<< "$detail"
|
IFS='|' read -r _ _ _ _ _ _ _ _ is_brew_cask_flag _ <<< "$detail"
|
||||||
if [[ "$has_sensitive_data" == "true" ]]; then
|
[[ "$is_brew_cask_flag" == "true" ]] && has_brew_cask=true
|
||||||
has_user_data=true
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ "$has_user_data" == "true" ]]; then
|
if [[ "$has_brew_cask" == "true" ]]; then
|
||||||
echo -e "${GRAY}${ICON_WARNING}${NC} ${YELLOW}Note: Some apps contain user configurations/themes${NC}"
|
echo -e "${GRAY}${ICON_WARNING}${NC} ${YELLOW}Homebrew apps will be fully cleaned (--zap: removes configs & data)${NC}"
|
||||||
echo ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -431,6 +428,7 @@ batch_uninstall_applications() {
|
|||||||
local related_files=$(decode_file_list "$encoded_files" "$app_name")
|
local related_files=$(decode_file_list "$encoded_files" "$app_name")
|
||||||
local system_files=$(decode_file_list "$encoded_system_files" "$app_name")
|
local system_files=$(decode_file_list "$encoded_system_files" "$app_name")
|
||||||
local reason=""
|
local reason=""
|
||||||
|
local suggestion=""
|
||||||
|
|
||||||
# Show progress for current app
|
# Show progress for current app
|
||||||
local brew_tag=""
|
local brew_tag=""
|
||||||
@@ -567,7 +565,7 @@ batch_uninstall_applications() {
|
|||||||
[[ "$used_brew_successfully" == "true" ]] && ((brew_apps_removed++))
|
[[ "$used_brew_successfully" == "true" ]] && ((brew_apps_removed++))
|
||||||
((files_cleaned++))
|
((files_cleaned++))
|
||||||
((total_items++))
|
((total_items++))
|
||||||
success_items+=("$app_name")
|
success_items+=("$app_path")
|
||||||
else
|
else
|
||||||
if [[ -t 1 ]]; then
|
if [[ -t 1 ]]; then
|
||||||
if [[ ${#app_details[@]} -gt 1 ]]; then
|
if [[ ${#app_details[@]} -gt 1 ]]; then
|
||||||
@@ -593,7 +591,6 @@ batch_uninstall_applications() {
|
|||||||
local -a summary_details=()
|
local -a summary_details=()
|
||||||
|
|
||||||
if [[ $success_count -gt 0 ]]; then
|
if [[ $success_count -gt 0 ]]; then
|
||||||
local success_list="${success_items[*]}"
|
|
||||||
local success_text="app"
|
local success_text="app"
|
||||||
[[ $success_count -gt 1 ]] && success_text="apps"
|
[[ $success_count -gt 1 ]] && success_text="apps"
|
||||||
local success_line="Removed ${success_count} ${success_text}"
|
local success_line="Removed ${success_count} ${success_text}"
|
||||||
@@ -602,13 +599,15 @@ batch_uninstall_applications() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Format app list with max 3 per line.
|
# Format app list with max 3 per line.
|
||||||
if [[ -n "$success_list" ]]; then
|
if [[ ${#success_items[@]} -gt 0 ]]; then
|
||||||
local idx=0
|
local idx=0
|
||||||
local is_first_line=true
|
local is_first_line=true
|
||||||
local current_line=""
|
local current_line=""
|
||||||
|
|
||||||
for app_name in "${success_items[@]}"; do
|
for success_path in "${success_items[@]}"; do
|
||||||
local display_item="${GREEN}${app_name}${NC}"
|
local display_name
|
||||||
|
display_name=$(basename "$success_path" .app)
|
||||||
|
local display_item="${GREEN}${display_name}${NC}"
|
||||||
|
|
||||||
if ((idx % 3 == 0)); then
|
if ((idx % 3 == 0)); then
|
||||||
if [[ -n "$current_line" ]]; then
|
if [[ -n "$current_line" ]]; then
|
||||||
@@ -709,20 +708,8 @@ batch_uninstall_applications() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Clean up Dock entries for uninstalled apps.
|
# Clean up Dock entries for uninstalled apps.
|
||||||
if [[ $success_count -gt 0 ]]; then
|
if [[ $success_count -gt 0 && ${#success_items[@]} -gt 0 ]]; then
|
||||||
local -a removed_paths=()
|
remove_apps_from_dock "${success_items[@]}" 2> /dev/null || true
|
||||||
for detail in "${app_details[@]}"; do
|
|
||||||
IFS='|' read -r app_name app_path _ _ _ _ <<< "$detail"
|
|
||||||
for success_name in "${success_items[@]}"; do
|
|
||||||
if [[ "$success_name" == "$app_name" ]]; then
|
|
||||||
removed_paths+=("$app_path")
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
done
|
|
||||||
if [[ ${#removed_paths[@]} -gt 0 ]]; then
|
|
||||||
remove_apps_from_dock "${removed_paths[@]}" 2> /dev/null || true
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_cleanup_sudo_keepalive
|
_cleanup_sudo_keepalive
|
||||||
@@ -733,18 +720,8 @@ batch_uninstall_applications() {
|
|||||||
if [[ $success_count -gt 0 ]]; then
|
if [[ $success_count -gt 0 ]]; then
|
||||||
local cache_file="$HOME/.cache/mole/app_scan_cache"
|
local cache_file="$HOME/.cache/mole/app_scan_cache"
|
||||||
if [[ -f "$cache_file" ]]; then
|
if [[ -f "$cache_file" ]]; then
|
||||||
local -a removed_paths=()
|
if [[ ${#success_items[@]} -gt 0 ]]; then
|
||||||
for detail in "${app_details[@]}"; do
|
local -a removed_paths=("${success_items[@]}")
|
||||||
IFS='|' read -r app_name app_path _ _ _ _ <<< "$detail"
|
|
||||||
for success_name in "${success_items[@]}"; do
|
|
||||||
if [[ "$success_name" == "$app_name" ]]; then
|
|
||||||
removed_paths+=("$app_path")
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
done
|
|
||||||
|
|
||||||
if [[ ${#removed_paths[@]} -gt 0 ]]; then
|
|
||||||
local temp_cache
|
local temp_cache
|
||||||
temp_cache=$(create_temp_file)
|
temp_cache=$(create_temp_file)
|
||||||
local line_removed=false
|
local line_removed=false
|
||||||
|
|||||||
Reference in New Issue
Block a user