为什么 GTK3 Application::send_notification() 的 'id' 参数似乎没有做任何事情?

Why doesn't the `id` parameter of GTK3 Application::send_notification() seem to do anything?

提问人:b0fh 提问时间:11/9/2023 更新时间:11/9/2023 访问量:11

问:

我正在尝试调试一个使用 GTK3 绑定发送和更新桌面通知的 python 应用程序。但它似乎无法更新通知;相反,它总是创建一个新的。

Application.send_notification 的 GTK 文档说:

id可以是唯一标识应用程序事件的任何字符串。它不需要采用任何特殊格式。例如,“new-message”可能适用于有关新消息的通知。

如果之前的通知是使用相同的 ID 发送的,则该通知将替换为通知,并再次显示为新通知。这甚至适用于从应用程序的先前执行发送的通知,只要 id 是相同的字符串。

当我尝试这个最小的 python 示例时:

#!/usr/bin/python3

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gio, Gtk

n = Gio.Notification.new("one")

app = Gtk.Application()
app.set_application_id("org.example.Notifier")
app.register()
app.send_notification("my-id", n)
n.set_title("two")
app.send_notification("my-id", n)

我看到它确实创建了新通知而不是更新。

通知规范说明,发送通知是通过对 on 的 DBus RPC 调用来完成的。RPC 调用返回一个唯一值,稍后可以提供给另一个调用以更新通知。Notifyorg.freedesktop.Notificationuint32Notify

通过监视活动,我可以确认更新机制是否与提供的命令(允许手动指定)一起工作,并使用两个不同的通知守护程序(和)。我还可以看到,在我的 python 示例中,无论参数是什么,它始终为零。dbus-monitornotify-sendinotifyuint32xfce4-notifyddunstuint32id

为了完整起见,我在 Rust 中尝试了一个最小的示例:

use gtk::{self, gio::{Notification, ApplicationFlags, Cancellable}, Application};
use gtk::prelude::*;

fn main() {
    let id = Some("1234");
    let not = Notification::new("one");
    let app = Application::new(Some("org.example.Notifier"), ApplicationFlags::default());
    app.register(Cancellable::NONE).expect("register failed");
    app.send_notification(id, &not);
    not.set_title("two");
    app.send_notification(id, &not);
}

同样的问题,将创建第二个通知而不是更新第一个通知。

为什么此功能不起作用?应用程序是否忘记初始化 GTK 的某些部分?还是 GTK 本身的错误?

GTK GTK3

评论


答: 暂无答案