diff --git a/aw-sync/README.md b/aw-sync/README.md index 68b92362..76af7e44 100644 --- a/aw-sync/README.md +++ b/aw-sync/README.md @@ -12,15 +12,28 @@ Was originally prototyped as a PR to aw-server: https://github.com/ActivityWatch ## Usage -This will start a daemon which both pulls and pushes events with the sync directory. +This will start a daemon which pulls and pushes events with the sync directory (`~/ActivityWatchSync` by default) every 5 minutes: ```sh -cargo run --bin aw-sync +aw-sync ``` -For more options, see `cargo run --bin aw-sync -- --help`. +For more options, see `aw-sync --help`. ---- +### Setting up sync + +Once you have aw-sync running, you need to set up syncing with the sync directory using your preferred syncing tool. + +The default sync directory is `~/ActivityWatchSync`, but you can change it using the `--sync-dir` option or by setting the `AW_SYNC_DIR` environment variable. + +### Running from source + +If you want to run it from source, in the root of the repository run: + +```sh +cargo run --bin aw-sync +``` +For more options, see `cargo run --bin aw-sync -- --help`. ## FAQ diff --git a/aw-sync/src/dirs.rs b/aw-sync/src/dirs.rs index 878df033..9c7ecf68 100644 --- a/aw-sync/src/dirs.rs +++ b/aw-sync/src/dirs.rs @@ -24,7 +24,10 @@ pub fn get_server_config_path(testing: bool) -> Result { } pub fn get_sync_dir() -> Result> { - // TODO: make this configurable + // if AW_SYNC_DIR is set, use that + if let Ok(dir) = std::env::var("AW_SYNC_DIR") { + return Ok(PathBuf::from(dir)); + } let home_dir = home_dir().ok_or("Unable to read home_dir")?; Ok(home_dir.join("ActivityWatchSync")) } diff --git a/aw-sync/src/main.rs b/aw-sync/src/main.rs index d8a33e1e..46c2bb41 100644 --- a/aw-sync/src/main.rs +++ b/aw-sync/src/main.rs @@ -45,6 +45,11 @@ struct Opts { #[clap(long)] testing: bool, + /// Full path to sync directory. + /// If not specified, use AW_SYNC_DIR env var, or default to ~/ActivityWatchSync + #[clap(long)] + sync_dir: Option, + /// Enable debug logging. #[clap(long)] verbose: bool, @@ -89,11 +94,6 @@ enum Commands { #[clap(long, default_value = "both")] mode: sync::SyncMode, - /// Full path to sync directory. - /// If not specified, exit. - #[clap(long)] - sync_dir: PathBuf, - /// Full path to sync db file /// Useful for syncing buckets from a specific db file in the sync directory. /// Must be a valid absolute path to a file in the sync directory. @@ -121,6 +121,16 @@ fn main() -> Result<(), Box> { aw_server::logging::setup_logger("aw-sync", opts.testing, verbose)?; + // if sync_dir, set env var + if let Some(sync_dir) = opts.sync_dir { + if !sync_dir.is_absolute() { + Err("Sync dir must be absolute")? + } + + info!("Using sync dir: {}", &sync_dir.display()); + std::env::set_var("AW_SYNC_DIR", sync_dir); + } + let port = opts .port .map(|a| Ok(a)) @@ -160,15 +170,9 @@ fn main() -> Result<(), Box> { start_date, buckets, mode, - sync_dir, sync_db, } => { - if !sync_dir.is_absolute() { - Err("Sync dir must be absolute")? - } - - info!("Using sync dir: {}", &sync_dir.display()); - + let sync_dir = dirs::get_sync_dir()?; if let Some(db_path) = &sync_db { info!("Using sync db: {}", &db_path.display());