diff options
| author | Ellie Huxtable <ellie@elliehuxtable.com> | 2022-10-14 10:59:21 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-14 10:59:21 +0100 |
| commit | f03f6e9ad74d8e1cf1fa33dc2c0c7c5dd7ae5c94 (patch) | |
| tree | aa03f60230b3bc96485806724383bfd6e4cc6b1d /atuin-client/src/api_client.rs | |
| parent | Fix ZSH import print (diff) | |
| download | atuin-f03f6e9ad74d8e1cf1fa33dc2c0c7c5dd7ae5c94.zip | |
Add automatic update checking (#555)
* Add automatic update checking
* Add setting to opt out of update checks
* Document options
* no
* no
* also no
* Make clippy happy
* Update atuin-client/src/settings.rs
Co-authored-by: Conrad Ludgate <conradludgate@gmail.com>
* fix features
Co-authored-by: Conrad Ludgate <conradludgate@gmail.com>
Co-authored-by: Conrad Ludgate <conrad.ludgate@truelayer.com>
Diffstat (limited to '')
| -rw-r--r-- | atuin-client/src/api_client.rs | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/atuin-client/src/api_client.rs b/atuin-client/src/api_client.rs index 5692fea0..b20d9378 100644 --- a/atuin-client/src/api_client.rs +++ b/atuin-client/src/api_client.rs @@ -9,9 +9,10 @@ use reqwest::{ use sodiumoxide::crypto::secretbox; use atuin_common::api::{ - AddHistoryRequest, CountResponse, ErrorResponse, LoginRequest, LoginResponse, RegisterResponse, - SyncHistoryResponse, + AddHistoryRequest, CountResponse, ErrorResponse, IndexResponse, LoginRequest, LoginResponse, + RegisterResponse, SyncHistoryResponse, }; +use semver::Version; use crate::{ encryption::{decode_key, decrypt}, @@ -86,6 +87,27 @@ pub async fn login(address: &str, req: LoginRequest) -> Result<LoginResponse> { Ok(session) } +pub async fn latest_version() -> Result<Version> { + let url = "https://api.atuin.sh"; + let client = reqwest::Client::new(); + + let resp = client + .get(url) + .header(USER_AGENT, APP_USER_AGENT) + .send() + .await?; + + if resp.status() != reqwest::StatusCode::OK { + let error = resp.json::<ErrorResponse>().await?; + bail!("failed to check latest version: {}", error.reason); + } + + let index = resp.json::<IndexResponse>().await?; + let version = Version::parse(index.version.as_str())?; + + Ok(version) +} + impl<'a> Client<'a> { pub fn new(sync_addr: &'a str, session_token: &'a str, key: String) -> Result<Self> { let mut headers = HeaderMap::new(); |
