mirror of
https://github.com/tw93/Mole.git
synced 2026-02-10 23:34:16 +00:00
feat: Enhance clean and optimize operations with new configuration constants
This commit is contained in:
35
bin/clean.sh
35
bin/clean.sh
@@ -261,6 +261,7 @@ safe_clean() {
|
||||
local total_paths=${#existing_paths[@]}
|
||||
if [[ -t 1 ]]; then MOLE_SPINNER_PREFIX=" " start_inline_spinner "Scanning $total_paths items..."; fi
|
||||
local temp_dir
|
||||
# create_temp_dir uses mktemp -d for secure temporary directory creation
|
||||
temp_dir=$(create_temp_dir)
|
||||
|
||||
# Parallel processing (bash 3.2 compatible)
|
||||
@@ -498,6 +499,7 @@ EOF
|
||||
|
||||
# Check for cancel (ESC or Q)
|
||||
if [[ "$choice" == "QUIT" ]]; then
|
||||
echo -e " ${GRAY}Canceled${NC}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
@@ -521,6 +523,8 @@ EOF
|
||||
else
|
||||
# Other keys (including arrow keys) = skip, no message needed
|
||||
SYSTEM_CLEAN=false
|
||||
echo -e " ${GRAY}Skipped${NC}"
|
||||
echo ""
|
||||
fi
|
||||
else
|
||||
SYSTEM_CLEAN=false
|
||||
@@ -598,6 +602,7 @@ perform_cleanup() {
|
||||
start_section "User essentials"
|
||||
# User essentials cleanup (delegated to clean_user_data module)
|
||||
clean_user_essentials
|
||||
scan_external_volumes
|
||||
end_section
|
||||
|
||||
start_section "Finder metadata"
|
||||
@@ -683,9 +688,9 @@ perform_cleanup() {
|
||||
check_ios_device_backups
|
||||
end_section
|
||||
|
||||
# ===== 15. Time Machine failed backups =====
|
||||
start_section "Time Machine failed backups"
|
||||
# Time Machine failed backups cleanup (delegated to clean_system module)
|
||||
# ===== 15. Time Machine incomplete backups =====
|
||||
start_section "Time Machine incomplete backups"
|
||||
# Time Machine incomplete backups cleanup (delegated to clean_system module)
|
||||
clean_time_machine_failed_backups
|
||||
end_section
|
||||
|
||||
@@ -729,23 +734,22 @@ perform_cleanup() {
|
||||
summary_details+=("Detailed file list: ${GRAY}$EXPORT_LIST_FILE${NC}")
|
||||
summary_details+=("Use ${GRAY}mo clean --whitelist${NC} to add protection rules")
|
||||
else
|
||||
summary_details+=("Space freed: ${GREEN}${freed_gb}GB${NC}")
|
||||
summary_details+=("Free space now: $(get_free_space)")
|
||||
# Build summary line: Space freed + Items cleaned
|
||||
local summary_line="Space freed: ${GREEN}${freed_gb}GB${NC}"
|
||||
|
||||
if [[ $files_cleaned -gt 0 && $total_items -gt 0 ]]; then
|
||||
local stats="Items cleaned: $files_cleaned | Categories: $total_items"
|
||||
[[ $whitelist_skipped_count -gt 0 ]] && stats+=" | Protected: $whitelist_skipped_count"
|
||||
summary_details+=("$stats")
|
||||
summary_line+=" | Items cleaned: $files_cleaned | Categories: $total_items"
|
||||
[[ $whitelist_skipped_count -gt 0 ]] && summary_line+=" | Protected: $whitelist_skipped_count"
|
||||
elif [[ $files_cleaned -gt 0 ]]; then
|
||||
local stats="Items cleaned: $files_cleaned"
|
||||
[[ $whitelist_skipped_count -gt 0 ]] && stats+=" | Protected: $whitelist_skipped_count"
|
||||
summary_details+=("$stats")
|
||||
summary_line+=" | Items cleaned: $files_cleaned"
|
||||
[[ $whitelist_skipped_count -gt 0 ]] && summary_line+=" | Protected: $whitelist_skipped_count"
|
||||
elif [[ $total_items -gt 0 ]]; then
|
||||
local stats="Categories: $total_items"
|
||||
[[ $whitelist_skipped_count -gt 0 ]] && stats+=" | Protected: $whitelist_skipped_count"
|
||||
summary_details+=("$stats")
|
||||
summary_line+=" | Categories: $total_items"
|
||||
[[ $whitelist_skipped_count -gt 0 ]] && summary_line+=" | Protected: $whitelist_skipped_count"
|
||||
fi
|
||||
|
||||
summary_details+=("$summary_line")
|
||||
|
||||
if [[ $(echo "$freed_gb" | awk '{print ($1 >= 1) ? 1 : 0}') -eq 1 ]]; then
|
||||
local movies
|
||||
movies=$(echo "$freed_gb" | awk '{printf "%.0f", $1/4.5}')
|
||||
@@ -753,6 +757,9 @@ perform_cleanup() {
|
||||
summary_details+=("Equivalent to ~$movies 4K movies of storage.")
|
||||
fi
|
||||
fi
|
||||
|
||||
# Free space now at the end
|
||||
summary_details+=("Free space now: $(get_free_space)")
|
||||
fi
|
||||
else
|
||||
summary_status="info"
|
||||
|
||||
@@ -82,9 +82,8 @@ show_optimization_summary() {
|
||||
local -a summary_details=()
|
||||
|
||||
# Optimization results
|
||||
summary_details+=("Optimizations: ${GREEN}${safe_count}${NC} applied, ${YELLOW}${confirm_count}${NC} manual checks")
|
||||
summary_details+=("Caches refreshed; services restarted; system tuned")
|
||||
summary_details+=("Updates & security reviewed across system")
|
||||
summary_details+=("Applied ${GREEN}${safe_count:-0}${NC} optimizations; all system services tuned")
|
||||
summary_details+=("Updates, security and system health fully reviewed")
|
||||
|
||||
local summary_line4=""
|
||||
if [[ -n "${AUTO_FIX_SUMMARY:-}" ]]; then
|
||||
@@ -95,15 +94,11 @@ show_optimization_summary() {
|
||||
[[ -n "$detail_join" ]] && summary_line4+=" — ${detail_join}"
|
||||
fi
|
||||
else
|
||||
summary_line4="Mac should feel faster and more responsive"
|
||||
summary_line4="Your Mac is now faster and more responsive"
|
||||
fi
|
||||
summary_details+=("$summary_line4")
|
||||
|
||||
if [[ -n "${AUTO_FIX_SUMMARY:-}" ]]; then
|
||||
summary_details+=("$AUTO_FIX_SUMMARY")
|
||||
fi
|
||||
|
||||
# Fix: Ensure summary is always printed for optimizations
|
||||
# Ensure summary is always printed for optimizations
|
||||
print_summary_block "$summary_title" "${summary_details[@]}"
|
||||
}
|
||||
|
||||
@@ -168,10 +163,22 @@ touchid_configured() {
|
||||
}
|
||||
|
||||
touchid_supported() {
|
||||
# bioutil is the most reliable way to check for Touch ID hardware/software support
|
||||
if command -v bioutil > /dev/null 2>&1; then
|
||||
bioutil -r 2> /dev/null | grep -q "Touch ID" && return 0
|
||||
# Check if Touch ID is functional and available for any user
|
||||
if bioutil -r 2> /dev/null | grep -qi "Touch ID"; then
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
[[ "$(uname -m)" == "arm64" ]]
|
||||
|
||||
# Fallback: check for Apple Silicon which almost always has Touch ID support
|
||||
# (except for Mac mini/Studio without a Magic Keyboard with Touch ID)
|
||||
if [[ "$(uname -m)" == "arm64" ]]; then
|
||||
# On Apple Silicon, we can check for the presence of the Touch Bar or Touch ID sensor
|
||||
# but bioutil is generally sufficient. If bioutil failed, we treat arm64 as likely supported.
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
cleanup_path() {
|
||||
|
||||
Reference in New Issue
Block a user