书签:
可以通过 DBus 触发和调用 org.freedesktop.Notifications.CloseNotification(uint id) 吗?
目前,这个脚本
dbus-monitor "interface='org.freedesktop.Notifications'" | \
grep --line-buffered "member=Notify" | \
sed -u -e 's/.*/killall notify-osd/g' | \
bash
Run Code Online (Sandbox Code Playgroud)
将杀死所有待处理的通知。
最好使用 org.freedesktop.Notifications.CloseNotification(uint id). 是否有接口方法可以将它放在(在?)DBus 上以在发生特定通知事件时触发?
该方法需要获取通知 PID 以用作 的参数CloseNotification(uint id)。或者,
qdbus org.freedesktop.Notifications \
/org/freedesktop/Notifications \
org.freedesktop.Notifications.CloseNotification(uint id)
Run Code Online (Sandbox Code Playgroud)
如果(uint id)可以确定参数,则可以从外壳使用。实际的命令语法将使用整数代替(uint id)。
也许首先要问的更好的问题可能是“如何找到通知的 DBus 地址?”。
这些都不能正确识别它:
gdbus monitor --session --dest org.freedesktop.Notifications
Run Code Online (Sandbox Code Playgroud)
返回
The name org.freedesktop.Notifications is owned by :1.130
...
Run Code Online (Sandbox Code Playgroud)
或者
dbus-monitor "interface='org.freedesktop.Notifications'"
Run Code Online (Sandbox Code Playgroud)
返回
... string ":1.340" ...
Run Code Online (Sandbox Code Playgroud)
事后看来,(uint id)鉴于之前对另一个问题的回答,之前的问题“如何找到通知?”是修辞
手法:
https : //askubuntu.com/a/186311/89468
提供了详细信息,因此可以使用以下任一方法:
gdbus call --session --dest org.freedesktop.DBus \
--object-path / \
--method org.freedesktop.DBus.GetConnectionUnixProcessID :1.16
Run Code Online (Sandbox Code Playgroud)
返回:
(uint32 8957,)
Run Code Online (Sandbox Code Playgroud)
或者
qdbus --literal --session org.freedesktop.DBus \
/ \
org.freedesktop.DBus.GetConnectionUnixProcessID :1.16
Run Code Online (Sandbox Code Playgroud)
返回:
8957
Run Code Online (Sandbox Code Playgroud)
弹出的通知 OSD 涂鸦将被击败:
qdbus org.freedesktop.Notifications \
/org/freedesktop/Notifications \
org.freedesktop.Notifications.CloseNotification \
$(qdbus --literal --session \
org.freedesktop.DBus \
/ \
org.freedesktop.DBus.GetConnectionUnixProcessID :?.??? )
Run Code Online (Sandbox Code Playgroud)
“技巧”是找到:?.???DBus 地址。
小智 2
你怎么知道什么(UINT32 id)是或不是?
You ... need a way to get that ID ...鉴于此答案中的陈述以及以下实证观察,问题的标题也许应该更改为“如何gdbus ... -m org.freedesktop.Notifications.CloseNotification ...关闭通知?”
9.1.2的描述中的语句“...它仅说明 ID 是唯一的、非零且小于 MAXINT ...”是通过暗示还是消除过程来实现的?org.freedesktop.Notifications.Notify,也适用于CloseNotification参数(UINT32 id)? 通过消除过程UINT32是文档中作为属性类型的唯一共同因素,这意味着必须有某种共同的 ID“句柄”,但是......
返回值Notify及其参数的详细信息UINT32 replaces_id非常明确,但尚不清楚CloseNotifications(UINT32 id)与此有什么关系,如下面的实证测试所示。
引用9.1.3。org.freedesktop.Notifications.CloseNotification总体而言:
9.1.3. org.freedesktop.Notifications.CloseNotification
void org.freedesktop.Notifications.CloseNotification (UINT32 id);
Causes a notification to be forcefully closed and removed from the user's view.
It can be used, for example, in the event that what the notification pertains to
is no longer relevant, or to cancel a notification with no expiration time.
The NotificationClosed signal is emitted by this method.
If the notification no longer exists, an empty D-BUS Error message is sent back.
Run Code Online (Sandbox Code Playgroud)
这并不表征或解释 的含义(UINT32 id)。
一个明显的遗漏是缺少描述NotificationClosed (UINT32 id)参数的表格。方法和信号的所有其他参数均符合此类表。
经验测试显示通知不会使用 的Notify返回值关闭:
qdbus org.freedesktop.Notifications \
/org/freedesktop/Notifications \
org.freedesktop.Notifications.CloseNotification \
$(gdbus call --session \
-d org.freedesktop.Notifications \
-o /org/freedesktop/Notifications \
-m org.freedesktop.Notifications.Notify \
"" 0 "" "sigma-ry" "corpus" [] {} 200 \
| sed -e 's/(uint32\(.*\),)/\1/g' )
Run Code Online (Sandbox Code Playgroud)
或者
qdbus org.freedesktop.Notifications \
/org/freedesktop/Notifications \
org.freedesktop.Notifications.CloseNotification \
$(gdbus call --session \
-d org.freedesktop.Notifications \
-o /org/freedesktop/Notifications \
-m org.freedesktop.Notifications.Notify \
"" 5 "" "sigma-ry" "corpus" [] {} 20 \
| sed -e 's/(uint32\(.*\),)/\1/g' )
Run Code Online (Sandbox Code Playgroud)
(UINT32 id)如果使用返回值 进行标识,则通知不会关闭Notify。
更多测试:
gdbus call --session \
-d org.freedesktop.Notifications \
-o /org/freedesktop/Notifications \
-m org.freedesktop.Notifications.CloseNotification \
$(gdbus call --session \
-d org.freedesktop.Notifications \
-o /org/freedesktop/Notifications \
-m org.freedesktop.Notifications.Notify \
"" 0 "" "sigma-ry" "corpus" [] {} 0 \
| sed -e 's/(uint32\(.*\),)/\1/g' )
Run Code Online (Sandbox Code Playgroud)
甚至强制使用常量 ID,通过设置UINT32 replaces_id为 42 和expire_timeout0,可以看出CloseNotification没有影响
gdbus call --session \
-d org.freedesktop.Notifications \
-o /org/freedesktop/Notifications \
-m org.freedesktop.Notifications.CloseNotification \
$(gdbus call --session \
-d org.freedesktop.Notifications \
-o /org/freedesktop/Notifications \
-m org.freedesktop.Notifications.Notify \
"" 42 "" "sigma-ry" "corpus" [] {} 0 \
| sed -e 's/(uint32\(.*\),)/\1/g' )
Run Code Online (Sandbox Code Playgroud)
42即使通过确认的方法进行往返,通知也不会关闭
dbus-monitor "interface='org.freedesktop.Notifications'"
Run Code Online (Sandbox Code Playgroud)
在输出中
方法调用 sender=:1.332 -> dest=org.freedesktop.Notifications serial=3 path=/org/freedesktop/Notifications; 接口=org.freedesktop.Notifications;会员=通知 细绳 ”” uint32 42 细绳 ”” 字符串“西格玛” 字符串“语料库” 大批 [ ] 大批 [ ] int32 0 方法调用 sender=:1.333 -> dest=org.freedesktop.Notifications serial=3 path=/org/freedesktop/Notifications; 接口=org.freedesktop.Notifications;成员=关闭通知 uint32 42
另请注意 -1 超时的通知失败(文档是矛盾的):
gdbus call --session \
-d org.freedesktop.Notifications \
-o /org/freedesktop/Notifications \
-m org.freedesktop.Notifications.Notify \
"" 42 "" "sigma-ry" "corpus" [] {} -1
Run Code Online (Sandbox Code Playgroud)
虽然这“有效”
notify-send "test" -t -1
Run Code Online (Sandbox Code Playgroud)
参考:
显示通知的程序的名称是什么?(文档矛盾)
如何强制在notify-osd中显示新的通知而不等待较早的通知退出?
如何使用“通知发送”立即替换现有通知?
书签:
org.freedesktop.Notifications.CloseNotification(uint id) 能否通过DBus触发调用?