From 579d3084a00ab71e83339d801cc8516468d6f10b Mon Sep 17 00:00:00 2001 From: Thibault Meyer Date: Sun, 19 May 2024 16:11:50 +0200 Subject: [PATCH] Loop interval can be customized Signed-off-by: Thibault Meyer --- README.md | 4 +++- src/bingwallpaper/arguments.rs | 2 +- src/bingwallpaper/configuration.rs | 2 ++ src/main.rs | 7 +++++-- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7097be4..a6b27f4 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,8 @@ Options: -o, --download-only Download wallpaper, but dont try to change it automatically -l, --loop - Keep application running. Looking for new wallpaper every hours + Keep application running. Looking for new wallpaper every 900 seconds (15 minutes). + You can override value with `loop_interval_second` in your configuration file. -w, --nowindow Don't display console when not run from a CLI (Windows Only) -v, --version @@ -85,6 +86,7 @@ background. ## Configuration file +* `loop_interval_second` The interval in seconds between two wallpaper update attempts. Default value is `900` * `image_dimension_width` The "width" dimension of the wallpaper * `image_dimension_height` The "height" dimension of the wallpaper * `target_filename` The location where is stored the wallpaper diff --git a/src/bingwallpaper/arguments.rs b/src/bingwallpaper/arguments.rs index 544934a..b0d49d3 100644 --- a/src/bingwallpaper/arguments.rs +++ b/src/bingwallpaper/arguments.rs @@ -17,7 +17,7 @@ pub struct BingWallpaperArguments { pub(crate) download_only: bool, /// If `true`, the application must continue to looking for new version of the image to use as wallpaper. - #[clap(long = "loop", short = 'l', help = "Keep application running. Looking for new wallpaper every hours")] + #[clap(long = "loop", short = 'l', help = "Keep application running. Looking for new wallpaper every 900 seconds (15 minutes)\nYou can override value with `loop_interval_second` in the configuration file")] pub(crate) must_loop: bool, /// If `true`, the application will don't display console diff --git a/src/bingwallpaper/configuration.rs b/src/bingwallpaper/configuration.rs index e8906b2..ed1e5de 100644 --- a/src/bingwallpaper/configuration.rs +++ b/src/bingwallpaper/configuration.rs @@ -9,6 +9,7 @@ use winit::window::WindowBuilder; /// Bing wallpaper application configuration #[derive(Serialize, Deserialize)] pub struct BingWallpaperConfiguration { + pub(crate) loop_interval_second: Option, pub(crate) image_dimension_width: u32, pub(crate) image_dimension_height: u32, pub(crate) target_filename: String, @@ -21,6 +22,7 @@ pub struct BingWallpaperConfiguration { impl Default for BingWallpaperConfiguration { fn default() -> Self { Self { + loop_interval_second: 900.into(), image_dimension_height: 1080, image_dimension_width: 1920, target_filename: "/tmp/bingwallpaper.png".into(), diff --git a/src/main.rs b/src/main.rs index 0e472eb..7feecf5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,8 +48,11 @@ fn main() { process::exit(0); } - // Creates BingWallpaperChanger instance + // Load configuration file let config = BingWallpaperConfiguration::load(args.config_file); + let sleep_duration_sec = config.loop_interval_second; + + // Creates BingWallpaperChanger instance let bing_wallpaper_changer = BingWallpaperChanger::new(config); // Run @@ -64,7 +67,7 @@ fn main() { println!("Can't change wallpaper: {:?}", error); } - sleep(Duration::from_secs(900)); + sleep(Duration::from_secs(sleep_duration_sec.unwrap_or(900))); } }).unwrap();