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

ddcci-multi-monitor@tim-we: Retry setting brightness and raise timeouts #6434

Merged
merged 1 commit into from
Sep 24, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class Monitor {
this.index = index;
this.name = name;
this.brightness = 50;
this.send_brightness = null;
this.sent_brightness = null;
this.bus = bus;
this.menuLabel = null;
this.menuSlider = null;
Expand All @@ -50,7 +52,7 @@ class Monitor {
const cmd = `ddcutil --bus=${this.bus} getvcp 10`;
Util.spawnCommandLineAsyncIO(cmd, (stdout, stderr, exitCode) => {
// guarantee resolve, even if the following code fails
setTimeout(resolve, 10);
setTimeout(resolve, 500);

if (exitCode == 0) {
// regex from ddcci-monitor-control@andr35
Expand Down Expand Up @@ -82,18 +84,38 @@ class Monitor {

setBrightness(value) {
this.brightness = Math.round(value);
this.send_brightness = this.brightness;
this.updateMenu();
this.#promises = this.#promises.then(() => {
return new Promise((resolve, reject) => {
Util.spawnCommandLineAsync(
`ddcutil --bus=${this.bus} setvcp 10 ${this.brightness}`,
resolve,
reject
);
setTimeout(resolve, 5000);
this.trySetBrightness(resolve, reject, 16);
});
});
}

trySetBrightness(resolve, reject, attempts) {
if (attempts <= 0) {
log(`Failed to change brightness of ${this.name} after multiple attempts.`, "warning");
return resolve();
}
const target_brightness = this.send_brightness;
if (target_brightness !== this.sent_brightness) {
Util.spawnCommandLineAsync(
`ddcutil --bus=${this.bus} setvcp 10 ${target_brightness}`,
() => {
this.sent_brightness = target_brightness;
resolve();
},
() => {
this.trySetBrightness(resolve, reject, attempts - 1);
},
);
} else {
resolve();
}
}

addToMenu(menu) {
// create & add label
const menuLabel = new PopupMenu.PopupMenuItem(this.name, {
Expand Down