Skip to content

Commit

Permalink
fix: Load even if one or more monitor(s) always fail as long as at le…
Browse files Browse the repository at this point in the history
…ast 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>
  • Loading branch information
Gr3q and wiiznokes authored Feb 19, 2025
1 parent c5e693d commit 4d30335
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum State {
pub fn sub() -> impl Stream<Item = Message> {
stream::channel(100, |mut output| async move {
let mut state = State::Waiting;
let mut failed_attempts = 0;

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

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

debug!("start enumerate");

let mut some_failed = false;
for mut display in Display::enumerate() {
let brightness = match display.handle.get_vcp_feature(BRIGHTNESS_CODE) {
Ok(v) => v.value(),
Ok(v) => {
v.value()
},
// on my machine, i get this error when starting the session
// can't get_vcp_feature: DDC/CI error: Expected DDC/CI length bit
// This go away after the third attempt
Err(e) => {
// on my machine, i get this error when starting the session
// can't get_vcp_feature: DDC/CI error: Expected DDC/CI length bit
// This go away after the third attempt
error!("can't get_vcp_feature: {e}");
state = State::Waiting;
break;
some_failed = true;
continue;
}
};

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

if let State::Waiting = state {
if some_failed {
failed_attempts += 1;
}

// On some monitors this error is permanent
// So we mark the app as ready if at least one monitor is loaded after 5 attempts
if some_failed && failed_attempts < 5 {
state = State::Waiting;
continue;
}

Expand Down

0 comments on commit 4d30335

Please sign in to comment.