2

我正在尝试GLib.Notification从我的应用程序发送一个并传递一个string参数。

动作的名称是action-show-chat-view,它注册在activate ()我的主应用程序类的方法中:

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);
        // ...
    }

}

要发送通知,我执行以下操作:

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

通知已正确发送并按预期显示,但是当单击通知激活操作时,我收到以下错误:

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

我尝试过的其他事情:

  1. 如果我替换GLib.VariantType.STRING为, 并在通知上作为目标值null传递(并删除),我会看到“哔哔”控制台输出,因此我知道至少所有内容都已正确连接并调用正确的方法。nullparameter.get_string ()

  2. 我也尝试过使用app.前缀注册操作,但是我在文档中的某处读到,当通过Application.add_action ()this 添加时是隐式的。

  3. 我尝试使用类型字符串创建一个操作组,s但得到了同样的错误。

  4. 我尝试过使用其他Variant类型STRING

  5. 我尝试在发送通知之前添加以下检查以查看类型是否对齐,他们做到了:app.get_action_parameter_type ("action-show-chat-view").equal (target.get_type ()). 如果我使用app.前缀,这会失败,但是我认为这是预期的行为,因为它是在没有前缀的情况下注册的?

  6. 我查看了 Flatpak 沙箱权限(这部分对我来说是全新的),但由于通知发送成功,我认为这不是问题。

4

1 回答 1

0

这似乎是一个错误xdg-desktop-portal-gtkhttps ://github.com/flatpak/xdg-desktop-portal-gtk/pull/359 。尽管已修复,但尚未包含在版本中。

关于使用基本/通知记录的问题的一些相关讨论:https ://github.com/elementary/notifications/issues/153

于 2021-12-03T22:35:39.267 回答