Skip to content

scripting: Fix dbus calls with numeric types

Kristen McWilliam requested to merge work/merritt/call-dbus-types-fix into master

DBus calls with numeric types other than int and double were not working(eg. uint16, int16, etc).

This was because the JavaScript types were converted by QJSValue::toVariant(), which only supports int and double.

This change adds support for the other numeric types which JavaScript does not support by introspecting the type signature of the DBus method and converting the JavaScript value to the appropriate QVariant type.

This is important because if one tries to call a DBus method with an incorrect type signature, the call will fail.

BUG: 486024


Test plan

  1. Monitor kwin script output:
journalctl -b -f | grep -i "kwin"
  1. Open the KWin Scripting Console

  2. Call the Inhibit method on org.freedesktop.Notifications, which works as expected:

callDBus(
    "org.freedesktop.Notifications",
    "/org/freedesktop/Notifications",
    "org.freedesktop.Notifications",
    "Inhibit",
    "",
    "",
    {},
    function (reply) {
        console.info("Callback. Reply: " + reply);
    }
);
  1. Check the output of the journal, which should show the message "Callback. Reply: $number" - I'll assume it was 1 for the sake of this example. Do Not Disturb should have been enabled.

  2. Call the method UnInhibit on org.freedesktop.Notifications, which expects a uint32 as argument:

callDBus(
    "org.freedesktop.Notifications",
    "/org/freedesktop/Notifications",
    "org.freedesktop.Notifications",
    "UnInhibit",
    1,
    function () {
        console.info("UnInhibit callback.");
    }
);

Step 5 fails on master, succeeds on the fix branch.

Edited by Kristen McWilliam

Merge request reports

Loading