Skip to content

Commit 2f41cb9

Browse files
committed
feature: add arguments to change intervals
- fix #5
1 parent bee0abf commit 2f41cb9

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "waybar-module-pacman-updates"
33
description = "waybar module for Arch to show system updates available"
4-
version = "0.2.3"
4+
version = "0.2.4"
55
edition = "2021"
66
exclude = ["target", "Cargo.lock", "screenshot.png"]
77
readme = "README.md"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ This small program will give you fast updates with less network usage. After you
3434
"updated": "󰂪"
3535
},
3636
"exec-if": "which waybar-module-pacman-updates",
37-
"exec": "waybar-module-pacman-updates"
37+
"exec": "waybar-module-pacman-updates --interval-seconds 5 --network-interval-seconds 300"
3838
}
3939
```
4040
- add `"custom/updates"` to one of `modules-left`, `modules-center` or `modules-right`

src/main.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::env;
12
use std::io::Error;
23
use std::process::Command;
34
use std::sync::Mutex;
@@ -7,14 +8,29 @@ lazy_static::lazy_static! {
78
static ref DATABASE_SYNC_MUTEX: Mutex<()> = Mutex::new(());
89
}
910
const SLEEP_SECONDS: u16 = 5;
10-
const SLEEP_DURATION: Duration = Duration::from_secs(SLEEP_SECONDS as u64);
1111

1212
fn main() -> Result<(), Error> {
1313
thread::spawn(move || {
1414
sync_database();
1515
});
1616
let mut iter: u16 = 0;
17-
let update_on_iter = 300 / SLEEP_SECONDS;
17+
let args: Vec<String> = env::args().collect();
18+
let mut interval_seconds = SLEEP_SECONDS;
19+
let mut network_interval_seconds = 300;
20+
if args.len() > 1 {
21+
for (i, arg) in args.iter().enumerate() {
22+
if arg == "--interval-seconds" && i + 1 < args.len() {
23+
interval_seconds = args[i + 1].parse().unwrap();
24+
} else if arg == "--network-interval-seconds" && i + 1 < args.len() {
25+
network_interval_seconds = args[i + 1].parse().unwrap();
26+
}
27+
}
28+
}
29+
let sleep_duration: Duration = Duration::from_secs(interval_seconds as u64);
30+
if (interval_seconds == 0) || (network_interval_seconds == 0) {
31+
panic!("interval-seconds and network-interval-seconds must be greater than 0");
32+
}
33+
let update_on_iter = network_interval_seconds / interval_seconds;
1834
loop {
1935
if iter >= update_on_iter {
2036
sync_database();
@@ -28,7 +44,7 @@ fn main() -> Result<(), Error> {
2844
println!("{{\"text\":\"{}\",\"tooltip\":\"System updated\",\"class\": \"updated\",\"alt\":\"updated\"}}", updates);
2945
}
3046
iter += 1;
31-
std::thread::sleep(SLEEP_DURATION);
47+
std::thread::sleep(sleep_duration);
3248
}
3349
}
3450

0 commit comments

Comments
 (0)