diff --git a/bin/optimize.sh b/bin/optimize.sh index b38f06e..07e7d81 100755 --- a/bin/optimize.sh +++ b/bin/optimize.sh @@ -83,21 +83,54 @@ show_optimization_summary() { summary_details+=("Run without ${YELLOW}--dry-run${NC} to apply these changes") else summary_title="Optimization and Check Complete" - summary_details+=("Applied ${GREEN}${total_applied:-0}${NC} optimizations; all system services tuned") - summary_details+=("Updates, security and system health fully reviewed") - local summary_line4="" + # Build statistics summary + local -a stats=() + local cache_kb="${OPTIMIZE_CACHE_CLEANED_KB:-0}" + local db_count="${OPTIMIZE_DATABASES_COUNT:-0}" + local config_count="${OPTIMIZE_CONFIGS_REPAIRED:-0}" + + if [[ "$cache_kb" =~ ^[0-9]+$ ]] && [[ "$cache_kb" -gt 0 ]]; then + local cache_human=$(bytes_to_human "$((cache_kb * 1024))") + stats+=("${cache_human} cache cleaned") + fi + + if [[ "$db_count" =~ ^[0-9]+$ ]] && [[ "$db_count" -gt 0 ]]; then + stats+=("${db_count} databases optimized") + fi + + if [[ "$config_count" =~ ^[0-9]+$ ]] && [[ "$config_count" -gt 0 ]]; then + stats+=("${config_count} configs repaired") + fi + + # Build first summary line with most important stat only + local key_stat="" + if [[ "$cache_kb" =~ ^[0-9]+$ ]] && [[ "$cache_kb" -gt 0 ]]; then + local cache_human=$(bytes_to_human "$((cache_kb * 1024))") + key_stat="${cache_human} cache cleaned" + elif [[ "$db_count" =~ ^[0-9]+$ ]] && [[ "$db_count" -gt 0 ]]; then + key_stat="${db_count} databases optimized" + elif [[ "$config_count" =~ ^[0-9]+$ ]] && [[ "$config_count" -gt 0 ]]; then + key_stat="${config_count} configs repaired" + fi + + if [[ -n "$key_stat" ]]; then + summary_details+=("Applied ${GREEN}${total_applied:-0}${NC} optimizations — ${key_stat}") + else + summary_details+=("Applied ${GREEN}${total_applied:-0}${NC} optimizations — all services tuned") + fi + + local summary_line3="" if [[ -n "${AUTO_FIX_SUMMARY:-}" ]]; then - summary_line4="${AUTO_FIX_SUMMARY}" + summary_line3="${AUTO_FIX_SUMMARY}" if [[ -n "${AUTO_FIX_DETAILS:-}" ]]; then local detail_join detail_join=$(echo "${AUTO_FIX_DETAILS}" | paste -sd ", " -) - [[ -n "$detail_join" ]] && summary_line4+=" — ${detail_join}" + [[ -n "$detail_join" ]] && summary_line3+=" — ${detail_join}" fi - else - summary_line4="Your Mac is now faster and more responsive" + summary_details+=("$summary_line3") fi - summary_details+=("$summary_line4") + summary_details+=("System fully optimized — faster, more secure and responsive") fi print_summary_block "$summary_title" "${summary_details[@]}" diff --git a/lib/optimize/tasks.sh b/lib/optimize/tasks.sh index 1f3ffb4..042e0f2 100644 --- a/lib/optimize/tasks.sh +++ b/lib/optimize/tasks.sh @@ -117,6 +117,8 @@ opt_system_maintenance() { # Refresh Finder caches (QuickLook/icon services). opt_cache_refresh() { + local total_cache_size=0 + if [[ "${MO_DEBUG:-}" == "1" ]]; then debug_operation_start "Finder Cache Refresh" "Refresh QuickLook thumbnails and icon services" debug_operation_detail "Method" "Remove cache files and rebuild via qlmanage" @@ -157,11 +159,17 @@ opt_cache_refresh() { for target_path in "${cache_targets[@]}"; do if [[ -e "$target_path" ]]; then if ! should_protect_path "$target_path"; then + local size_kb + size_kb=$(get_path_size_kb "$target_path" 2> /dev/null || echo "0") + if [[ "$size_kb" =~ ^[0-9]+$ ]]; then + total_cache_size=$((total_cache_size + size_kb)) + fi safe_remove "$target_path" true > /dev/null 2>&1 fi fi done + export OPTIMIZE_CACHE_CLEANED_KB="${total_cache_size}" opt_msg "QuickLook thumbnails refreshed" opt_msg "Icon services cache rebuilt" } @@ -213,6 +221,7 @@ opt_fix_broken_configs() { stop_inline_spinner fi + export OPTIMIZE_CONFIGS_REPAIRED="${broken_prefs}" if [[ $broken_prefs -gt 0 ]]; then opt_msg "Repaired $broken_prefs corrupted preference files" else @@ -361,6 +370,7 @@ opt_sqlite_vacuum() { stop_inline_spinner fi + export OPTIMIZE_DATABASES_COUNT="${vacuumed}" if [[ $vacuumed -gt 0 ]]; then opt_msg "Optimized $vacuumed databases for Mail, Safari, Messages" elif [[ $timed_out -eq 0 && $failed -eq 0 ]]; then