Skip to content

Commit cdb47b1

Browse files
author
RAR27
authored
Merge pull request #12 from RAR27/iss11
fixed issue 11
2 parents b4dc4f1 + 7048a09 commit cdb47b1

File tree

2 files changed

+31
-28
lines changed

2 files changed

+31
-28
lines changed

src/lib.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ pub mod time_track;
5050
/// * `times` - vector of time objects representing the times for each wallpaper in order
5151
pub fn wallpaper_current_time(
5252
dir: &str,
53-
dir_count: usize,
5453
program: Arc<Option<String>>,
5554
times: &[Time],
5655
) -> Result<(), Box<dyn Error>> {
@@ -68,7 +67,7 @@ pub fn wallpaper_current_time(
6867
let mut filepath_set: String = String::new();
6968
let mut last_image = String::new();
7069

71-
let mut loop_time = error_checking(times, loop_time, dir_count)?;
70+
let mut loop_time = error_checking(times, loop_time)?;
7271

7372
//this loop is to find where the current time lays, and adjust the wallpaper based on that
7473
for file in dir_iter {
@@ -145,15 +144,15 @@ pub fn wallpaper_listener(
145144
Some(t) => times = t,
146145
}
147146

148-
wallpaper_current_time(&dir, dir_count, Arc::clone(&program), &times)?;
147+
wallpaper_current_time(&dir, Arc::clone(&program), &times)?;
149148

150149
for time in &times {
151150
let time_fmt = format!("{:02}:{:02}", time.hours, time.mins);
152151
sched_addto = sched_addto.and_every(1.day()).at(time_fmt.as_str());
153152
}
154153

155154
let sched_closure = move || {
156-
let result = wallpaper_current_time(&dir, dir_count, Arc::clone(&program), &times);
155+
let result = wallpaper_current_time(&dir, Arc::clone(&program), &times);
157156

158157
match result {
159158
Ok(s) => s,
@@ -234,11 +233,7 @@ pub fn sorted_dir_iter(dir: &str) -> IntoIter {
234233
.into_iter()
235234
}
236235

237-
fn error_checking(
238-
times: &[Time],
239-
loop_time: Option<&Time>,
240-
dir_count: usize,
241-
) -> Result<Time, Box<dyn Error>> {
236+
fn error_checking(times: &[Time], loop_time: Option<&Time>) -> Result<Time, Box<dyn Error>> {
242237
let times_iter_err = times.iter();
243238
let full_time = Time::new(24 * 60);
244239
let start_range = times
@@ -272,9 +267,6 @@ fn error_checking(
272267
None => Err(Errors::ConfigFileError(ConfigFileErrors::Empty)),
273268
Some(time) => Ok(time),
274269
}?;
275-
if 1440 % dir_count != 0 || dir_count == 0 {
276-
return Err(Errors::CountCompatError(dir_count).into());
277-
}
278270
Ok(*loop_time)
279271
}
280272

src/main.rs

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,22 @@ fn main() {
8585
if let Some(auto) = matches.value_of("Auto") {
8686
let dir_count = WalkDir::new(auto).into_iter().count() - 1;
8787

88-
match check_dir_exists(auto) {
89-
Err(e) => eprintln!("{}", e),
90-
Ok(_) => {
91-
let auto = canonicalize(auto).unwrap();
92-
let auto = auto.to_str().unwrap();
93-
if let Err(e) =
94-
wallpaper_listener(String::from(auto), dir_count, Arc::clone(&program), None)
95-
{
96-
eprintln!("{}", e);
88+
if 1440 % dir_count != 0 || dir_count == 0 {
89+
eprintln!("{}", Errors::CountCompatError(dir_count));
90+
} else {
91+
match check_dir_exists(auto) {
92+
Err(e) => eprintln!("{}", e),
93+
Ok(_) => {
94+
let auto = canonicalize(auto).unwrap();
95+
let auto = auto.to_str().unwrap();
96+
if let Err(e) = wallpaper_listener(
97+
String::from(auto),
98+
dir_count,
99+
Arc::clone(&program),
100+
None,
101+
) {
102+
eprintln!("{}", e);
103+
}
97104
}
98105
}
99106
}
@@ -102,13 +109,17 @@ fn main() {
102109
if let Some(s) = matches.value_of("Schedule") {
103110
let dir_count = WalkDir::new(s).into_iter().count() - 1;
104111

105-
match check_dir_exists(s) {
106-
Err(e) => eprintln!("{}", e),
107-
Ok(_) => {
108-
let s = canonicalize(s).unwrap();
109-
let s = s.to_str().unwrap();
110-
if let Err(e) = print_schedule(s, dir_count) {
111-
eprintln!("{}", e);
112+
if 1440 % dir_count != 0 || dir_count == 0 {
113+
eprintln!("{}", Errors::CountCompatError(dir_count));
114+
} else {
115+
match check_dir_exists(s) {
116+
Err(e) => eprintln!("{}", e),
117+
Ok(_) => {
118+
let s = canonicalize(s).unwrap();
119+
let s = s.to_str().unwrap();
120+
if let Err(e) = print_schedule(s, dir_count) {
121+
eprintln!("{}", e);
122+
}
112123
}
113124
}
114125
}

0 commit comments

Comments
 (0)