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

chore: auto format code

This commit is contained in:
Tw93
2025-12-29 11:07:20 +00:00
parent 580548876a
commit c8b2e3691b
2 changed files with 35 additions and 38 deletions

View File

@@ -60,5 +60,3 @@ fix_broken_preferences() {
echo "$broken_count"
}

View File

@@ -163,14 +163,14 @@ opt_sqlite_vacuum() {
should_protect_path "$db_file" && continue
# Verify it's a SQLite database
if ! file "$db_file" 2>/dev/null | grep -q "SQLite"; then
if ! file "$db_file" 2> /dev/null | grep -q "SQLite"; then
continue
fi
# Try to vacuum
local exit_code=0
set +e
run_with_timeout 20 sqlite3 "$db_file" "VACUUM;" 2>/dev/null
run_with_timeout 20 sqlite3 "$db_file" "VACUUM;" 2> /dev/null
exit_code=$?
set -e
@@ -330,14 +330,14 @@ opt_startup_items_cleanup() {
fi
if [[ "$need_sudo" == "true" ]]; then
sudo launchctl unload "$plist_file" 2>/dev/null || true
sudo launchctl unload "$plist_file" 2> /dev/null || true
if safe_sudo_remove "$plist_file"; then
((broken_count++))
else
echo -e " ${YELLOW}!${NC} Failed to remove (sudo) $plist_file"
fi
else
launchctl unload "$plist_file" 2>/dev/null || true
launchctl unload "$plist_file" 2> /dev/null || true
if safe_remove "$plist_file" true; then
((broken_count++))
else
@@ -349,10 +349,10 @@ opt_startup_items_cleanup() {
# Extract program path
local program=""
program=$(plutil -extract Program raw "$plist_file" 2>/dev/null || echo "")
program=$(plutil -extract Program raw "$plist_file" 2> /dev/null || echo "")
if [[ -z "$program" ]]; then
program=$(plutil -extract ProgramArguments.0 raw "$plist_file" 2>/dev/null || echo "")
program=$(plutil -extract ProgramArguments.0 raw "$plist_file" 2> /dev/null || echo "")
fi
program="${program/#\~/$HOME}"
@@ -363,7 +363,7 @@ opt_startup_items_cleanup() {
fi
# Check for orphaned privileged helpers (app uninstalled but helper remains)
local associated_bundle=""
associated_bundle=$(plutil -extract AssociatedBundleIdentifiers.0 raw "$plist_file" 2>/dev/null || echo "")
associated_bundle=$(plutil -extract AssociatedBundleIdentifiers.0 raw "$plist_file" 2> /dev/null || echo "")
if [[ -n "$associated_bundle" ]]; then
# Check if the associated app exists
@@ -375,7 +375,7 @@ opt_startup_items_cleanup() {
app_path="$HOME/Applications/$associated_bundle.app"
else
# Fallback to mdfind (slower but comprehensive, with 10s timeout)
app_path=$(run_with_timeout 10 mdfind "kMDItemCFBundleIdentifier == '$associated_bundle'" 2>/dev/null | head -1 || echo "")
app_path=$(run_with_timeout 10 mdfind "kMDItemCFBundleIdentifier == '$associated_bundle'" 2> /dev/null | head -1 || echo "")
fi
# If associated app is MISSING, this is an orphan
@@ -386,9 +386,9 @@ opt_startup_items_cleanup() {
# Get the helper tool path
local program=""
program=$(plutil -extract Program raw "$plist_file" 2>/dev/null || echo "")
program=$(plutil -extract Program raw "$plist_file" 2> /dev/null || echo "")
if [[ -z "$program" ]]; then
program=$(plutil -extract ProgramArguments.0 raw "$plist_file" 2>/dev/null || echo "")
program=$(plutil -extract ProgramArguments.0 raw "$plist_file" 2> /dev/null || echo "")
fi
program="${program/#\~/$HOME}"
@@ -402,7 +402,7 @@ opt_startup_items_cleanup() {
fi
if [[ "$need_sudo" == "true" ]]; then
sudo launchctl unload "$plist_file" 2>/dev/null || true
sudo launchctl unload "$plist_file" 2> /dev/null || true
# remove the plist
safe_sudo_remove "$plist_file"
@@ -413,7 +413,7 @@ opt_startup_items_cleanup() {
((broken_count++))
echo -e " ${GREEN}${NC} Removed orphaned helper: $(basename "$program")"
else
launchctl unload "$plist_file" 2>/dev/null || true
launchctl unload "$plist_file" 2> /dev/null || true
safe_remove "$plist_file" true
if [[ -n "$program" && -f "$program" ]]; then
safe_remove "$program" true
@@ -432,14 +432,14 @@ opt_startup_items_cleanup() {
fi
if [[ "$need_sudo" == "true" ]]; then
sudo launchctl unload "$plist_file" 2>/dev/null || true
sudo launchctl unload "$plist_file" 2> /dev/null || true
if safe_sudo_remove "$plist_file"; then
((broken_count++))
else
echo -e " ${YELLOW}!${NC} Failed to remove (sudo) $plist_file"
fi
else
launchctl unload "$plist_file" 2>/dev/null || true
launchctl unload "$plist_file" 2> /dev/null || true
if safe_remove "$plist_file" true; then
((broken_count++))
else
@@ -447,7 +447,7 @@ opt_startup_items_cleanup() {
fi
fi
fi
done < <("${find_cmd[@]}" "$dir" -maxdepth 1 -name "*.plist" -type f 2>/dev/null || true)
done < <("${find_cmd[@]}" "$dir" -maxdepth 1 -name "*.plist" -type f 2> /dev/null || true)
done
if [[ $broken_count -gt 0 ]]; then
@@ -475,7 +475,7 @@ opt_dyld_cache_update() {
local dyld_cache_path="/var/db/dyld/dyld_shared_cache_$(uname -m)"
if [[ -e "$dyld_cache_path" ]]; then
local cache_mtime
cache_mtime=$(stat -f "%m" "$dyld_cache_path" 2>/dev/null || echo "0")
cache_mtime=$(stat -f "%m" "$dyld_cache_path" 2> /dev/null || echo "0")
local current_time
current_time=$(date +%s)
local time_diff=$((current_time - cache_mtime))
@@ -522,22 +522,22 @@ opt_system_services_refresh() {
local -a restarted_services=()
# cfprefsd - Preferences cache daemon (ensures fixed preferences take effect)
if killall -HUP cfprefsd 2>/dev/null; then
if killall -HUP cfprefsd 2> /dev/null; then
restarted_services+=("Preferences")
fi
# lsd - LaunchServices daemon (ensures rebuild takes effect)
if killall lsd 2>/dev/null; then
if killall lsd 2> /dev/null; then
restarted_services+=("LaunchServices")
fi
# iconservicesagent - Icon services (ensures cache refresh takes effect)
if killall iconservicesagent 2>/dev/null; then
if killall iconservicesagent 2> /dev/null; then
restarted_services+=("Icon Services")
fi
# fontd - Font server (ensures font cache refresh takes effect)
if killall fontd 2>/dev/null; then
if killall fontd 2> /dev/null; then
restarted_services+=("Font Server")
fi
@@ -563,18 +563,18 @@ opt_dock_refresh() {
if [[ -f "$db_file" ]]; then
safe_remove "$db_file" true > /dev/null 2>&1 && refreshed=true
fi
done < <(find "$dock_support" -name "*.db" -type f 2>/dev/null || true)
done < <(find "$dock_support" -name "*.db" -type f 2> /dev/null || true)
fi
# Also clear Dock plist cache
local dock_plist="$HOME/Library/Preferences/com.apple.dock.plist"
if [[ -f "$dock_plist" ]]; then
# Just touch to invalidate cache, don't delete (preserves user settings)
touch "$dock_plist" 2>/dev/null || true
touch "$dock_plist" 2> /dev/null || true
fi
# Restart Dock to apply changes
killall Dock 2>/dev/null || true
killall Dock 2> /dev/null || true
if [[ "$refreshed" == "true" ]]; then
echo -e " ${GREEN}${NC} Dock cache cleared"
@@ -582,7 +582,6 @@ opt_dock_refresh() {
echo -e " ${GREEN}${NC} Dock refreshed"
}
# Execute optimization by action name
execute_optimization() {
local action="$1"