Skip to content
Merged
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
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
Loading