mirror of
https://github.com/tw93/Mole.git
synced 2026-03-23 21:35:06 +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"
|
source "$SCRIPT_DIR/lib/common.sh"
|
||||||
|
|
||||||
# Version info
|
# Version info
|
||||||
VERSION="1.3.2"
|
VERSION="1.3.1"
|
||||||
MOLE_TAGLINE="can dig deep to clean your Mac."
|
MOLE_TAGLINE="can dig deep to clean your Mac."
|
||||||
|
|
||||||
# Check for updates (non-blocking, cached)
|
# Check for updates (non-blocking, cached)
|
||||||
check_for_updates() {
|
check_for_updates() {
|
||||||
local cache="$HOME/.cache/mole/version_check"
|
local cache="$HOME/.cache/mole/version_check"
|
||||||
|
local msg_cache="$HOME/.cache/mole/update_message"
|
||||||
mkdir -p "$(dirname "$cache")" 2>/dev/null
|
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
|
if [[ -f "$cache" ]]; then
|
||||||
local age=$(($(date +%s) - $(stat -f%m "$cache" 2>/dev/null || echo 0)))
|
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
|
fi
|
||||||
|
|
||||||
# Background version check
|
# Background version check (save to file, don't output)
|
||||||
(
|
(
|
||||||
local latest=$(curl -fsSL --connect-timeout 2 --max-time 3 \
|
local latest=$(curl -fsSL --connect-timeout 2 --max-time 3 \
|
||||||
"https://raw.githubusercontent.com/tw93/mole/main/mole" 2>/dev/null | \
|
"https://raw.githubusercontent.com/tw93/mole/main/mole" 2>/dev/null | \
|
||||||
grep '^VERSION=' | head -1 | sed 's/VERSION="\(.*\)"/\1/')
|
grep '^VERSION=' | head -1 | sed 's/VERSION="\(.*\)"/\1/')
|
||||||
|
|
||||||
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
|
||||||
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
|
else
|
||||||
echo -n > "$cache"
|
echo -n > "$msg_cache"
|
||||||
fi
|
fi
|
||||||
touch "$cache" 2>/dev/null
|
touch "$cache" 2>/dev/null
|
||||||
) &
|
) &
|
||||||
disown 2>/dev/null || true
|
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() {
|
show_brand_banner() {
|
||||||
cat << EOF
|
cat << EOF
|
||||||
${GREEN} __ __ _ ${NC}
|
${GREEN} __ __ _ ${NC}
|
||||||
@@ -180,7 +189,7 @@ update_mole() {
|
|||||||
rm -f "$tmp_installer"
|
rm -f "$tmp_installer"
|
||||||
|
|
||||||
# Clear version check cache after successful update
|
# 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
|
# Display main menu options
|
||||||
@@ -192,6 +201,7 @@ show_main_menu() {
|
|||||||
clear_screen
|
clear_screen
|
||||||
echo ""
|
echo ""
|
||||||
show_brand_banner
|
show_brand_banner
|
||||||
|
show_update_notification
|
||||||
echo ""
|
echo ""
|
||||||
printf '\033[s'
|
printf '\033[s'
|
||||||
else
|
else
|
||||||
@@ -274,9 +284,6 @@ interactive_main_menu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
# Check for updates (non-blocking, won't delay startup)
|
|
||||||
check_for_updates
|
|
||||||
|
|
||||||
case "${1:-""}" in
|
case "${1:-""}" in
|
||||||
"clean")
|
"clean")
|
||||||
exec "$SCRIPT_DIR/bin/clean.sh" "${@:2}"
|
exec "$SCRIPT_DIR/bin/clean.sh" "${@:2}"
|
||||||
@@ -297,6 +304,7 @@ main() {
|
|||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
"")
|
"")
|
||||||
|
check_for_updates
|
||||||
interactive_main_menu
|
interactive_main_menu
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
|||||||
Reference in New Issue
Block a user