mirror of
https://github.com/tw93/Mole.git
synced 2026-03-22 19:40:07 +00:00
🐛 Version update check
This commit is contained in:
30
mole
30
mole
@@ -20,37 +20,46 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$SCRIPT_DIR/lib/common.sh"
|
||||
|
||||
# Version info
|
||||
VERSION="1.3.2"
|
||||
VERSION="1.3.1"
|
||||
MOLE_TAGLINE="can dig deep to clean your Mac."
|
||||
|
||||
# Check for updates (non-blocking, cached)
|
||||
check_for_updates() {
|
||||
local cache="$HOME/.cache/mole/version_check"
|
||||
|
||||
local msg_cache="$HOME/.cache/mole/update_message"
|
||||
mkdir -p "$(dirname "$cache")" 2>/dev/null
|
||||
|
||||
# Show cached message if less than 24 hours old
|
||||
# Skip if checked within 24 hours
|
||||
if [[ -f "$cache" ]]; then
|
||||
local age=$(($(date +%s) - $(stat -f%m "$cache" 2>/dev/null || echo 0)))
|
||||
[[ $age -lt 86400 ]] && [[ -s "$cache" ]] && cat "$cache" && return
|
||||
[[ $age -lt 86400 ]] && return
|
||||
fi
|
||||
|
||||
# Background version check
|
||||
# Background version check (save to file, don't output)
|
||||
(
|
||||
local latest=$(curl -fsSL --connect-timeout 2 --max-time 3 \
|
||||
"https://raw.githubusercontent.com/tw93/mole/main/mole" 2>/dev/null | \
|
||||
grep '^VERSION=' | head -1 | sed 's/VERSION="\(.*\)"/\1/')
|
||||
|
||||
if [[ -n "$latest" && "$VERSION" != "$latest" && "$(printf '%s\n' "$VERSION" "$latest" | sort -V | head -1)" == "$VERSION" ]]; then
|
||||
echo -e "${YELLOW}📢 New version ${GREEN}${latest}${YELLOW} available (current: ${VERSION})\n Run ${GREEN}mole update${YELLOW} to upgrade${NC}" | tee "$cache"
|
||||
echo -e "${YELLOW}📢 New version ${GREEN}${latest}${YELLOW} available (current: ${VERSION})\n Run ${GREEN}mole update${YELLOW} to upgrade${NC}" > "$msg_cache"
|
||||
else
|
||||
echo -n > "$cache"
|
||||
echo -n > "$msg_cache"
|
||||
fi
|
||||
touch "$cache" 2>/dev/null
|
||||
) &
|
||||
disown 2>/dev/null || true
|
||||
}
|
||||
|
||||
# Show update notification if available
|
||||
show_update_notification() {
|
||||
local msg_cache="$HOME/.cache/mole/update_message"
|
||||
if [[ -f "$msg_cache" && -s "$msg_cache" ]]; then
|
||||
cat "$msg_cache"
|
||||
echo
|
||||
fi
|
||||
}
|
||||
|
||||
show_brand_banner() {
|
||||
cat << EOF
|
||||
${GREEN} __ __ _ ${NC}
|
||||
@@ -180,7 +189,7 @@ update_mole() {
|
||||
rm -f "$tmp_installer"
|
||||
|
||||
# Clear version check cache after successful update
|
||||
rm -f "$HOME/.cache/mole/version_check"
|
||||
rm -f "$HOME/.cache/mole/version_check" "$HOME/.cache/mole/update_message"
|
||||
}
|
||||
|
||||
# Display main menu options
|
||||
@@ -192,6 +201,7 @@ show_main_menu() {
|
||||
clear_screen
|
||||
echo ""
|
||||
show_brand_banner
|
||||
show_update_notification
|
||||
echo ""
|
||||
printf '\033[s'
|
||||
else
|
||||
@@ -274,9 +284,6 @@ interactive_main_menu() {
|
||||
}
|
||||
|
||||
main() {
|
||||
# Check for updates (non-blocking, won't delay startup)
|
||||
check_for_updates
|
||||
|
||||
case "${1:-""}" in
|
||||
"clean")
|
||||
exec "$SCRIPT_DIR/bin/clean.sh" "${@:2}"
|
||||
@@ -297,6 +304,7 @@ main() {
|
||||
exit 0
|
||||
;;
|
||||
"")
|
||||
check_for_updates
|
||||
interactive_main_menu
|
||||
;;
|
||||
*)
|
||||
|
||||
Reference in New Issue
Block a user