From 1f656eccbbe32b8f387fee8ae57a2e99322df530 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 31 Jul 2024 15:21:57 +0530 Subject: [PATCH] Fix tests for buttons functionality --- docs/notifications.py | 2 +- kitty/notifications.py | 9 ++++----- kitty_tests/notifications.py | 10 +++++----- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/docs/notifications.py b/docs/notifications.py index cdfa8d4a2..60f0a002d 100644 --- a/docs/notifications.py +++ b/docs/notifications.py @@ -18,7 +18,7 @@ def log_notification(nc: NotificationCommand) -> None: print('\n', file=log) -def on_notification_activated(nc: NotificationCommand) -> None: +def on_notification_activated(nc: NotificationCommand, which: int) -> None: # do something when this notification is activated (clicked on) # remember to assign this to the on_activation field in main() pass diff --git a/kitty/notifications.py b/kitty/notifications.py index b7864c13d..f7f5c4d14 100644 --- a/kitty/notifications.py +++ b/kitty/notifications.py @@ -221,7 +221,7 @@ class NotificationCommand: buttons: tuple[str, ...] = () # event callbacks - on_activation: Optional[Callable[['NotificationCommand'], None]] = None + on_activation: Optional[Callable[['NotificationCommand', int], None]] = None on_close: Optional[Callable[['NotificationCommand'], None]] = None on_update: Optional[Callable[['NotificationCommand', 'NotificationCommand'], None]] = None @@ -455,7 +455,7 @@ class DesktopIntegration: def notify(self, nc: NotificationCommand, existing_desktop_notification_id: Optional[int]) -> int: raise NotImplementedError('Implement me in subclass') - def on_new_version_notification_activation(self, cmd: NotificationCommand) -> None: + def on_new_version_notification_activation(self, cmd: NotificationCommand, which: int) -> None: from .update_check import notification_activated notification_activated() @@ -779,11 +779,10 @@ class NotificationManager: if n.focus_requested: self.channel.focus(n.channel_id, n.activation_token) if n.report_requested: - ident = n.identifier or '0' - self.channel.send(n.channel_id, f'99;i={ident};{which or ""}') + self.channel.send(n.channel_id, f'99;i={n.identifier or "0"};{which or ""}') if n.on_activation: try: - n.on_activation(n) + n.on_activation(n, which) except Exception as e: self.log('Notification on_activation handler failed with error:', e) diff --git a/kitty_tests/notifications.py b/kitty_tests/notifications.py index 553675625..6faa58756 100644 --- a/kitty_tests/notifications.py +++ b/kitty_tests/notifications.py @@ -37,8 +37,8 @@ class DesktopIntegration(DesktopIntegration): ids = [n['id'] for n in self.notifications] self.notification_manager.send_live_response(channel_id, client_id, tuple(ids)) - def on_new_version_notification_activation(self, cmd) -> None: - self.new_version_activated = True + def on_new_version_notification_activation(self, cmd, which) -> None: + self.new_version_activated = which + 1 def close_notification(self, desktop_notification_id: int) -> bool: self.close_events.append(desktop_notification_id) @@ -101,9 +101,9 @@ def do_test(self: 'TestNotifications', tdir: str) -> None: def h(raw_data, osc_code=99, channel_id=1): nm.handle_notification_cmd(channel_id, osc_code, raw_data) - def activate(which=0): + def activate(which=0, button=0): n = di.notifications[which] - nm.notification_activated(n['id']) + nm.notification_activated(n['id'], button) def close(which=0): n = di.notifications[which] @@ -238,7 +238,7 @@ def do_test(self: 'TestNotifications', tdir: str) -> None: # Test querying h('i=xyz:p=?') self.assertFalse(di.notifications) - qr = 'a=focus,report:o=always,unfocused,invisible:u=0,1,2:p=title,body,?,close,icon,alive:c=1:w=1' + qr = 'a=focus,report:o=always,unfocused,invisible:u=0,1,2:p=title,body,?,close,icon,alive,buttons:c=1:w=1' self.ae(ch.responses, [f'99;i=xyz:p=?;{qr}']) reset() h('p=?')