aboutsummaryrefslogtreecommitdiffstats
path: root/atuin-client/src/api_client.rs
diff options
context:
space:
mode:
authorEllie Huxtable <ellie@elliehuxtable.com>2022-10-14 10:59:21 +0100
committerGitHub <noreply@github.com>2022-10-14 10:59:21 +0100
commitf03f6e9ad74d8e1cf1fa33dc2c0c7c5dd7ae5c94 (patch)
treeaa03f60230b3bc96485806724383bfd6e4cc6b1d /atuin-client/src/api_client.rs
parentFix ZSH import print (diff)
downloadatuin-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 'atuin-client/src/api_client.rs')
-rw-r--r--atuin-client/src/api_client.rs26
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();