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

Fix the issue of obtaining the path when uninstalling the software

This commit is contained in:
Tw93
2025-12-21 22:00:02 +08:00
parent 73cf2dff96
commit 6d087b3b12

View File

@@ -19,10 +19,8 @@ source "$SCRIPT_DIR/../lib/ui/menu_paginated.sh"
source "$SCRIPT_DIR/../lib/ui/app_selector.sh" source "$SCRIPT_DIR/../lib/ui/app_selector.sh"
source "$SCRIPT_DIR/../lib/uninstall/batch.sh" source "$SCRIPT_DIR/../lib/uninstall/batch.sh"
# Note: Bundle preservation logic is now in lib/core/common.sh
# Initialize global variables # Initialize global variables
selected_apps=() # Global array for app selection selected_apps=()
declare -a apps_data=() declare -a apps_data=()
declare -a selection_state=() declare -a selection_state=()
total_items=0 total_items=0
@@ -72,7 +70,7 @@ scan_applications() {
# Simplified cache: only check timestamp (24h TTL) # Simplified cache: only check timestamp (24h TTL)
local cache_dir="$HOME/.cache/mole" local cache_dir="$HOME/.cache/mole"
local cache_file="$cache_dir/app_scan_cache" local cache_file="$cache_dir/app_scan_cache"
local cache_ttl=86400 # 24 hours local cache_ttl=86400
local force_rescan="${1:-false}" local force_rescan="${1:-false}"
mkdir -p "$cache_dir" 2> /dev/null mkdir -p "$cache_dir" 2> /dev/null
@@ -80,13 +78,10 @@ scan_applications() {
# Check if cache exists and is fresh # Check if cache exists and is fresh
if [[ $force_rescan == false && -f "$cache_file" ]]; then if [[ $force_rescan == false && -f "$cache_file" ]]; then
local cache_age=$(($(date +%s) - $(get_file_mtime "$cache_file"))) local cache_age=$(($(date +%s) - $(get_file_mtime "$cache_file")))
[[ $cache_age -eq $(date +%s) ]] && cache_age=86401 # Handle missing file [[ $cache_age -eq $(date +%s) ]] && cache_age=86401
if [[ $cache_age -lt $cache_ttl ]]; then if [[ $cache_age -lt $cache_ttl ]]; then
# Cache hit - return immediately
# Show brief flash of cache usage if in interactive mode
if [[ -t 2 ]]; then if [[ -t 2 ]]; then
echo -e "${GREEN}Loading from cache...${NC}" >&2 echo -e "${GREEN}Loading from cache...${NC}" >&2
# Small sleep to let user see it (optional, but good for "feeling" the speed vs glitch)
sleep 0.3 sleep 0.3
fi fi
echo "$cache_file" echo "$cache_file"
@@ -94,62 +89,58 @@ scan_applications() {
fi fi
fi fi
# Cache miss - prepare for scanning
local inline_loading=false local inline_loading=false
if [[ -t 1 && -t 2 ]]; then if [[ -t 1 && -t 2 ]]; then
inline_loading=true inline_loading=true
# Clear screen for inline loading
printf "\033[2J\033[H" >&2 printf "\033[2J\033[H" >&2
fi fi
local temp_file local temp_file
temp_file=$(create_temp_file) temp_file=$(create_temp_file)
# Pre-cache current epoch to avoid repeated calls
local current_epoch local current_epoch
current_epoch=$(date "+%s") current_epoch=$(date "+%s")
# First pass: quickly collect all valid app paths and bundle IDs (NO mdls calls) # First pass: quickly collect all valid app paths and bundle IDs
local -a app_data_tuples=() local -a app_data_tuples=()
while IFS= read -r -d '' app_path; do local -a app_dirs=(
if [[ ! -e "$app_path" ]]; then continue; fi "/Applications"
"$HOME/Applications"
local app_name
app_name=$(basename "$app_path" .app)
# Skip nested apps (e.g. inside Wrapper/ or Frameworks/ of another app)
# Check if parent path component ends in .app (e.g. /Foo.app/Bar.app or /Foo.app/Contents/Bar.app)
# This prevents false positives like /Old.apps/Target.app
local parent_dir
parent_dir=$(dirname "$app_path")
if [[ "$parent_dir" == *".app" || "$parent_dir" == *".app/"* ]]; then
continue
fi
# Get bundle ID only (fast, no mdls calls in first pass)
local bundle_id="unknown"
if [[ -f "$app_path/Contents/Info.plist" ]]; then
bundle_id=$(defaults read "$app_path/Contents/Info.plist" CFBundleIdentifier 2> /dev/null || echo "unknown")
fi
# Skip system critical apps (input methods, system components)
if should_protect_from_uninstall "$bundle_id"; then
continue
fi
# Store tuple: app_path|app_name|bundle_id (display_name will be resolved in parallel later)
app_data_tuples+=("${app_path}|${app_name}|${bundle_id}")
done < <(
# Scan both system and user application directories
# Using maxdepth 3 to find apps in subdirectories (e.g., Adobe apps in /Applications/Adobe X/)
command find /Applications -name "*.app" -maxdepth 3 -print0 2> /dev/null
command find ~/Applications -name "*.app" -maxdepth 3 -print0 2> /dev/null
) )
for app_dir in "${app_dirs[@]}"; do
if [[ ! -d "$app_dir" ]]; then continue; fi
while IFS= read -r -d '' app_path; do
if [[ ! -e "$app_path" ]]; then continue; fi
local app_name
app_name=$(basename "$app_path" .app)
# Skip nested apps (e.g. inside Wrapper/ or Frameworks/ of another app)
local parent_dir
parent_dir=$(dirname "$app_path")
if [[ "$parent_dir" == *".app" || "$parent_dir" == *".app/"* ]]; then
continue
fi
local bundle_id="unknown"
if [[ -f "$app_path/Contents/Info.plist" ]]; then
bundle_id=$(defaults read "$app_path/Contents/Info.plist" CFBundleIdentifier 2> /dev/null || echo "unknown")
fi
# Skip system critical apps
if should_protect_from_uninstall "$bundle_id"; then
continue
fi
app_data_tuples+=("${app_path}|${app_name}|${bundle_id}")
done < <(command find "$app_dir" -name "*.app" -maxdepth 3 -print0 2> /dev/null)
done
# Second pass: process each app with parallel size calculation # Second pass: process each app with parallel size calculation
local app_count=0 local app_count=0
local total_apps=${#app_data_tuples[@]} local total_apps=${#app_data_tuples[@]}
# Bound parallelism - for metadata queries, can go higher since it's mostly waiting
local max_parallel local max_parallel
max_parallel=$(get_optimal_parallel_jobs "io") max_parallel=$(get_optimal_parallel_jobs "io")
if [[ $max_parallel -lt 8 ]]; then if [[ $max_parallel -lt 8 ]]; then
@@ -158,9 +149,7 @@ scan_applications() {
max_parallel=32 max_parallel=32
fi fi
local pids=() local pids=()
# inline_loading variable already set above (line ~92)
# Process app metadata extraction function
process_app_metadata() { process_app_metadata() {
local app_data_tuple="$1" local app_data_tuple="$1"
local output_file="$2" local output_file="$2"
@@ -168,25 +157,18 @@ scan_applications() {
IFS='|' read -r app_path app_name bundle_id <<< "$app_data_tuple" IFS='|' read -r app_path app_name bundle_id <<< "$app_data_tuple"
# Get localized display name (moved from first pass for better performance) # Get localized display name
local display_name="$app_name" local display_name="$app_name"
if [[ -f "$app_path/Contents/Info.plist" ]]; then if [[ -f "$app_path/Contents/Info.plist" ]]; then
# Try to get localized name from system metadata (best for i18n)
local md_display_name local md_display_name
md_display_name=$(run_with_timeout 0.05 mdls -name kMDItemDisplayName -raw "$app_path" 2> /dev/null || echo "") md_display_name=$(run_with_timeout 0.05 mdls -name kMDItemDisplayName -raw "$app_path" 2> /dev/null || echo "")
# Get bundle names
local bundle_display_name local bundle_display_name
bundle_display_name=$(plutil -extract CFBundleDisplayName raw "$app_path/Contents/Info.plist" 2> /dev/null) bundle_display_name=$(plutil -extract CFBundleDisplayName raw "$app_path/Contents/Info.plist" 2> /dev/null)
local bundle_name local bundle_name
bundle_name=$(plutil -extract CFBundleName raw "$app_path/Contents/Info.plist" 2> /dev/null) bundle_name=$(plutil -extract CFBundleName raw "$app_path/Contents/Info.plist" 2> /dev/null)
# Priority order for name selection (prefer localized names): # Priority order: MDItemDisplayName > CFBundleDisplayName > CFBundleName
# 1. System metadata display name (kMDItemDisplayName) - respects system language
# 2. CFBundleDisplayName - usually localized
# 3. CFBundleName - fallback
# 4. App folder name - last resort
if [[ -n "$md_display_name" && "$md_display_name" != "(null)" && "$md_display_name" != "$app_name" ]]; then if [[ -n "$md_display_name" && "$md_display_name" != "(null)" && "$md_display_name" != "$app_name" ]]; then
display_name="$md_display_name" display_name="$md_display_name"
elif [[ -n "$bundle_display_name" && "$bundle_display_name" != "(null)" ]]; then elif [[ -n "$bundle_display_name" && "$bundle_display_name" != "(null)" ]]; then
@@ -200,7 +182,6 @@ scan_applications() {
local app_size="N/A" local app_size="N/A"
local app_size_kb="0" local app_size_kb="0"
if [[ -d "$app_path" ]]; then if [[ -d "$app_path" ]]; then
# Get size in KB, then format for display
app_size_kb=$(get_path_size_kb "$app_path") app_size_kb=$(get_path_size_kb "$app_path")
app_size=$(bytes_to_human "$((app_size_kb * 1024))") app_size=$(bytes_to_human "$((app_size_kb * 1024))")
fi fi
@@ -210,7 +191,6 @@ scan_applications() {
local last_used_epoch=0 local last_used_epoch=0
if [[ -d "$app_path" ]]; then if [[ -d "$app_path" ]]; then
# Try mdls first with short timeout (0.05s) for accuracy, fallback to mtime for speed
local metadata_date local metadata_date
metadata_date=$(run_with_timeout 0.05 mdls -name kMDItemLastUsedDate -raw "$app_path" 2> /dev/null || echo "") metadata_date=$(run_with_timeout 0.05 mdls -name kMDItemLastUsedDate -raw "$app_path" 2> /dev/null || echo "")
@@ -218,7 +198,6 @@ scan_applications() {
last_used_epoch=$(date -j -f "%Y-%m-%d %H:%M:%S %z" "$metadata_date" "+%s" 2> /dev/null || echo "0") last_used_epoch=$(date -j -f "%Y-%m-%d %H:%M:%S %z" "$metadata_date" "+%s" 2> /dev/null || echo "0")
fi fi
# Fallback if mdls failed or returned nothing
if [[ "$last_used_epoch" -eq 0 ]]; then if [[ "$last_used_epoch" -eq 0 ]]; then
last_used_epoch=$(get_file_mtime "$app_path") last_used_epoch=$(get_file_mtime "$app_path")
fi fi
@@ -245,18 +224,14 @@ scan_applications() {
fi fi
fi fi
# Write to output file atomically
# Fields: epoch|app_path|display_name|bundle_id|size_human|last_used|size_kb
echo "${last_used_epoch}|${app_path}|${display_name}|${bundle_id}|${app_size}|${last_used}|${app_size_kb}" >> "$output_file" echo "${last_used_epoch}|${app_path}|${display_name}|${bundle_id}|${app_size}|${last_used}|${app_size_kb}" >> "$output_file"
} }
export -f process_app_metadata export -f process_app_metadata
# Create a temporary file to track progress
local progress_file="${temp_file}.progress" local progress_file="${temp_file}.progress"
echo "0" > "$progress_file" echo "0" > "$progress_file"
# Start a background spinner that reads progress from file
local spinner_pid="" local spinner_pid=""
( (
trap 'exit 0' TERM INT EXIT trap 'exit 0' TERM INT EXIT
@@ -279,27 +254,20 @@ scan_applications() {
# Process apps in parallel batches # Process apps in parallel batches
for app_data_tuple in "${app_data_tuples[@]}"; do for app_data_tuple in "${app_data_tuples[@]}"; do
((app_count++)) ((app_count++))
# Launch background process
process_app_metadata "$app_data_tuple" "$temp_file" "$current_epoch" & process_app_metadata "$app_data_tuple" "$temp_file" "$current_epoch" &
pids+=($!) pids+=($!)
# Update progress to show scanning progress (use app_count as it increments smoothly)
echo "$app_count" > "$progress_file" echo "$app_count" > "$progress_file"
# Wait if we've hit max parallel limit
if ((${#pids[@]} >= max_parallel)); then if ((${#pids[@]} >= max_parallel)); then
wait "${pids[0]}" 2> /dev/null wait "${pids[0]}" 2> /dev/null
pids=("${pids[@]:1}") # Remove first pid pids=("${pids[@]:1}")
fi fi
done done
# Wait for remaining background processes
for pid in "${pids[@]}"; do for pid in "${pids[@]}"; do
wait "$pid" 2> /dev/null wait "$pid" 2> /dev/null
done done
# Stop the spinner and clear the line
if [[ -n "$spinner_pid" ]]; then if [[ -n "$spinner_pid" ]]; then
kill -TERM "$spinner_pid" 2> /dev/null || true kill -TERM "$spinner_pid" 2> /dev/null || true
wait "$spinner_pid" 2> /dev/null || true wait "$spinner_pid" 2> /dev/null || true
@@ -311,15 +279,12 @@ scan_applications() {
fi fi
rm -f "$progress_file" rm -f "$progress_file"
# Check if we found any applications
if [[ ! -s "$temp_file" ]]; then if [[ ! -s "$temp_file" ]]; then
echo "No applications found to uninstall" >&2 echo "No applications found to uninstall" >&2
rm -f "$temp_file" rm -f "$temp_file"
return 1 return 1
fi fi
# Sort by last used (oldest first) and cache the result
# Show brief processing message for large app lists
if [[ $total_apps -gt 50 ]]; then if [[ $total_apps -gt 50 ]]; then
if [[ $inline_loading == true ]]; then if [[ $inline_loading == true ]]; then
printf "\033[H\033[2KProcessing %d applications...\n" "$total_apps" >&2 printf "\033[H\033[2KProcessing %d applications...\n" "$total_apps" >&2
@@ -334,7 +299,6 @@ scan_applications() {
} }
rm -f "$temp_file" rm -f "$temp_file"
# Clear processing message
if [[ $total_apps -gt 50 ]]; then if [[ $total_apps -gt 50 ]]; then
if [[ $inline_loading == true ]]; then if [[ $inline_loading == true ]]; then
printf "\033[H\033[2K" >&2 printf "\033[H\033[2K" >&2
@@ -343,10 +307,8 @@ scan_applications() {
fi fi
fi fi
# Save to cache (simplified - no metadata)
cp "${temp_file}.sorted" "$cache_file" 2> /dev/null || true cp "${temp_file}.sorted" "$cache_file" 2> /dev/null || true
# Return sorted file
if [[ -f "${temp_file}.sorted" ]]; then if [[ -f "${temp_file}.sorted" ]]; then
echo "${temp_file}.sorted" echo "${temp_file}.sorted"
else else
@@ -362,13 +324,10 @@ load_applications() {
return 1 return 1
fi fi
# Clear arrays
apps_data=() apps_data=()
selection_state=() selection_state=()
# Read apps into array, skip non-existent apps
while IFS='|' read -r epoch app_path app_name bundle_id size last_used size_kb; do while IFS='|' read -r epoch app_path app_name bundle_id size last_used size_kb; do
# Skip if app path no longer exists
[[ ! -e "$app_path" ]] && continue [[ ! -e "$app_path" ]] && continue
apps_data+=("$epoch|$app_path|$app_name|$bundle_id|$size|$last_used|${size_kb:-0}") apps_data+=("$epoch|$app_path|$app_name|$bundle_id|$size|$last_used|${size_kb:-0}")
@@ -385,7 +344,6 @@ load_applications() {
# Cleanup function - restore cursor and clean up # Cleanup function - restore cursor and clean up
cleanup() { cleanup() {
# Restore cursor using common function
if [[ "${MOLE_ALT_SCREEN_ACTIVE:-}" == "1" ]]; then if [[ "${MOLE_ALT_SCREEN_ACTIVE:-}" == "1" ]]; then
leave_alt_screen leave_alt_screen
unset MOLE_ALT_SCREEN_ACTIVE unset MOLE_ALT_SCREEN_ACTIVE
@@ -399,7 +357,6 @@ cleanup() {
exit "${1:-0}" exit "${1:-0}"
} }
# Set trap for cleanup on exit
trap cleanup EXIT INT TERM trap cleanup EXIT INT TERM
main() { main() {
@@ -420,24 +377,19 @@ main() {
use_inline_loading=true use_inline_loading=true
fi fi
# Hide cursor during operation
hide_cursor hide_cursor
# Main interaction loop # Main interaction loop
while true; do while true; do
# Simplified: always check if we need alt screen for scanning
# (scan_applications handles cache internally)
local needs_scanning=true local needs_scanning=true
local cache_file="$HOME/.cache/mole/app_scan_cache" local cache_file="$HOME/.cache/mole/app_scan_cache"
if [[ $force_rescan == false && -f "$cache_file" ]]; then if [[ $force_rescan == false && -f "$cache_file" ]]; then
local cache_age=$(($(date +%s) - $(get_file_mtime "$cache_file"))) local cache_age=$(($(date +%s) - $(get_file_mtime "$cache_file")))
[[ $cache_age -eq $(date +%s) ]] && cache_age=86401 # Handle missing file [[ $cache_age -eq $(date +%s) ]] && cache_age=86401
[[ $cache_age -lt 86400 ]] && needs_scanning=false [[ $cache_age -lt 86400 ]] && needs_scanning=false
fi fi
# Only enter alt screen if we need scanning (shows progress)
if [[ $needs_scanning == true && $use_inline_loading == true ]]; then if [[ $needs_scanning == true && $use_inline_loading == true ]]; then
# Only enter if not already active
if [[ "${MOLE_ALT_SCREEN_ACTIVE:-}" != "1" ]]; then if [[ "${MOLE_ALT_SCREEN_ACTIVE:-}" != "1" ]]; then
enter_alt_screen enter_alt_screen
export MOLE_ALT_SCREEN_ACTIVE=1 export MOLE_ALT_SCREEN_ACTIVE=1
@@ -446,10 +398,6 @@ main() {
fi fi
printf "\033[2J\033[H" >&2 printf "\033[2J\033[H" >&2
else else
# If we don't need scanning but have alt screen from previous iteration, keep it?
# Actually, scan_applications might output to stderr.
# Let's just unset the flags if we don't need scanning, but keep alt screen if it was active?
# No, select_apps_for_uninstall will handle its own screen management.
unset MOLE_INLINE_LOADING MOLE_MANAGED_ALT_SCREEN MOLE_ALT_SCREEN_ACTIVE unset MOLE_INLINE_LOADING MOLE_MANAGED_ALT_SCREEN MOLE_ALT_SCREEN_ACTIVE
if [[ "${MOLE_ALT_SCREEN_ACTIVE:-}" == "1" ]]; then if [[ "${MOLE_ALT_SCREEN_ACTIVE:-}" == "1" ]]; then
leave_alt_screen leave_alt_screen
@@ -457,7 +405,6 @@ main() {
fi fi
fi fi
# Scan applications
local apps_file="" local apps_file=""
if ! apps_file=$(scan_applications "$force_rescan"); then if ! apps_file=$(scan_applications "$force_rescan"); then
if [[ "${MOLE_ALT_SCREEN_ACTIVE:-}" == "1" ]]; then if [[ "${MOLE_ALT_SCREEN_ACTIVE:-}" == "1" ]]; then
@@ -474,7 +421,6 @@ main() {
fi fi
if [[ ! -f "$apps_file" ]]; then if [[ ! -f "$apps_file" ]]; then
# Error message already shown by scan_applications
if [[ "${MOLE_ALT_SCREEN_ACTIVE:-}" == "1" ]]; then if [[ "${MOLE_ALT_SCREEN_ACTIVE:-}" == "1" ]]; then
leave_alt_screen leave_alt_screen
unset MOLE_ALT_SCREEN_ACTIVE unset MOLE_ALT_SCREEN_ACTIVE
@@ -483,7 +429,6 @@ main() {
return 1 return 1
fi fi
# Load applications
if ! load_applications "$apps_file"; then if ! load_applications "$apps_file"; then
if [[ "${MOLE_ALT_SCREEN_ACTIVE:-}" == "1" ]]; then if [[ "${MOLE_ALT_SCREEN_ACTIVE:-}" == "1" ]]; then
leave_alt_screen leave_alt_screen
@@ -494,7 +439,6 @@ main() {
return 1 return 1
fi fi
# Interactive selection using paginated menu
set +e set +e
select_apps_for_uninstall select_apps_for_uninstall
local exit_code=$? local exit_code=$?
@@ -508,45 +452,37 @@ main() {
fi fi
show_cursor show_cursor
clear_screen clear_screen
printf '\033[2J\033[H' >&2 # Also clear stderr printf '\033[2J\033[H' >&2
rm -f "$apps_file" rm -f "$apps_file"
# Handle Refresh (code 10)
if [[ $exit_code -eq 10 ]]; then if [[ $exit_code -eq 10 ]]; then
force_rescan=true force_rescan=true
continue continue
fi fi
# User cancelled selection, exit the loop
return 0 return 0
fi fi
# Always clear on exit from selection, regardless of alt screen state
if [[ "${MOLE_ALT_SCREEN_ACTIVE:-}" == "1" ]]; then if [[ "${MOLE_ALT_SCREEN_ACTIVE:-}" == "1" ]]; then
leave_alt_screen leave_alt_screen
unset MOLE_ALT_SCREEN_ACTIVE unset MOLE_ALT_SCREEN_ACTIVE
unset MOLE_INLINE_LOADING MOLE_MANAGED_ALT_SCREEN unset MOLE_INLINE_LOADING MOLE_MANAGED_ALT_SCREEN
fi fi
# Restore cursor and clear screen (output to both stdout and stderr for reliability)
show_cursor show_cursor
clear_screen clear_screen
printf '\033[2J\033[H' >&2 # Also clear stderr in case of mixed output printf '\033[2J\033[H' >&2
local selection_count=${#selected_apps[@]} local selection_count=${#selected_apps[@]}
if [[ $selection_count -eq 0 ]]; then if [[ $selection_count -eq 0 ]]; then
echo "No apps selected" echo "No apps selected"
rm -f "$apps_file" rm -f "$apps_file"
# Loop back or exit? If select_apps_for_uninstall returns 0 but empty selection,
# it technically shouldn't happen based on that function's logic.
continue continue
fi fi
# Show selected apps with clean alignment
echo -e "${BLUE}${ICON_CONFIRM}${NC} Selected ${selection_count} app(s):" echo -e "${BLUE}${ICON_CONFIRM}${NC} Selected ${selection_count} app(s):"
local -a summary_rows=() local -a summary_rows=()
local max_name_display_width=0 local max_name_display_width=0
local max_size_width=0 local max_size_width=0
local max_last_width=0 local max_last_width=0
# First pass: get actual max widths for all columns
for selected_app in "${selected_apps[@]}"; do for selected_app in "${selected_apps[@]}"; do
IFS='|' read -r _ _ app_name _ size last_used _ <<< "$selected_app" IFS='|' read -r _ _ app_name _ size last_used _ <<< "$selected_app"
local name_width=$(get_display_width "$app_name") local name_width=$(get_display_width "$app_name")
@@ -560,12 +496,9 @@ main() {
((max_size_width < 5)) && max_size_width=5 ((max_size_width < 5)) && max_size_width=5
((max_last_width < 5)) && max_last_width=5 ((max_last_width < 5)) && max_last_width=5
# Calculate name width: use actual max, but constrain by terminal width
# Fixed elements: "99. " (4) + " " (2) + " | Last: " (11) = 17
local term_width=$(tput cols 2> /dev/null || echo 100) local term_width=$(tput cols 2> /dev/null || echo 100)
local available_for_name=$((term_width - 17 - max_size_width - max_last_width)) local available_for_name=$((term_width - 17 - max_size_width - max_last_width))
# Dynamic minimum for better spacing on wide terminals
local min_name_width=24 local min_name_width=24
if [[ $term_width -ge 120 ]]; then if [[ $term_width -ge 120 ]]; then
min_name_width=50 min_name_width=50
@@ -575,23 +508,19 @@ main() {
min_name_width=30 min_name_width=30
fi fi
# Constrain name width: dynamic min, max min(actual_max, available, 60)
local name_trunc_limit=$max_name_display_width local name_trunc_limit=$max_name_display_width
[[ $name_trunc_limit -lt $min_name_width ]] && name_trunc_limit=$min_name_width [[ $name_trunc_limit -lt $min_name_width ]] && name_trunc_limit=$min_name_width
[[ $name_trunc_limit -gt $available_for_name ]] && name_trunc_limit=$available_for_name [[ $name_trunc_limit -gt $available_for_name ]] && name_trunc_limit=$available_for_name
[[ $name_trunc_limit -gt 60 ]] && name_trunc_limit=60 [[ $name_trunc_limit -gt 60 ]] && name_trunc_limit=60
# Reset for second pass
max_name_display_width=0 max_name_display_width=0
for selected_app in "${selected_apps[@]}"; do for selected_app in "${selected_apps[@]}"; do
IFS='|' read -r epoch app_path app_name bundle_id size last_used size_kb <<< "$selected_app" IFS='|' read -r epoch app_path app_name bundle_id size last_used size_kb <<< "$selected_app"
# Truncate by display width if needed
local display_name local display_name
display_name=$(truncate_by_display_width "$app_name" "$name_trunc_limit") display_name=$(truncate_by_display_width "$app_name" "$name_trunc_limit")
# Track actual max width after truncation
local current_width local current_width
current_width=$(get_display_width "$display_name") current_width=$(get_display_width "$display_name")
[[ $current_width -gt $max_name_display_width ]] && max_name_display_width=$current_width [[ $current_width -gt $max_name_display_width ]] && max_name_display_width=$current_width
@@ -612,7 +541,6 @@ main() {
local index=1 local index=1
for row in "${summary_rows[@]}"; do for row in "${summary_rows[@]}"; do
IFS='|' read -r name_cell size_cell last_cell <<< "$row" IFS='|' read -r name_cell size_cell last_cell <<< "$row"
# Calculate printf width based on actual display width
local name_display_width local name_display_width
name_display_width=$(get_display_width "$name_cell") name_display_width=$(get_display_width "$name_cell")
local name_char_count=${#name_cell} local name_char_count=${#name_cell}
@@ -623,30 +551,24 @@ main() {
((index++)) ((index++))
done done
# Execute batch uninstallation (handles confirmation)
batch_uninstall_applications batch_uninstall_applications
# Cleanup current apps file
rm -f "$apps_file" rm -f "$apps_file"
# Pause before looping back
echo -e "${GRAY}Press Enter to return to application list, any other key to exit...${NC}" echo -e "${GRAY}Press Enter to return to application list, any other key to exit...${NC}"
local key local key
IFS= read -r -s -n1 key || key="" IFS= read -r -s -n1 key || key=""
drain_pending_input drain_pending_input
# Logic: Enter = continue loop, any other key = exit
if [[ -z "$key" ]]; then if [[ -z "$key" ]]; then
: # Enter pressed, continue loop :
else else
show_cursor show_cursor
return 0 return 0
fi fi
# Reset force_rescan to false for subsequent loops
force_rescan=false force_rescan=false
done done
} }
# Run main function
main "$@" main "$@"