Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loop interval can be customized #11

Merged
merged 1 commit into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/bingwallpaper/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/bingwallpaper/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use winit::window::WindowBuilder;
/// Bing wallpaper application configuration
#[derive(Serialize, Deserialize)]
pub struct BingWallpaperConfiguration {
pub(crate) loop_interval_second: Option<u64>,
pub(crate) image_dimension_width: u32,
pub(crate) image_dimension_height: u32,
pub(crate) target_filename: String,
Expand All @@ -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(),
Expand Down
7 changes: 5 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();

Expand Down
Loading