mirror of
https://github.com/tw93/Mole.git
synced 2026-03-24 12:55:07 +00:00
Fix the update check problem
This commit is contained in:
40
mole
40
mole
@@ -22,7 +22,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|||||||
source "$SCRIPT_DIR/lib/core/common.sh"
|
source "$SCRIPT_DIR/lib/core/common.sh"
|
||||||
|
|
||||||
# Version info
|
# Version info
|
||||||
VERSION="1.11.8"
|
VERSION="1.11.9"
|
||||||
MOLE_TAGLINE="can dig deep to clean your Mac."
|
MOLE_TAGLINE="can dig deep to clean your Mac."
|
||||||
|
|
||||||
# Check if Touch ID is already configured
|
# Check if Touch ID is already configured
|
||||||
@@ -38,13 +38,15 @@ get_latest_version() {
|
|||||||
grep '^VERSION=' | head -1 | sed 's/VERSION="\(.*\)"/\1/'
|
grep '^VERSION=' | head -1 | sed 's/VERSION="\(.*\)"/\1/'
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get latest version from Homebrew for brew-installed Mole
|
# Get latest version from GitHub API
|
||||||
get_latest_brew_version() {
|
# This works for both Homebrew and manual installs since versions are synced
|
||||||
if ! command -v brew > /dev/null 2>&1; then
|
get_latest_version_from_github() {
|
||||||
return 1
|
local version
|
||||||
fi
|
version=$(curl -fsSL --connect-timeout 2 --max-time 3 \
|
||||||
|
"https://api.github.com/repos/tw93/mole/releases/latest" 2> /dev/null |
|
||||||
brew info --json=v2 mole 2> /dev/null | grep -o '"version":"[^"]*"' | head -1 | sed 's/"version":"\(.*\)"/\1/'
|
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
|
# Check if installed via Homebrew
|
||||||
@@ -69,21 +71,17 @@ check_for_updates() {
|
|||||||
# Background version check (save to file, don't output)
|
# Background version check (save to file, don't output)
|
||||||
(
|
(
|
||||||
local latest
|
local latest
|
||||||
local check_method=""
|
local check_method="github"
|
||||||
|
|
||||||
# For Homebrew installations, check Homebrew version
|
# Use GitHub API for version check (works for both Homebrew and manual installs)
|
||||||
if is_homebrew_install; then
|
# Try API first (faster and more reliable)
|
||||||
latest=$(get_latest_brew_version)
|
latest=$(get_latest_version_from_github)
|
||||||
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
|
if [[ -z "$latest" ]]; then
|
||||||
|
# Fallback to parsing mole script from raw GitHub
|
||||||
latest=$(get_latest_version)
|
latest=$(get_latest_version)
|
||||||
check_method="github"
|
check_method="github-raw"
|
||||||
[[ -n "${MO_UPDATE_DEBUG:-}" ]] && echo "$(date): Checking via GitHub, got: $latest" >> "$debug_log"
|
|
||||||
fi
|
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
|
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"
|
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
|
# Check for updates
|
||||||
local latest
|
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
|
if [[ -z "$latest" ]]; then
|
||||||
log_error "Unable to check for updates. Check network connection."
|
log_error "Unable to check for updates. Check network connection."
|
||||||
|
|||||||
Reference in New Issue
Block a user