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

writeCollection: Wait until previous invocation finished #157

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions [email protected]/convenienceExt.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ export function brightnessLog(settings, str) {
}

export function spawnWithCallback(settings, argv, callback) {
brightnessLog(settings, `Calling: ${argv.join(' ')}`);
const proc = Gio.Subprocess.new(argv, Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_SILENCE);

proc.communicate_utf8_async(null, null, (proc, res) => {
try {
const [, stdout, stderr] = proc.communicate_utf8_finish(res);
brightnessLog(settings, "subprocess ended");
if (proc.get_successful()) {
callback(stdout);
} else {
Expand All @@ -27,6 +29,9 @@ export function spawnWithCallback(settings, argv, callback) {
callback(stderr);
else if (stdout)
callback(stdout);
else {
callback("");
}
}
} catch (e) {
brightnessLog(settings, e.message);
Expand Down
82 changes: 31 additions & 51 deletions [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,6 @@ export default class DDCUtilBrightnessControlExtension extends Extension {
if (_reloadExtensionTimer)
clearTimeout(_reloadExtensionTimer);

Object.keys(writeCollection).forEach(bus => {
if (writeCollection[bus].interval !== null) {
clearInterval(writeCollection[bus].interval);
}
});
if (monitorChangeTimeout !== null) {
clearTimeout(monitorChangeTimeout)
monitorChangeTimeout = null;
Expand All @@ -154,45 +149,38 @@ export default class DDCUtilBrightnessControlExtension extends Extension {
}
}

ddcWriteInQueue(displayBus) {
if (writeCollection[displayBus].interval == null) {
writeCollection[displayBus].interval = setInterval(() => {
if (writeCollection[displayBus].countdown === 0) {
brightnessLog(this.settings, `Write in queue countdown over for ${displayBus}`);
writeCollection[displayBus].writer();
clearInterval(writeCollection[displayBus].interval);
writeCollection[displayBus].interval = null;
const writeCollectorWaitMs = parseInt(this.settings.get_double('ddcutil-queue-ms'));
writeCollection[displayBus].countdown = writeCollectorWaitMs;
} else {
writeCollection[displayBus].countdown = writeCollection[displayBus].countdown - 1;
}
}, 1);
ddcWriteCollector(displayBus, writer) {
const kickoffNext = (reason) => {
brightnessLog(this.settings, `kickoffNext called ${reason}`);
writeCollection[displayBus].current = writeCollection[displayBus].next;
writeCollection[displayBus].next = null;
if (writeCollection[displayBus].current) {
writeCollection[displayBus].current(() => {
if (writeCollection === null) {
// Must be disabling. Do nothing.
return;
}
kickoffNext("on chain");
});
} else {
brightnessLog(this.settings, "writer done, nothing next");
}
}
}

ddcWriteCollector(displayBus, writer) {
if (displayBus in writeCollection) {
/* by setting writer to latest one,
when waiting is over latest writer will run */
writeCollection[displayBus].writer = writer;
brightnessLog(this.settings, `Write collector update, current countdown is ${writeCollection[displayBus].countdown} for ${displayBus}`);
/* countdown is over, meaning update process for this display can be added to the queue */
const writeCollectorWaitMs = parseInt(this.settings.get_double('ddcutil-queue-ms'));
if (writeCollection[displayBus].countdown === writeCollectorWaitMs) {
brightnessLog(this.settings, 'Write collector update, trigger queue again');
this.ddcWriteInQueue(displayBus);
writeCollection[displayBus].next = writer;
if (writeCollection[displayBus].current) {
brightnessLog(this.settings, "Saving writer for when ready");
} else {
kickoffNext("on start");
}
} else {
brightnessLog(this.settings, `Write collector defining new display ${displayBus} and adding it to queue`);
/* display query is not defined yet */
writeCollection[displayBus] = {
countdown: 0,
interval: null,
writer,
};
this.ddcWriteInQueue(displayBus);
return;
}
writeCollection[displayBus] = {
next: writer,
current: null
};
kickoffNext("on start");
}

setBrightness(display, newValue) {
Expand All @@ -208,9 +196,10 @@ export default class DDCUtilBrightnessControlExtension extends Extension {
const ddcutilPath = this.settings.get_string('ddcutil-binary-path');
const ddcutilAdditionalArgs = this.settings.get_string('ddcutil-additional-args');
const sleepMultiplier = this.settings.get_double('ddcutil-sleep-multiplier') / 40;
const writer = () => {
brightnessLog(this.settings, `async ${ddcutilPath} setvcp ${display.vcp} ${newBrightness} --bus ${display.bus} --sleep-multiplier ${sleepMultiplier} ${ddcutilAdditionalArgs}`);
GLib.spawn_command_line_async(`${ddcutilPath} setvcp ${display.vcp} ${newBrightness} --bus ${display.bus} --sleep-multiplier ${sleepMultiplier} ${ddcutilAdditionalArgs}`);
const writer = (ondone) => {
const cmd = `${ddcutilPath} setvcp ${display.vcp} ${newBrightness} --bus ${display.bus} --sleep-multiplier ${sleepMultiplier} ${ddcutilAdditionalArgs}`.split(" ").filter(x => x !== "");
brightnessLog(this.settings, `async ${cmd.join(" ")}`);
spawnWithCallback(this.settings, cmd, (result) => {if (ondone) {ondone();}});
};
brightnessLog(this.settings, `display ${display.name}, current: ${display.current} => ${newValue / 100}, new brightness: ${newBrightness}, new value: ${newValue}`);
display.current = newValue / 100;
Expand Down Expand Up @@ -699,15 +688,6 @@ export default class DDCUtilBrightnessControlExtension extends Extension {
this.reloadMenuWidgets();
if (this.settings.get_boolean('verbose-debugging'))
brightnessLog(this.settings, JSON.stringify(this.settingsToJSObject()));

const writeCollectorWaitMs = parseInt(this.settings.get_double('ddcutil-queue-ms'));
Object.keys(writeCollection).forEach(displayBus => {
writeCollection[displayBus].countdown = writeCollectorWaitMs;
if (writeCollection[displayBus].interval !== null)
clearInterval(writeCollection[displayBus].interval);

writeCollection[displayBus].interval = null;
});
}

onMonitorChange() {
Expand Down
12 changes: 6 additions & 6 deletions [email protected]/po/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-10-21 23:16+0300\n"
"POT-Creation-Date: 2024-11-10 13:27-0800\n"
"PO-Revision-Date: 2022-02-13 09:53+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
Expand Down Expand Up @@ -168,20 +168,20 @@ msgstr ""
msgid "Initializing"
msgstr "Initialisiere"

#: [email protected]/extension.js:301
#: [email protected]/extension.js:290
msgid "Settings"
msgstr "Einstellungen"

#: [email protected]/extension.js:310
#: [email protected]/extension.js:299
msgid "Reload"
msgstr "Neu laden"

#: [email protected]/extension.js:327
#: [email protected]/extension.js:331
#: [email protected]/extension.js:316
#: [email protected]/extension.js:320
msgid "All"
msgstr "Alle"

#: [email protected]/extension.js:600
#: [email protected]/extension.js:589
msgid "Internal"
msgstr ""

Expand Down
12 changes: 6 additions & 6 deletions [email protected]/po/display-brightness-ddcutil.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-10-22 00:14+0300\n"
"POT-Creation-Date: 2024-11-10 13:31-0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -160,20 +160,20 @@ msgstr ""
msgid "Initializing"
msgstr ""

#: [email protected]/extension.js:301
#: [email protected]/extension.js:290
msgid "Settings"
msgstr ""

#: [email protected]/extension.js:310
#: [email protected]/extension.js:299
msgid "Reload"
msgstr ""

#: [email protected]/extension.js:327
#: [email protected]/extension.js:331
#: [email protected]/extension.js:316
#: [email protected]/extension.js:320
msgid "All"
msgstr ""

#: [email protected]/extension.js:600
#: [email protected]/extension.js:589
msgid "Internal"
msgstr ""

Expand Down
12 changes: 6 additions & 6 deletions [email protected]/po/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: gnome-display-brightness-ddcutil\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-10-21 23:16+0300\n"
"POT-Creation-Date: 2024-11-10 13:27-0800\n"
"PO-Revision-Date: 2023-11-26 12:05+0100\n"
"Last-Translator: Óscar Fernández Díaz <[email protected]>\n"
"Language-Team: Spanish\n"
Expand Down Expand Up @@ -163,20 +163,20 @@ msgstr "Pulse Esc para cancelar el atajo del teclado."
msgid "Initializing"
msgstr "Inicializando"

#: [email protected]/extension.js:301
#: [email protected]/extension.js:290
msgid "Settings"
msgstr "Configuración"

#: [email protected]/extension.js:310
#: [email protected]/extension.js:299
msgid "Reload"
msgstr "Recargar"

#: [email protected]/extension.js:327
#: [email protected]/extension.js:331
#: [email protected]/extension.js:316
#: [email protected]/extension.js:320
msgid "All"
msgstr "Todos"

#: [email protected]/extension.js:600
#: [email protected]/extension.js:589
msgid "Internal"
msgstr ""

Expand Down