use std::time::Duration;
use update_informer::{Check, registry::GitHub};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum InstallMethod {
Homebrew,
Cargo,
Binary,
}
impl InstallMethod {
pub fn detect() -> Self {
let exe_path = std::env::current_exe()
.ok()
.and_then(|p| p.canonicalize().ok());
if let Some(path) = exe_path {
let path_str = path.to_string_lossy().to_lowercase();
if path_str.contains("homebrew") || path_str.contains("cellar") {
return Self::Homebrew;
}
if path_str.contains(".cargo/bin") {
return Self::Cargo;
}
}
Self::Binary
}
pub fn update_command(&self) -> &'static str {
match self {
Self::Homebrew => "brew upgrade xfr",
Self::Cargo => "cargo install xfr",
Self::Binary => "github.com/lance0/xfr/releases",
}
}
}
pub fn check_for_update() -> Option<String> {
let informer = update_informer::new(GitHub, "lance0/xfr", env!("CARGO_PKG_VERSION"))
.interval(Duration::from_secs(3600));
informer
.check_version()
.ok()
.flatten()
.map(|v| v.to_string())
}