Skip to content

Commit 1b56e03

Browse files
authored
fix: added sync dir config via global --sync-dir cli param and AW_SYNC_DIR env var (#457)
* docs(sync): improved usage instructions, updated docs to mention sync dir config options * docs: added global `--sync-dir` cli param and `AW_SYNC_DIR` env var
1 parent 41b030a commit 1b56e03

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed

aw-sync/README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,28 @@ Was originally prototyped as a PR to aw-server: https://github.com/ActivityWatch
1212

1313
## Usage
1414

15-
This will start a daemon which both pulls and pushes events with the sync directory.
15+
This will start a daemon which pulls and pushes events with the sync directory (`~/ActivityWatchSync` by default) every 5 minutes:
1616

1717
```sh
18-
cargo run --bin aw-sync
18+
aw-sync
1919
```
2020

21-
For more options, see `cargo run --bin aw-sync -- --help`.
21+
For more options, see `aw-sync --help`.
2222

23-
---
23+
### Setting up sync
24+
25+
Once you have aw-sync running, you need to set up syncing with the sync directory using your preferred syncing tool.
26+
27+
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.
28+
29+
### Running from source
30+
31+
If you want to run it from source, in the root of the repository run:
32+
33+
```sh
34+
cargo run --bin aw-sync
35+
```
36+
For more options, see `cargo run --bin aw-sync -- --help`.
2437

2538
## FAQ
2639

aw-sync/src/dirs.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ pub fn get_server_config_path(testing: bool) -> Result<PathBuf, ()> {
2424
}
2525

2626
pub fn get_sync_dir() -> Result<PathBuf, Box<dyn Error>> {
27-
// TODO: make this configurable
27+
// if AW_SYNC_DIR is set, use that
28+
if let Ok(dir) = std::env::var("AW_SYNC_DIR") {
29+
return Ok(PathBuf::from(dir));
30+
}
2831
let home_dir = home_dir().ok_or("Unable to read home_dir")?;
2932
Ok(home_dir.join("ActivityWatchSync"))
3033
}

aw-sync/src/main.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ struct Opts {
4545
#[clap(long)]
4646
testing: bool,
4747

48+
/// Full path to sync directory.
49+
/// If not specified, use AW_SYNC_DIR env var, or default to ~/ActivityWatchSync
50+
#[clap(long)]
51+
sync_dir: Option<PathBuf>,
52+
4853
/// Enable debug logging.
4954
#[clap(long)]
5055
verbose: bool,
@@ -89,11 +94,6 @@ enum Commands {
8994
#[clap(long, default_value = "both")]
9095
mode: sync::SyncMode,
9196

92-
/// Full path to sync directory.
93-
/// If not specified, exit.
94-
#[clap(long)]
95-
sync_dir: PathBuf,
96-
9797
/// Full path to sync db file
9898
/// Useful for syncing buckets from a specific db file in the sync directory.
9999
/// Must be a valid absolute path to a file in the sync directory.
@@ -121,6 +121,16 @@ fn main() -> Result<(), Box<dyn Error>> {
121121

122122
aw_server::logging::setup_logger("aw-sync", opts.testing, verbose)?;
123123

124+
// if sync_dir, set env var
125+
if let Some(sync_dir) = opts.sync_dir {
126+
if !sync_dir.is_absolute() {
127+
Err("Sync dir must be absolute")?
128+
}
129+
130+
info!("Using sync dir: {}", &sync_dir.display());
131+
std::env::set_var("AW_SYNC_DIR", sync_dir);
132+
}
133+
124134
let port = opts
125135
.port
126136
.map(|a| Ok(a))
@@ -160,15 +170,9 @@ fn main() -> Result<(), Box<dyn Error>> {
160170
start_date,
161171
buckets,
162172
mode,
163-
sync_dir,
164173
sync_db,
165174
} => {
166-
if !sync_dir.is_absolute() {
167-
Err("Sync dir must be absolute")?
168-
}
169-
170-
info!("Using sync dir: {}", &sync_dir.display());
171-
175+
let sync_dir = dirs::get_sync_dir()?;
172176
if let Some(db_path) = &sync_db {
173177
info!("Using sync db: {}", &db_path.display());
174178

0 commit comments

Comments
 (0)