Search code examples
gtkglibvalaflatpakelementary-os

GLib.Notification fails to activate action with a non-null VariantType


I'm trying to send a GLib.Notification from my application and pass a string parameter.

The name of the action is action-show-chat-view, and it is registered in the activate () method of my main application class:

public class MyApplication : Gtk.Application {

    protected override void activate () {
        // ...
        var show_chat_view_action = new GLib.SimpleAction ("action-show-chat-view", GLib.VariantType.STRING);
        show_chat_view_action.activate.connect ((parameter) => {
            debug ("beep boop");
            debug (parameter.get_string ());
        });
        add_action (show_chat_view_action);
        // ...
    }

}

To send the notification, I do the following:

var notification = new GLib.Notification ("Hello, world");
var target = new GLib.Variant.string ("foobar");
notification.set_default_action_and_target_value ("app.action-show-chat-view", target);
app.send_notification (null, notification); // app is the instance of the MyApplication class above

The notification is sent correctly and appears as expected, however when the notification is clicked to activate the action, I receive the following error:

GLib-GIO-CRITICAL **: 13:04:37.169: g_simple_action_activate: assertion 'simple->parameter_type == NULL ? parameter == NULL : (parameter != NULL && g_variant_is_of_type (parameter, simple->parameter_type))' failed

Other things that I've tried:

  1. If I replace GLib.VariantType.STRING with null, and pass null as the target value on the notification (and removing parameter.get_string ()), I see the "beep boop" console output so I know that everything is at least wired up correctly and calling the right methods.

  2. I have also tried registering the action with the app. prefix as well, however I read somewhere in documentation that when added via the Application.add_action () this is implicit.

  3. I tried creating an action group with the type string s but got the same error.

  4. I've tried using other Variant types besides STRING

  5. I tried adding the following check before sending the notification to see if the types align, and they did: app.get_action_parameter_type ("action-show-chat-view").equal (target.get_type ()). This failed if I used the app. prefix, however I think that's expected behavior since it's registered without the prefix?

  6. I looked into Flatpak sandbox permissions (this part is all new to me), but since the notification is sent successfully, I don't think that's the problem.


Solution

  • This appears to have been a bug with xdg-desktop-portal-gtk: https://github.com/flatpak/xdg-desktop-portal-gtk/pull/359. Despite being fixed, it has not yet been included in a release.

    Some related discussion on an issue logged with elementary/notifications: https://github.com/elementary/notifications/issues/153