Skip to content

Commit 4d30335

Browse files
Gr3qwiiznokes
andauthored
fix: Load even if one or more monitor(s) always fail as long as at least one loads (#12)
* Add timeout if at least one monitor loaded but not all * amend comment * Update monitor.rs --------- Co-authored-by: wiiznokes <78230769+wiiznokes@users.noreply.github.com>
1 parent c5e693d commit 4d30335

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/monitor.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ enum State {
3838
pub fn sub() -> impl Stream<Item = Message> {
3939
stream::channel(100, |mut output| async move {
4040
let mut state = State::Waiting;
41+
let mut failed_attempts = 0;
4142

4243
let mut duration = Duration::from_millis(50);
4344

@@ -55,16 +56,19 @@ pub fn sub() -> impl Stream<Item = Message> {
5556

5657
debug!("start enumerate");
5758

59+
let mut some_failed = false;
5860
for mut display in Display::enumerate() {
5961
let brightness = match display.handle.get_vcp_feature(BRIGHTNESS_CODE) {
60-
Ok(v) => v.value(),
62+
Ok(v) => {
63+
v.value()
64+
},
65+
// on my machine, i get this error when starting the session
66+
// can't get_vcp_feature: DDC/CI error: Expected DDC/CI length bit
67+
// This go away after the third attempt
6168
Err(e) => {
62-
// on my machine, i get this error when starting the session
63-
// can't get_vcp_feature: DDC/CI error: Expected DDC/CI length bit
64-
// This go away after the third attempt
6569
error!("can't get_vcp_feature: {e}");
66-
state = State::Waiting;
67-
break;
70+
some_failed = true;
71+
continue;
6872
}
6973
};
7074

@@ -77,7 +81,14 @@ pub fn sub() -> impl Stream<Item = Message> {
7781
displays.insert(display.info.id.clone(), Arc::new(Mutex::new(display)));
7882
}
7983

80-
if let State::Waiting = state {
84+
if some_failed {
85+
failed_attempts += 1;
86+
}
87+
88+
// On some monitors this error is permanent
89+
// So we mark the app as ready if at least one monitor is loaded after 5 attempts
90+
if some_failed && failed_attempts < 5 {
91+
state = State::Waiting;
8192
continue;
8293
}
8394

0 commit comments

Comments
 (0)