Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add feature to allow always disable check update #1628

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions atuin-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ repository = { workspace = true }
[features]
default = ["sync"]
sync = ["urlencoding", "reqwest", "sha2", "hex"]
check-update = []

[dependencies]
atuin-common = { path = "../atuin-common", version = "17.2.1" }
Expand Down
8 changes: 6 additions & 2 deletions atuin-client/src/api_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ use reqwest::{

use atuin_common::{
api::{
AddHistoryRequest, CountResponse, DeleteHistoryRequest, ErrorResponse, IndexResponse,
LoginRequest, LoginResponse, RegisterResponse, StatusResponse, SyncHistoryResponse,
AddHistoryRequest, CountResponse, DeleteHistoryRequest, ErrorResponse, LoginRequest,
LoginResponse, RegisterResponse, StatusResponse, SyncHistoryResponse,
},
record::RecordStatus,
};
use atuin_common::{
api::{ATUIN_CARGO_VERSION, ATUIN_HEADER_VERSION, ATUIN_VERSION},
record::{EncryptedData, HostId, Record, RecordIdx},
};

use semver::Version;
use time::format_description::well_known::Rfc3339;
use time::OffsetDateTime;
Expand Down Expand Up @@ -97,7 +98,10 @@ pub async fn login(address: &str, req: LoginRequest) -> Result<LoginResponse> {
Ok(session)
}

#[cfg(feature = "check-update")]
pub async fn latest_version() -> Result<Version> {
use atuin_common::api::IndexResponse;

let url = "https://api.atuin.sh";
let client = reqwest::Client::new();

Expand Down
10 changes: 9 additions & 1 deletion atuin-client/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ impl Settings {
}
}

#[cfg(feature = "check-update")]
fn needs_update_check(&self) -> Result<bool> {
let last_check = Settings::last_version_check()?;
let diff = OffsetDateTime::now_utc() - last_check;
Expand All @@ -410,6 +411,7 @@ impl Settings {
Ok(diff.whole_hours() >= 1)
}

#[cfg(feature = "check-update")]
async fn latest_version(&self) -> Result<Version> {
// Default to the current version, and if that doesn't parse, a version so high it's unlikely to ever
// suggest upgrading.
Expand Down Expand Up @@ -440,6 +442,7 @@ impl Settings {
}

// Return Some(latest version) if an update is needed. Otherwise, none.
#[cfg(feature = "check-update")]
pub async fn needs_update(&self) -> Option<Version> {
if !self.update_check {
return None;
Expand All @@ -463,6 +466,11 @@ impl Settings {
None
}

#[cfg(not(feature = "check-update"))]
pub async fn needs_update(&self) -> Option<Version> {
None
}

pub fn builder() -> Result<ConfigBuilder<DefaultState>> {
let data_dir = atuin_common::utils::data_dir();
let db_path = data_dir.join("history.db");
Expand All @@ -478,7 +486,7 @@ impl Settings {
.set_default("session_path", session_path.to_str())?
.set_default("dialect", "us")?
.set_default("auto_sync", true)?
.set_default("update_check", true)?
.set_default("update_check", cfg!(feature = "check-update"))?
.set_default("sync_address", "https://api.atuin.sh")?
.set_default("sync_frequency", "10m")?
.set_default("search_mode", "fuzzy")?
Expand Down
3 changes: 2 additions & 1 deletion atuin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ buildflags = ["--release"]
atuin = { path = "/usr/bin/atuin" }

[features]
default = ["client", "sync", "server", "clipboard"]
default = ["client", "sync", "server", "clipboard", "check-update"]
client = ["atuin-client"]
sync = ["atuin-client/sync"]
server = ["atuin-server", "atuin-server-postgres", "tracing-subscriber"]
clipboard = ["cli-clipboard"]
check-update = ["atuin-client/check-update"]

[dependencies]
atuin-server-postgres = { path = "../atuin-server-postgres", version = "17.2.1", optional = true }
Expand Down