Skip to content

Commit 1215a4e

Browse files
committed
cleaner button callbacks
1 parent 25de9bb commit 1215a4e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/desktop_notifier/winrt.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class WinRTDesktopNotifier(DesktopNotifierBase):
6969

7070
DEFAULT_ACTION = "default"
7171
REPLY_ACTION = "action=reply&amp"
72+
BUTTON_ACTION_PREFIX = "action=button&id="
7273
REPLY_TEXTBOX_NAME = "textBox"
7374

7475
def __init__(
@@ -185,7 +186,7 @@ async def _send(
185186
{
186187
"content": button.title,
187188
"activationType": "background",
188-
"arguments": str(n),
189+
"arguments": WinRTDesktopNotifier.BUTTON_ACTION_PREFIX + str(n),
189190
},
190191
)
191192

@@ -217,8 +218,11 @@ def on_activated(sender, boxed_activated_args) -> None: # type:ignore
217218
]
218219
text = unbox_winrt(boxed_text)
219220
notification.reply_field.on_replied(text)
220-
elif action_id.isnumeric():
221-
action_number = int(action_id)
221+
elif action_id.startswith(WinRTDesktopNotifier.BUTTON_ACTION_PREFIX):
222+
action_number_str = action_id.replace(
223+
WinRTDesktopNotifier.BUTTON_ACTION_PREFIX, ""
224+
)
225+
action_number = int(action_number_str)
222226
callback = notification.buttons[action_number].on_pressed
223227
if callback:
224228
callback()

0 commit comments

Comments
 (0)