Skip to content

Commit da3cf67

Browse files
committed
Update notifications interface using recent code generator
This fixes several issues: 1. Fix `action_invoked` return type. It should be `tuple[int, str]` instead of `tuple[int, int]`. (reported by @C0rn3j) 2. Fix flags and result argument names missing. 3. Add new `activation_token` signal.
1 parent 7932225 commit da3cf67

File tree

2 files changed

+82
-18
lines changed

2 files changed

+82
-18
lines changed

sdbus_async/notifications/__init__.py

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,36 @@
2222
from pathlib import Path
2323
from typing import Any, Dict, List, Optional, Tuple, Union
2424

25-
from sdbus import (DbusInterfaceCommonAsync, dbus_method_async,
26-
dbus_signal_async)
25+
from sdbus import (
26+
DbusInterfaceCommonAsync,
27+
DbusUnprivilegedFlag,
28+
dbus_method_async,
29+
dbus_signal_async,
30+
)
2731
from sdbus.sd_bus_internals import SdBus
2832

2933

3034
class NotificationsInterface(
3135
DbusInterfaceCommonAsync,
3236
interface_name='org.freedesktop.Notifications'):
3337

34-
@dbus_method_async('u')
38+
@dbus_method_async(
39+
input_signature="u",
40+
result_args_names=(),
41+
flags=DbusUnprivilegedFlag,
42+
)
3543
async def close_notification(self, notif_id: int) -> None:
3644
"""Close notification by id.
3745
3846
:param int notif_id: Notification id to close.
3947
"""
4048
raise NotImplementedError
4149

42-
@dbus_method_async()
50+
@dbus_method_async(
51+
result_signature="as",
52+
result_args_names=('capabilities',),
53+
flags=DbusUnprivilegedFlag,
54+
)
4355
async def get_capabilities(self) -> List[str]:
4456
"""Returns notification daemon capabilities.
4557
@@ -66,7 +78,16 @@ async def get_capabilities(self) -> List[str]:
6678
"""
6779
raise NotImplementedError
6880

69-
@dbus_method_async()
81+
@dbus_method_async(
82+
result_signature="ssss",
83+
result_args_names=(
84+
'server_name',
85+
'server_vendor',
86+
'version',
87+
'notifications_version',
88+
),
89+
flags=DbusUnprivilegedFlag,
90+
)
7091
async def get_server_information(self) -> Tuple[str, str, str, str]:
7192
"""Returns notification server information.
7293
@@ -76,7 +97,12 @@ async def get_server_information(self) -> Tuple[str, str, str, str]:
7697
"""
7798
raise NotImplementedError
7899

79-
@dbus_method_async("susssasa{sv}i")
100+
@dbus_method_async(
101+
input_signature="susssasa{sv}i",
102+
result_signature="u",
103+
result_args_names=('notif_id',),
104+
flags=DbusUnprivilegedFlag,
105+
)
80106
async def notify(
81107
self,
82108
app_name: str = '',
@@ -97,7 +123,8 @@ async def notify(
97123
:param str summary: Summary of notification.
98124
:param str body: Optional body of notification.
99125
:param List[str] actions: Optional list of actions presented to user. \
100-
List index becomes action id.
126+
Should be sent in pairs of strings that represent action \
127+
key identifier and a localized string to be displayed to user.
101128
:param Dict[str,Tuple[str,Any]] hints: Extra options such as sounds \
102129
that can be passed. See :py:meth:`create_hints`.
103130
:param int expire_timeout: Optional notification expiration timeout \
@@ -109,18 +136,23 @@ async def notify(
109136

110137
raise NotImplementedError
111138

112-
@dbus_signal_async()
113-
def action_invoked(self) -> Tuple[int, int]:
139+
@dbus_signal_async(
140+
signal_signature="us",
141+
signal_args_names=('notif_id', 'action_key'),
142+
)
143+
def action_invoked(self) -> Tuple[int, str]:
114144
"""Signal when user invokes one of the actions specified.
115145
116146
First element of tuple is notification id.
117147
118-
Second element is the index of the action invoked. \
119-
Matches the index of passed list of actions.
148+
Second element is the key identifier of the action invoked.
120149
"""
121150
raise NotImplementedError
122151

123-
@dbus_signal_async()
152+
@dbus_signal_async(
153+
signal_signature="uu",
154+
signal_args_names=('notif_id', 'reason'),
155+
)
124156
def notification_closed(self) -> Tuple[int, int]:
125157
"""Signal when notification is closed.
126158
@@ -135,6 +167,24 @@ def notification_closed(self) -> Tuple[int, int]:
135167
"""
136168
raise NotImplementedError
137169

170+
@dbus_signal_async(
171+
signal_signature="us",
172+
signal_args_names=('notif_id', 'action_key'),
173+
)
174+
def activation_token(self) -> Tuple[int, str]:
175+
"""Signal carrying window system token.
176+
177+
Emitted before :py:attr:`action_invoked`.
178+
179+
Carries windowing system token like X11 startup id or
180+
Wayland adctivation token.
181+
182+
First element of tuple is notification id.
183+
184+
Second element is the key identifier of the action invoked.
185+
"""
186+
raise NotImplementedError
187+
138188
def create_hints(
139189
self,
140190
use_action_icons: Optional[bool] = None,

sdbus_block/notifications/__init__.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from pathlib import Path
2323
from typing import Any, Dict, List, Optional, Tuple, Union
2424

25-
from sdbus import DbusInterfaceCommon, dbus_method
25+
from sdbus import DbusInterfaceCommon, DbusUnprivilegedFlag, dbus_method
2626
from sdbus.sd_bus_internals import SdBus
2727

2828

@@ -47,15 +47,21 @@ def __init__(self, bus: Optional[SdBus] = None) -> None:
4747
bus,
4848
)
4949

50-
@dbus_method('u')
50+
@dbus_method(
51+
input_signature="u",
52+
flags=DbusUnprivilegedFlag,
53+
)
5154
def close_notification(self, notif_id: int) -> None:
5255
"""Close notification by id.
5356
5457
:param int notif_id: Notification id to close.
5558
"""
5659
raise NotImplementedError
5760

58-
@dbus_method()
61+
@dbus_method(
62+
result_signature="as",
63+
flags=DbusUnprivilegedFlag,
64+
)
5965
def get_capabilities(self) -> List[str]:
6066
"""Returns notification daemon capabilities.
6167
@@ -82,7 +88,10 @@ def get_capabilities(self) -> List[str]:
8288
"""
8389
raise NotImplementedError
8490

85-
@dbus_method()
91+
@dbus_method(
92+
result_signature="ssss",
93+
flags=DbusUnprivilegedFlag,
94+
)
8695
def get_server_information(self) -> Tuple[str, str, str, str]:
8796
"""Returns notification server information.
8897
@@ -92,7 +101,11 @@ def get_server_information(self) -> Tuple[str, str, str, str]:
92101
"""
93102
raise NotImplementedError
94103

95-
@dbus_method('susssasa{sv}i')
104+
@dbus_method(
105+
input_signature="susssasa{sv}i",
106+
result_signature="u",
107+
flags=DbusUnprivilegedFlag,
108+
)
96109
def notify(
97110
self,
98111
app_name: str = '',
@@ -113,7 +126,8 @@ def notify(
113126
:param str summary: Summary of notification.
114127
:param str body: Optional body of notification.
115128
:param List[str] actions: Optional list of actions presented to user. \
116-
List index becomes action id.
129+
Should be sent in pairs of strings that represent action \
130+
key identifier and a localized string to be displayed to user.
117131
:param Dict[str,Tuple[str,Any]] hints: Extra options such as sounds \
118132
that can be passed. See :py:meth:`create_hints`.
119133
:param int expire_timeout: Optional notification expiration timeout \

0 commit comments

Comments
 (0)