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

Optimize the display of all prompts

This commit is contained in:
Tw93
2025-11-20 15:33:16 +08:00
parent 85ddc3ad71
commit 780b738e72
6 changed files with 74 additions and 36 deletions

47
mole
View File

@@ -22,7 +22,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/lib/common.sh"
# Version info
VERSION="1.9.16"
VERSION="1.9.17"
MOLE_TAGLINE="can dig deep to clean your Mac."
# Get latest version from remote repository
@@ -32,10 +32,25 @@ get_latest_version() {
grep '^VERSION=' | head -1 | sed 's/VERSION="\(.*\)"/\1/'
}
# Get latest version from Homebrew for brew-installed Mole
get_latest_brew_version() {
if ! command -v brew > /dev/null 2>&1; then
return 1
fi
brew info --json=v2 mole 2> /dev/null | grep -o '"version":"[^"]*"' | head -1 | sed 's/"version":"\(.*\)"/\1/'
}
# Check if installed via Homebrew
is_homebrew_install() {
command -v brew > /dev/null 2>&1 && brew list mole > /dev/null 2>&1
}
# Check for updates (non-blocking, cached)
check_for_updates() {
local cache="$HOME/.cache/mole/version_check"
local msg_cache="$HOME/.cache/mole/update_message"
local debug_log="$HOME/.cache/mole/update_check_debug"
local ttl="${MO_UPDATE_CHECK_TTL:-3600}"
mkdir -p "$(dirname "$cache")" 2> /dev/null
@@ -48,12 +63,28 @@ check_for_updates() {
# Background version check (save to file, don't output)
(
local latest
latest=$(get_latest_version)
local check_method=""
# For Homebrew installations, check Homebrew version
if is_homebrew_install; then
latest=$(get_latest_brew_version)
check_method="brew"
[[ -n "${MO_UPDATE_DEBUG:-}" ]] && echo "$(date): Checking via Homebrew, got: $latest" >> "$debug_log"
fi
# Fallback to GitHub for non-brew or if brew check failed
if [[ -z "$latest" ]]; then
latest=$(get_latest_version)
check_method="github"
[[ -n "${MO_UPDATE_DEBUG:-}" ]] && echo "$(date): Checking via GitHub, got: $latest" >> "$debug_log"
fi
if [[ -n "$latest" && "$VERSION" != "$latest" && "$(printf '%s\n' "$VERSION" "$latest" | sort -V | head -1)" == "$VERSION" ]]; then
printf "\nUpdate available: %s → %s, run %smo update%s\n\n" "$VERSION" "$latest" "$GREEN" "$NC" > "$msg_cache"
[[ -n "${MO_UPDATE_DEBUG:-}" ]] && echo "$(date): Update available ($check_method): $VERSION → $latest" >> "$debug_log"
else
echo -n > "$msg_cache"
[[ -n "${MO_UPDATE_DEBUG:-}" ]] && echo "$(date): No update needed ($check_method): $VERSION == $latest" >> "$debug_log"
fi
touch "$cache" 2> /dev/null
) &
@@ -151,7 +182,7 @@ show_help() {
# Simple update function
update_mole() {
# Check if installed via Homebrew
if command -v brew > /dev/null 2>&1 && brew list mole > /dev/null 2>&1; then
if is_homebrew_install; then
update_via_homebrew "$VERSION"
exit 0
fi
@@ -279,7 +310,7 @@ remove_mole() {
local -a alias_installs=()
# Check Homebrew
if command -v brew > /dev/null 2>&1 && brew list mole > /dev/null 2>&1; then
if is_homebrew_install; then
is_homebrew=true
fi
@@ -475,7 +506,7 @@ show_main_menu() {
if [[ -t 0 ]]; then
printf '\r\033[2K\n'
printf '\r\033[2K%s\n' "${GRAY}↑/Nav ${GRAY}|${NC} ${GRAY}Enter${NC} Select ${GRAY}|${NC} ${GRAY}H${NC} Help ${GRAY}|${NC} ${GRAY}Q${NC} Quit"
printf '\r\033[2K%s\n' "${GRAY}↑↓ | Enter | H Help | V Version | Q Quit${NC}"
printf '\r\033[2K\n'
fi
@@ -570,6 +601,12 @@ interactive_main_menu() {
show_help
exit 0
;;
"VERSION")
show_cursor
clear
show_version
exit 0
;;
"QUIT") cleanup_and_exit ;;
esac
done