feat(cli): add version update checks

This commit adds version update checks and feedback to the komorebic
start and check commands.
This commit is contained in:
LGUG2Z
2024-12-31 10:58:22 -08:00
parent 083ab65077
commit 7ef4fd81c0

View File

@@ -35,6 +35,7 @@ use miette::SourceSpan;
use paste::paste;
use schemars::gen::SchemaSettings;
use schemars::schema_for;
use serde::Deserialize;
use sysinfo::ProcessesToUpdate;
use which::which;
use windows::Win32::Foundation::HWND;
@@ -1667,6 +1668,30 @@ fn main() -> Result<()> {
println!("No komorebi configuration found in {home_display}\n");
println!("If running 'komorebic start --await-configuration', you will manually have to call the following command to begin tiling: komorebic complete-configuration\n");
}
let client = reqwest::blocking::Client::new();
if let Ok(response) = client
.get("https://api.github.com/repos/LGUG2Z/komorebi/releases/latest")
.header("User-Agent", "komorebic-version-checker")
.send()
{
let version = env!("CARGO_PKG_VERSION");
#[derive(Deserialize)]
struct Release {
tag_name: String,
}
if let Ok(release) =
serde_json::from_str::<Release>(&response.text().unwrap_or_default())
{
let trimmed = release.tag_name.trim_start_matches("v");
if trimmed > version {
println!("An updated version of komorebi is available! https://github.com/LGUG2Z/komorebi/releases/v{trimmed}");
}
}
}
}
SubCommand::Configuration => {
let static_config = HOME_DIR.join("komorebi.json");
@@ -2246,6 +2271,30 @@ if (!(Get-Process masir -ErrorAction SilentlyContinue))
let stdout = String::from_utf8(output.stdout)?;
println!("{stdout}");
}
let client = reqwest::blocking::Client::new();
if let Ok(response) = client
.get("https://api.github.com/repos/LGUG2Z/komorebi/releases/latest")
.header("User-Agent", "komorebic-version-checker")
.send()
{
let version = env!("CARGO_PKG_VERSION");
#[derive(Deserialize)]
struct Release {
tag_name: String,
}
if let Ok(release) =
serde_json::from_str::<Release>(&response.text().unwrap_or_default())
{
let trimmed = release.tag_name.trim_start_matches("v");
if trimmed > version {
println!("An updated version of komorebi is available! https://github.com/LGUG2Z/komorebi/releases/v{trimmed}");
}
}
}
}
SubCommand::Stop(arg) => {
if arg.whkd {