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

chore: auto format code

This commit is contained in:
Tw93
2025-12-12 06:12:13 +00:00
parent 42634fbf3d
commit 5456d60876
9 changed files with 38 additions and 46 deletions

View File

@@ -306,7 +306,7 @@ func calculateDirSizeFast(root string, filesScanned, dirsScanned, bytesScanned *
subDir := filepath.Join(dirPath, entry.Name()) subDir := filepath.Join(dirPath, entry.Name())
go func(p string) { go func(p string) {
defer wg.Done() defer wg.Done()
sem <- struct{}{} // Acquire token sem <- struct{}{} // Acquire token
defer func() { <-sem }() // Release token defer func() { <-sem }() // Release token
walk(p) walk(p)
}(subDir) }(subDir)

View File

@@ -163,22 +163,22 @@ func (c *Collector) Collect() (MetricsSnapshot, error) {
hostInfo, _ := host.Info() hostInfo, _ := host.Info()
var ( var (
wg sync.WaitGroup wg sync.WaitGroup
errMu sync.Mutex errMu sync.Mutex
mergeErr error mergeErr error
cpuStats CPUStatus cpuStats CPUStatus
memStats MemoryStatus memStats MemoryStatus
diskStats []DiskStatus diskStats []DiskStatus
diskIO DiskIOStatus diskIO DiskIOStatus
netStats []NetworkStatus netStats []NetworkStatus
proxyStats ProxyStatus proxyStats ProxyStatus
batteryStats []BatteryStatus batteryStats []BatteryStatus
thermalStats ThermalStatus thermalStats ThermalStatus
sensorStats []SensorReading sensorStats []SensorReading
gpuStats []GPUStatus gpuStats []GPUStatus
btStats []BluetoothDevice btStats []BluetoothDevice
topProcs []ProcessInfo topProcs []ProcessInfo
) )
// Helper to launch concurrent collection // Helper to launch concurrent collection

View File

@@ -164,8 +164,8 @@ scan_installed_apps() {
( (
run_with_timeout 5 find ~/Library/LaunchAgents /Library/LaunchAgents \ run_with_timeout 5 find ~/Library/LaunchAgents /Library/LaunchAgents \
-name "*.plist" -type f 2> /dev/null | -name "*.plist" -type f 2> /dev/null |
xargs -I {} basename {} .plist > "$scan_tmp_dir/agents.txt" 2> /dev/null || true xargs -I {} basename {} .plist > "$scan_tmp_dir/agents.txt" 2> /dev/null || true
) & ) &
pids+=($!) pids+=($!)
@@ -212,7 +212,6 @@ is_bundle_orphaned() {
return 1 return 1
fi fi
# Extra check for specific system bundles not covered by patterns # Extra check for specific system bundles not covered by patterns
case "$bundle_id" in case "$bundle_id" in
loginwindow | dock | systempreferences | finder | safari) loginwindow | dock | systempreferences | finder | safari)

View File

@@ -38,7 +38,7 @@ clean_orphaned_casks() {
rm -f "$cask_cache" 2> /dev/null || true rm -f "$cask_cache" 2> /dev/null || true
true > "$cask_cache" true > "$cask_cache"
while IFS= read -r cask; do while IFS= read -r cask; do
# Get app path from cask info with timeout protection (expensive call, hence caching) # Get app path from cask info with timeout protection (expensive call, hence caching)
local cask_info local cask_info
cask_info=$(run_with_timeout 10 brew info --cask "$cask" 2> /dev/null || true) cask_info=$(run_with_timeout 10 brew info --cask "$cask" 2> /dev/null || true)
@@ -62,12 +62,11 @@ clean_orphaned_casks() {
# Check if app exists into common locations # Check if app exists into common locations
# We must check both /Applications and ~/Applications # We must check both /Applications and ~/Applications
if [[ ! -e "/Applications/$app_name" ]] && [[ ! -e "$HOME/Applications/$app_name" ]]; then if [[ ! -e "/Applications/$app_name" ]] && [[ ! -e "$HOME/Applications/$app_name" ]]; then
orphaned_casks+=("$cask") orphaned_casks+=("$cask")
fi fi
done < <(brew list --cask 2> /dev/null || true) done < <(brew list --cask 2> /dev/null || true)
fi fi
# Remove orphaned casks if found and sudo session is still valid # Remove orphaned casks if found and sudo session is still valid
if [[ ${#orphaned_casks[@]} -gt 0 ]]; then if [[ ${#orphaned_casks[@]} -gt 0 ]]; then
# Check if sudo session is still valid (without prompting) # Check if sudo session is still valid (without prompting)

View File

@@ -52,8 +52,6 @@ clean_deep_system() {
fi fi
fi fi
# Clean macOS Install Data (system upgrade leftovers) # Clean macOS Install Data (system upgrade leftovers)
# Only remove if older than 30 days to ensure system stability # Only remove if older than 30 days to ensure system stability
if [[ -d "/macOS Install Data" ]]; then if [[ -d "/macOS Install Data" ]]; then

View File

@@ -734,23 +734,23 @@ find_app_receipt_files() {
# Whitelisted prefixes # Whitelisted prefixes
case "$clean_path" in case "$clean_path" in
/Applications/*) is_safe=true ;; /Applications/*) is_safe=true ;;
/Users/*) is_safe=true ;; /Users/*) is_safe=true ;;
/usr/local/*) is_safe=true ;; /usr/local/*) is_safe=true ;;
/opt/*) is_safe=true ;; /opt/*) is_safe=true ;;
/Library/*) /Library/*)
# Filter sub-paths in /Library to avoid system damage # Filter sub-paths in /Library to avoid system damage
# Allow safely: Application Support, Caches, Logs, Preferences # Allow safely: Application Support, Caches, Logs, Preferences
case "$clean_path" in case "$clean_path" in
/Library/Application\ Support/*) is_safe=true ;; /Library/Application\ Support/*) is_safe=true ;;
/Library/Caches/*) is_safe=true ;; /Library/Caches/*) is_safe=true ;;
/Library/Logs/*) is_safe=true ;; /Library/Logs/*) is_safe=true ;;
/Library/Preferences/*) is_safe=true ;; /Library/Preferences/*) is_safe=true ;;
/Library/PrivilegedHelperTools/*) is_safe=true ;; /Library/PrivilegedHelperTools/*) is_safe=true ;;
/Library/LaunchAgents/*) is_safe=true ;; /Library/LaunchAgents/*) is_safe=true ;;
/Library/LaunchDaemons/*) is_safe=true ;; /Library/LaunchDaemons/*) is_safe=true ;;
/Library/Internet\ Plug-Ins/*) is_safe=true ;; /Library/Internet\ Plug-Ins/*) is_safe=true ;;
/Library/Audio/Plug-Ins/*) is_safe=true ;; /Library/Audio/Plug-Ins/*) is_safe=true ;;
/Library/Extensions/*) is_safe=false ;; # Default unsafe /Library/Extensions/*) is_safe=false ;; # Default unsafe
*) is_safe=false ;; *) is_safe=false ;;
esac esac
;; ;;
@@ -758,7 +758,7 @@ find_app_receipt_files() {
# Hard blocks # Hard blocks
case "$clean_path" in case "$clean_path" in
/System/*|/usr/bin/*|/usr/lib/*|/bin/*|/sbin/*) is_safe=false ;; /System/* | /usr/bin/* | /usr/lib/* | /bin/* | /sbin/*) is_safe=false ;;
esac esac
if [[ "$is_safe" == "true" && -e "$clean_path" ]]; then if [[ "$is_safe" == "true" && -e "$clean_path" ]]; then
@@ -774,7 +774,7 @@ find_app_receipt_files() {
# Extra check: path must be deep enough? # Extra check: path must be deep enough?
# If path is just "/Applications", skip. # If path is just "/Applications", skip.
if [[ "$clean_path" == "/Applications" || "$clean_path" == "/Library" || "$clean_path" == "/usr/local" ]]; then if [[ "$clean_path" == "/Applications" || "$clean_path" == "/Library" || "$clean_path" == "/usr/local" ]]; then
continue continue
fi fi
receipt_files+=("$clean_path") receipt_files+=("$clean_path")

View File

@@ -127,7 +127,7 @@ log_system_info() {
echo "Shell: ${SHELL:-unknown} (${TERM:-unknown})" echo "Shell: ${SHELL:-unknown} (${TERM:-unknown})"
# Check sudo status non-interactively # Check sudo status non-interactively
if sudo -n true 2>/dev/null; then if sudo -n true 2> /dev/null; then
echo "Sudo Access: Active" echo "Sudo Access: Active"
else else
echo "Sudo Access: Required" echo "Sudo Access: Required"

View File

@@ -254,12 +254,12 @@ perform_updates() {
if [[ -x "$mole_bin" ]]; then if [[ -x "$mole_bin" ]]; then
if "$mole_bin" update 2>&1 | grep -qE "(Updated|latest version)"; then if "$mole_bin" update 2>&1 | grep -qE "(Updated|latest version)"; then
echo -e "${GREEN}${NC} Mole updated" echo -e "${GREEN}${NC} Mole updated"
reset_mole_cache reset_mole_cache
((updated_count++)) ((updated_count++))
else else
echo -e "${RED}${NC} Mole update failed" echo -e "${RED}${NC} Mole update failed"
fi fi
else else
echo -e "${RED}${NC} Mole executable not found" echo -e "${RED}${NC} Mole executable not found"
fi fi

View File

@@ -16,8 +16,6 @@ opt_system_maintenance() {
echo -e "${RED}${ICON_ERROR}${NC} Failed to clear DNS cache" echo -e "${RED}${ICON_ERROR}${NC} Failed to clear DNS cache"
fi fi
echo -e "${BLUE}${ICON_ARROW}${NC} Checking Spotlight index..." echo -e "${BLUE}${ICON_ARROW}${NC} Checking Spotlight index..."
local md_status local md_status
md_status=$(mdutil -s / 2> /dev/null || echo "") md_status=$(mdutil -s / 2> /dev/null || echo "")
@@ -31,7 +29,6 @@ opt_system_maintenance() {
sudo pkill -f blued 2> /dev/null || true sudo pkill -f blued 2> /dev/null || true
echo -e "${GREEN}${ICON_SUCCESS}${NC} Bluetooth controller refreshed" echo -e "${GREEN}${ICON_SUCCESS}${NC} Bluetooth controller refreshed"
} }
# Cache refresh: update Finder/Safari caches # Cache refresh: update Finder/Safari caches
@@ -112,7 +109,6 @@ opt_radio_refresh() {
echo -e "${BLUE}${ICON_ARROW}${NC} Refreshing Wi-Fi service..." echo -e "${BLUE}${ICON_ARROW}${NC} Refreshing Wi-Fi service..."
# Only restart Wi-Fi service, do NOT delete saved networks # Only restart Wi-Fi service, do NOT delete saved networks
# Safe alternative: just restart the Wi-Fi interface # Safe alternative: just restart the Wi-Fi interface
local wifi_interface local wifi_interface
wifi_interface=$(networksetup -listallhardwareports | awk '/Wi-Fi/{getline; print $2}' | head -1) wifi_interface=$(networksetup -listallhardwareports | awk '/Wi-Fi/{getline; print $2}' | head -1)