forked from cinco/tmuxido
✨ feat: periodic update check on startup
On startup, if `update_check_interval_hours` have elapsed since the last check, fetches the latest release tag from the Gitea API and prints a notice when a newer version is available. Silent on network failure or no update found. - New `update_check` module with injected fetcher for full testability - Cache at ~/.cache/tmuxido/update_check.json tracks timestamp + version - `fetch_latest_tag` and `version_compare` promoted to `pub(crate)` - 6 unit tests covering disabled, interval not elapsed, fetch triggered, equal versions, update available, and current-newer edge case
This commit is contained in:
+2
-2
@@ -27,7 +27,7 @@ fn detect_arch() -> Result<&'static str> {
|
||||
}
|
||||
|
||||
/// Fetch latest release tag from Gitea API
|
||||
fn fetch_latest_tag() -> Result<String> {
|
||||
pub(crate) fn fetch_latest_tag() -> Result<String> {
|
||||
let url = format!("{}/api/v1/repos/{}/releases?limit=1&page=1", BASE_URL, REPO);
|
||||
|
||||
let output = Command::new("curl")
|
||||
@@ -166,7 +166,7 @@ pub fn self_update() -> Result<()> {
|
||||
}
|
||||
|
||||
/// Compare two semver versions
|
||||
fn version_compare(a: &str, b: &str) -> std::cmp::Ordering {
|
||||
pub(crate) fn version_compare(a: &str, b: &str) -> std::cmp::Ordering {
|
||||
let parse = |s: &str| {
|
||||
s.split('.')
|
||||
.filter_map(|n| n.parse::<u32>().ok())
|
||||
|
||||
Reference in New Issue
Block a user