elementary / notifications

Gtk Notifications Server
https://elementary.io
GNU General Public License v3.0
38 stars 6 forks source link

Clicking a notification does not pass target parameters to action #153

Closed avojak closed 1 year ago

avojak commented 2 years ago

Prerequisites

Describe the bug

When clicking on a notification that triggers an action with a parameter, the parameter does not seem to be passed.

In a simple setup, I use a single string parameter. To register the action:

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 action:

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 result is an error in the logs, and the action is not triggered:

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

If I remove the VariantType and pass null as the target value, the action is triggered as expected.

To Reproduce

Steps to reproduce the behavior:

  1. See above

Expected behavior

The parameter value(s) is passed to the action.

Screenshots or screen recordings

N/A

Logs

Error received when clicking the notification:

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

Platform Information

image

Additional context

I asked about this on the community Slack, and someone made the following comment:

You are using flatpak right, that was a bug with the portal not passing the target to the action when activating, that was already fixed in the gtk portal

However I can't seem to find any other information about the bug (maybe it's an upstream issue)?

jeremypw commented 2 years ago

Just to clarify, this relates to NotificationEntries that appear in the indicator popover, doesn't it? I noticed this recently. Clicking on the initial GLib.Notification before it disappears does seem to work. It seems to be related to the NotificationEntry activating an action called "default" with no target when clicked. rather than the actual action and target that was set as default in the original GLib.Notification. This does not seem to be only Flatpaks that are affected.

avojak commented 2 years ago

For me it's affecting both the initial notification "box", as well as the entries in the indicator popover.

Marukesu commented 2 years ago

It seems to be related to the NotificationEntry activating an action called "default" with no target when clicked. rather than the actual action and target that was set as default in the original GLib.Notification.

That's expected, the sever don't receive the action that was set as default, but "default". when the server emit action_invoked ("default") GLib or Portal calls the right action, with the target.

For me, this issue is the same of #128, the portal was parsing the actions wrongly, and ignoring all targets. this was fixed on flatpak/xdg-desktop-portal-gtk#359.

avojak commented 2 years ago

Thanks for pointing out those two other issues! This does sound like #128, so I bet this is a duplicate.

It looks like the fix on xdg-desktop-portal-gtk hasn't yet been included in a release. When it is, how does that upstream change make its way down to elementary? That's all a bit fuzzy to me!

Marukesu commented 2 years ago

It looks like the fix on xdg-desktop-portal-gtk hasn't yet been included in a release. When it is, how does that upstream change make its way down to elementary? That's all a bit fuzzy to me!

I believe it would require an backport for odin

Marukesu commented 2 years ago

@jeremypw I tried to see why the indicator cannot activate the default action, and looks like it isn't calling org.Freedesktop.Notification.ActionInvoked at all, so that's definitely an different issue.

jeremypw commented 2 years ago

@Marukesu So that would be a fix for https://github.com/elementary/wingpanel-indicator-notifications/issues/216?

Marukesu commented 2 years ago

Yes

Marukesu commented 2 years ago

So, i managed to make the indicator emit the ActionInvoked signal, however there's another problem that is both GLib and Portal only listen to signals emitted by the address of the org.freedesktop.Notifications, what the indicator isn't. right now i can think in two possibilities:

Marukesu commented 1 year ago

Closing as this was fixed in the portal. the indicator side of this is open in elementary/wingpanel-indicator-notifications#216.