1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-11 05:59:16 +00:00

Fix search problems and best practices

This commit is contained in:
Tw93
2025-12-08 17:40:54 +08:00
parent 95ff2e30ac
commit 2386701897
7 changed files with 151 additions and 24 deletions

View File

@@ -456,7 +456,10 @@ safe_clean() {
}
start_cleanup() {
clear
if [[ -t 1 ]]; then
# Avoid relying on TERM since CI often runs without it
printf '\033[2J\033[H'
fi
printf '\n'
echo -e "${PURPLE_BOLD}Clean Your Mac${NC}"
echo ""

View File

@@ -73,11 +73,12 @@ scan_applications() {
local cache_dir="$HOME/.cache/mole"
local cache_file="$cache_dir/app_scan_cache"
local cache_ttl=86400 # 24 hours
local force_rescan="${1:-false}"
mkdir -p "$cache_dir" 2> /dev/null
# Check if cache exists and is fresh
if [[ -f "$cache_file" ]]; then
if [[ $force_rescan == false && -f "$cache_file" ]]; then
local cache_age=$(($(date +%s) - $(get_file_mtime "$cache_file")))
[[ $cache_age -eq $(date +%s) ]] && cache_age=86401 # Handle missing file
if [[ $cache_age -lt $cache_ttl ]]; then
@@ -405,11 +406,15 @@ trap cleanup EXIT INT TERM
# Main function
main() {
# Parse args
local force_rescan=false
for arg in "$@"; do
case "$arg" in
"--debug")
export MO_DEBUG=1
;;
"--force-rescan")
force_rescan=true
;;
esac
done
@@ -425,7 +430,7 @@ main() {
# (scan_applications handles cache internally)
local needs_scanning=true
local cache_file="$HOME/.cache/mole/app_scan_cache"
if [[ -f "$cache_file" ]]; then
if [[ $force_rescan == false && -f "$cache_file" ]]; then
local cache_age=$(($(date +%s) - $(get_file_mtime "$cache_file")))
[[ $cache_age -eq $(date +%s) ]] && cache_age=86401 # Handle missing file
[[ $cache_age -lt 86400 ]] && needs_scanning=false
@@ -444,7 +449,7 @@ main() {
# Scan applications
local apps_file=""
if ! apps_file=$(scan_applications); then
if ! apps_file=$(scan_applications "$force_rescan"); then
if [[ "${MOLE_ALT_SCREEN_ACTIVE:-}" == "1" ]]; then
printf "\033[2J\033[H" >&2
leave_alt_screen