pub struct VersionChecker { /* private fields */ }Expand description
Version checking and caching system with automatic update notifications.
VersionChecker provides intelligent caching of version information and
automatic update checking based on user configuration. It manages notification
state to avoid alert fatigue while ensuring users are aware of updates.
§Features
- Automatic Checking: Checks for updates based on configured intervals
- Smart Caching: Reduces GitHub API calls with intelligent cache management
- Notification Tracking: Avoids repeated notifications for the same update
- Configurable Behavior: Respects user preferences for update checking
§Caching Strategy
The version checker implements a sophisticated caching strategy:
- Stores version information with timestamps
- Tracks notification state to avoid alert fatigue
- Uses configurable intervals for cache expiration
- Implements exponential backoff for re-notifications
Implementations§
Source§impl VersionChecker
impl VersionChecker
Sourcepub async fn new() -> Result<Self>
pub async fn new() -> Result<Self>
Create a new VersionChecker with configuration from global settings.
Loads the global configuration and sets up the version checker with appropriate cache paths and update settings.
§Returns
Ok(VersionChecker)- Successfully created with loaded configurationErr(error)- Failed to load configuration or determine cache path
§Cache Location
The cache file is stored at:
- Unix/macOS:
~/.agpm/.version_cache - Windows:
%LOCALAPPDATA%\agpm\.version_cache
Sourcepub fn with_cache_dir(self, cache_dir: PathBuf) -> Self
pub fn with_cache_dir(self, cache_dir: PathBuf) -> Self
Create a new VersionChecker with custom cache directory.
§Arguments
cache_dir- Directory where the version cache file will be stored
Sourcepub async fn check_for_updates_if_needed(&self) -> Result<Option<String>>
pub async fn check_for_updates_if_needed(&self) -> Result<Option<String>>
Check for updates automatically based on configuration.
This is the main entry point for automatic update checking. It:
- Checks if automatic updates are enabled in configuration
- Loads and validates the cache
- Performs a new check if cache is expired
- Returns version info if user should be notified
§Returns
Ok(Some(version))- Update available and user should be notifiedOk(None)- No update or notification not neededErr(error)- Error during check (non-fatal, logged)
Sourcepub async fn check_now(&self) -> Result<Option<String>>
pub async fn check_now(&self) -> Result<Option<String>>
Perform an explicit update check, bypassing the cache.
This method always queries GitHub for the latest version, regardless of cache state. Used for manual update checks.
§Returns
Ok(Some(version))- New version availableOk(None)- Already on latest versionErr(error)- Check failed
Sourcepub async fn clear_cache(&self) -> Result<()>
pub async fn clear_cache(&self) -> Result<()>
Clear the version cache by removing the cache file.
Removes cached version information, forcing subsequent version checks to fetch fresh data from GitHub.
Sourcepub fn display_update_notification(latest_version: &str)
pub fn display_update_notification(latest_version: &str)
Display a user-friendly update notification.
Shows an attractive notification banner informing the user about the available update with instructions on how to upgrade.
§Arguments
latest_version- The new version available for upgrade
Auto Trait Implementations§
impl Freeze for VersionChecker
impl RefUnwindSafe for VersionChecker
impl Send for VersionChecker
impl Sync for VersionChecker
impl Unpin for VersionChecker
impl UnwindSafe for VersionChecker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more