1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-22 20:15:07 +00:00

Fix the update check problem

This commit is contained in:
Tw93
2025-12-01 19:34:20 +08:00
parent a0ec06b5db
commit 48a0570890

40
mole
View File

@@ -22,7 +22,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/lib/core/common.sh"
# Version info
VERSION="1.11.8"
VERSION="1.11.9"
MOLE_TAGLINE="can dig deep to clean your Mac."
# Check if Touch ID is already configured
@@ -38,13 +38,15 @@ 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/'
# Get latest version from GitHub API
# This works for both Homebrew and manual installs since versions are synced
get_latest_version_from_github() {
local version
version=$(curl -fsSL --connect-timeout 2 --max-time 3 \
"https://api.github.com/repos/tw93/mole/releases/latest" 2> /dev/null |
grep '"tag_name"' | head -1 | sed -E 's/.*"([^"]+)".*/\1/')
# Remove 'v' or 'V' prefix if present
echo "$version" | sed 's/^[vV]//'
}
# Check if installed via Homebrew
@@ -69,21 +71,17 @@ check_for_updates() {
# Background version check (save to file, don't output)
(
local latest
local check_method=""
local check_method="github"
# 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
# Use GitHub API for version check (works for both Homebrew and manual installs)
# Try API first (faster and more reliable)
latest=$(get_latest_version_from_github)
if [[ -z "$latest" ]]; then
# Fallback to parsing mole script from raw GitHub
latest=$(get_latest_version)
check_method="github"
[[ -n "${MO_UPDATE_DEBUG:-}" ]] && echo "$(date): Checking via GitHub, got: $latest" >> "$debug_log"
check_method="github-raw"
fi
[[ -n "${MO_UPDATE_DEBUG:-}" ]] && echo "$(date): Checking via $check_method, got: $latest" >> "$debug_log"
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"
@@ -198,7 +196,9 @@ update_mole() {
# Check for updates
local latest
latest=$(get_latest_version)
latest=$(get_latest_version_from_github)
# Fallback to raw GitHub if API fails
[[ -z "$latest" ]] && latest=$(get_latest_version)
if [[ -z "$latest" ]]; then
log_error "Unable to check for updates. Check network connection."