mirror of
https://github.com/atuinsh/atuin.git
synced 2024-12-26 17:09:14 +01:00
chore: add feature to allow always disable check update (#1628)
* chore: add feature to allow always disable check update In the packaging rules of some distributions, the software's self-update check needs to be permanently turned off This commit will make it easier for these users to * fix: formatting --------- Co-authored-by: Ellie Huxtable <ellie@elliehuxtable.com>
This commit is contained in:
parent
400e1ba23d
commit
d21de3cd25
@ -15,6 +15,7 @@ repository = { workspace = true }
|
|||||||
[features]
|
[features]
|
||||||
default = ["sync"]
|
default = ["sync"]
|
||||||
sync = ["urlencoding", "reqwest", "sha2", "hex"]
|
sync = ["urlencoding", "reqwest", "sha2", "hex"]
|
||||||
|
check-update = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
atuin-common = { path = "../atuin-common", version = "17.2.1" }
|
atuin-common = { path = "../atuin-common", version = "17.2.1" }
|
||||||
|
@ -10,8 +10,8 @@ use reqwest::{
|
|||||||
|
|
||||||
use atuin_common::{
|
use atuin_common::{
|
||||||
api::{
|
api::{
|
||||||
AddHistoryRequest, CountResponse, DeleteHistoryRequest, ErrorResponse, IndexResponse,
|
AddHistoryRequest, CountResponse, DeleteHistoryRequest, ErrorResponse, LoginRequest,
|
||||||
LoginRequest, LoginResponse, RegisterResponse, StatusResponse, SyncHistoryResponse,
|
LoginResponse, RegisterResponse, StatusResponse, SyncHistoryResponse,
|
||||||
},
|
},
|
||||||
record::RecordStatus,
|
record::RecordStatus,
|
||||||
};
|
};
|
||||||
@ -19,6 +19,7 @@ use atuin_common::{
|
|||||||
api::{ATUIN_CARGO_VERSION, ATUIN_HEADER_VERSION, ATUIN_VERSION},
|
api::{ATUIN_CARGO_VERSION, ATUIN_HEADER_VERSION, ATUIN_VERSION},
|
||||||
record::{EncryptedData, HostId, Record, RecordIdx},
|
record::{EncryptedData, HostId, Record, RecordIdx},
|
||||||
};
|
};
|
||||||
|
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
use time::format_description::well_known::Rfc3339;
|
use time::format_description::well_known::Rfc3339;
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
@ -97,7 +98,10 @@ pub async fn login(address: &str, req: LoginRequest) -> Result<LoginResponse> {
|
|||||||
Ok(session)
|
Ok(session)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "check-update")]
|
||||||
pub async fn latest_version() -> Result<Version> {
|
pub async fn latest_version() -> Result<Version> {
|
||||||
|
use atuin_common::api::IndexResponse;
|
||||||
|
|
||||||
let url = "https://api.atuin.sh";
|
let url = "https://api.atuin.sh";
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
|
|
||||||
|
@ -402,6 +402,7 @@ impl Settings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "check-update")]
|
||||||
fn needs_update_check(&self) -> Result<bool> {
|
fn needs_update_check(&self) -> Result<bool> {
|
||||||
let last_check = Settings::last_version_check()?;
|
let last_check = Settings::last_version_check()?;
|
||||||
let diff = OffsetDateTime::now_utc() - last_check;
|
let diff = OffsetDateTime::now_utc() - last_check;
|
||||||
@ -410,6 +411,7 @@ impl Settings {
|
|||||||
Ok(diff.whole_hours() >= 1)
|
Ok(diff.whole_hours() >= 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "check-update")]
|
||||||
async fn latest_version(&self) -> Result<Version> {
|
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
|
// Default to the current version, and if that doesn't parse, a version so high it's unlikely to ever
|
||||||
// suggest upgrading.
|
// suggest upgrading.
|
||||||
@ -440,6 +442,7 @@ impl Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return Some(latest version) if an update is needed. Otherwise, none.
|
// Return Some(latest version) if an update is needed. Otherwise, none.
|
||||||
|
#[cfg(feature = "check-update")]
|
||||||
pub async fn needs_update(&self) -> Option<Version> {
|
pub async fn needs_update(&self) -> Option<Version> {
|
||||||
if !self.update_check {
|
if !self.update_check {
|
||||||
return None;
|
return None;
|
||||||
@ -463,6 +466,11 @@ impl Settings {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "check-update"))]
|
||||||
|
pub async fn needs_update(&self) -> Option<Version> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
pub fn builder() -> Result<ConfigBuilder<DefaultState>> {
|
pub fn builder() -> Result<ConfigBuilder<DefaultState>> {
|
||||||
let data_dir = atuin_common::utils::data_dir();
|
let data_dir = atuin_common::utils::data_dir();
|
||||||
let db_path = data_dir.join("history.db");
|
let db_path = data_dir.join("history.db");
|
||||||
@ -478,7 +486,7 @@ impl Settings {
|
|||||||
.set_default("session_path", session_path.to_str())?
|
.set_default("session_path", session_path.to_str())?
|
||||||
.set_default("dialect", "us")?
|
.set_default("dialect", "us")?
|
||||||
.set_default("auto_sync", true)?
|
.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_address", "https://api.atuin.sh")?
|
||||||
.set_default("sync_frequency", "10m")?
|
.set_default("sync_frequency", "10m")?
|
||||||
.set_default("search_mode", "fuzzy")?
|
.set_default("search_mode", "fuzzy")?
|
||||||
|
@ -33,11 +33,12 @@ buildflags = ["--release"]
|
|||||||
atuin = { path = "/usr/bin/atuin" }
|
atuin = { path = "/usr/bin/atuin" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["client", "sync", "server", "clipboard"]
|
default = ["client", "sync", "server", "clipboard", "check-update"]
|
||||||
client = ["atuin-client"]
|
client = ["atuin-client"]
|
||||||
sync = ["atuin-client/sync"]
|
sync = ["atuin-client/sync"]
|
||||||
server = ["atuin-server", "atuin-server-postgres", "tracing-subscriber"]
|
server = ["atuin-server", "atuin-server-postgres", "tracing-subscriber"]
|
||||||
clipboard = ["cli-clipboard"]
|
clipboard = ["cli-clipboard"]
|
||||||
|
check-update = ["atuin-client/check-update"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
atuin-server-postgres = { path = "../atuin-server-postgres", version = "17.2.1", optional = true }
|
atuin-server-postgres = { path = "../atuin-server-postgres", version = "17.2.1", optional = true }
|
||||||
|
Loading…
Reference in New Issue
Block a user