From bce0faa1c2dc221b0ff77d2cd647bfb2a48ffa7e Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Wed, 8 May 2024 12:09:04 +0100 Subject: feat: add background daemon (#2006) * init daemon crate * wip * minimal functioning daemon, needs cleanup for sure * better errors * add signal cleanup * logging * things * add sync worker * move daemon crate * 30s -> 5mins * make clippy happy * fix stuff maybe? * fmt * trim packages * rate limit fix * more protoc huh * this makes no sense, why linux why * can it install literally just curl * windows in ci is slow, and all the newer things will not work there. disable the daemon feature and it will build * add daemon feature * maybe this * ok wut where is protoc * try setting protoc * hm * try copying protoc * remove optional * add cross config * idk nix * does nix want this? * some random pkg I found does this * uh oh * hack, be gone! * update contributing --- crates/atuin-client/src/settings.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'crates/atuin-client/src/settings.rs') diff --git a/crates/atuin-client/src/settings.rs b/crates/atuin-client/src/settings.rs index 675fb307..ad7f95fc 100644 --- a/crates/atuin-client/src/settings.rs +++ b/crates/atuin-client/src/settings.rs @@ -342,6 +342,19 @@ pub struct Preview { pub strategy: PreviewStrategy, } +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Daemon { + /// Use the daemon to sync + /// If enabled, requires a running daemon with `atuin daemon` + pub enabled: bool, + + /// The daemon will handle sync on an interval. How often to sync, in seconds. + pub sync_frequency: u64, + + /// The path to the unix socket used by the daemon + pub socket_path: String, +} + impl Default for Preview { fn default() -> Self { Self { @@ -350,6 +363,16 @@ impl Default for Preview { } } +impl Default for Daemon { + fn default() -> Self { + Self { + enabled: false, + sync_frequency: 300, + socket_path: "".to_string(), + } + } +} + // The preview height strategy also takes max_preview_height into account. #[derive(Clone, Debug, Deserialize, Copy, PartialEq, Eq, ValueEnum, Serialize)] pub enum PreviewStrategy { @@ -428,6 +451,9 @@ pub struct Settings { #[serde(default)] pub dotfiles: dotfiles::Settings, + #[serde(default)] + pub daemon: Daemon, + // This is automatically loaded when settings is created. Do not set in // config! Keep secrets and settings apart. #[serde(skip)] @@ -622,6 +648,7 @@ impl Settings { let data_dir = atuin_common::utils::data_dir(); let db_path = data_dir.join("history.db"); let record_store_path = data_dir.join("records.db"); + let socket_path = data_dir.join("atuin.sock"); let key_path = data_dir.join("key"); let session_path = data_dir.join("session"); @@ -643,6 +670,7 @@ impl Settings { .set_default("style", "auto")? .set_default("inline_height", 0)? .set_default("show_preview", true)? + .set_default("preview.strategy", "auto")? .set_default("max_preview_height", 4)? .set_default("show_help", true)? .set_default("show_tabs", true)? @@ -675,6 +703,9 @@ impl Settings { .set_default("keymap_cursor", HashMap::::new())? .set_default("smart_sort", false)? .set_default("store_failed", true)? + .set_default("daemon.sync_frequency", 300)? + .set_default("daemon.enabled", false)? + .set_default("daemon.socket_path", socket_path.to_str())? .set_default( "prefers_reduced_motion", std::env::var("NO_MOTION") -- cgit v1.3.1