use anyhow::Result;
use std::thread;
pub const NO_AUTOUPDATE: &str = "KAGI_NO_AUTOUPDATE";
fn options() -> kaishin::KaishinOptions {
kaishin::KaishinOptions::new("yukimemi", "kagi", "kagi", env!("CARGO_PKG_VERSION"))
.crate_name(env!("CARGO_PKG_NAME"))
}
fn runtime() -> Result<tokio::runtime::Runtime> {
Ok(tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()?)
}
pub fn run_self_update(yes: bool, check_only: bool, non_interactive: bool) -> Result<()> {
let upd_opts = kaishin::UpdateOptions::new()
.yes(yes)
.check_only(check_only)
.non_interactive(non_interactive);
runtime()?.block_on(kaishin::run_self_update(&options(), upd_opts))
}
pub fn spawn_auto_update() {
if std::env::var_os(NO_AUTOUPDATE).is_some() {
return;
}
thread::spawn(|| {
let Ok(rt) = runtime() else { return };
let checker = kaishin::Checker::new("kagi", options());
let _ = rt.block_on(checker.auto_update());
});
}