mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-26 18:22:09 +02:00
Fix tests for buttons functionality
This commit is contained in:
@@ -18,7 +18,7 @@ def log_notification(nc: NotificationCommand) -> None:
|
|||||||
print('\n', file=log)
|
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)
|
# do something when this notification is activated (clicked on)
|
||||||
# remember to assign this to the on_activation field in main()
|
# remember to assign this to the on_activation field in main()
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ class NotificationCommand:
|
|||||||
buttons: tuple[str, ...] = ()
|
buttons: tuple[str, ...] = ()
|
||||||
|
|
||||||
# event callbacks
|
# 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_close: Optional[Callable[['NotificationCommand'], None]] = None
|
||||||
on_update: Optional[Callable[['NotificationCommand', '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:
|
def notify(self, nc: NotificationCommand, existing_desktop_notification_id: Optional[int]) -> int:
|
||||||
raise NotImplementedError('Implement me in subclass')
|
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
|
from .update_check import notification_activated
|
||||||
notification_activated()
|
notification_activated()
|
||||||
|
|
||||||
@@ -779,11 +779,10 @@ class NotificationManager:
|
|||||||
if n.focus_requested:
|
if n.focus_requested:
|
||||||
self.channel.focus(n.channel_id, n.activation_token)
|
self.channel.focus(n.channel_id, n.activation_token)
|
||||||
if n.report_requested:
|
if n.report_requested:
|
||||||
ident = n.identifier or '0'
|
self.channel.send(n.channel_id, f'99;i={n.identifier or "0"};{which or ""}')
|
||||||
self.channel.send(n.channel_id, f'99;i={ident};{which or ""}')
|
|
||||||
if n.on_activation:
|
if n.on_activation:
|
||||||
try:
|
try:
|
||||||
n.on_activation(n)
|
n.on_activation(n, which)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.log('Notification on_activation handler failed with error:', e)
|
self.log('Notification on_activation handler failed with error:', e)
|
||||||
|
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ class DesktopIntegration(DesktopIntegration):
|
|||||||
ids = [n['id'] for n in self.notifications]
|
ids = [n['id'] for n in self.notifications]
|
||||||
self.notification_manager.send_live_response(channel_id, client_id, tuple(ids))
|
self.notification_manager.send_live_response(channel_id, client_id, tuple(ids))
|
||||||
|
|
||||||
def on_new_version_notification_activation(self, cmd) -> None:
|
def on_new_version_notification_activation(self, cmd, which) -> None:
|
||||||
self.new_version_activated = True
|
self.new_version_activated = which + 1
|
||||||
|
|
||||||
def close_notification(self, desktop_notification_id: int) -> bool:
|
def close_notification(self, desktop_notification_id: int) -> bool:
|
||||||
self.close_events.append(desktop_notification_id)
|
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):
|
def h(raw_data, osc_code=99, channel_id=1):
|
||||||
nm.handle_notification_cmd(channel_id, osc_code, raw_data)
|
nm.handle_notification_cmd(channel_id, osc_code, raw_data)
|
||||||
|
|
||||||
def activate(which=0):
|
def activate(which=0, button=0):
|
||||||
n = di.notifications[which]
|
n = di.notifications[which]
|
||||||
nm.notification_activated(n['id'])
|
nm.notification_activated(n['id'], button)
|
||||||
|
|
||||||
def close(which=0):
|
def close(which=0):
|
||||||
n = di.notifications[which]
|
n = di.notifications[which]
|
||||||
@@ -238,7 +238,7 @@ def do_test(self: 'TestNotifications', tdir: str) -> None:
|
|||||||
# Test querying
|
# Test querying
|
||||||
h('i=xyz:p=?')
|
h('i=xyz:p=?')
|
||||||
self.assertFalse(di.notifications)
|
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}'])
|
self.ae(ch.responses, [f'99;i=xyz:p=?;{qr}'])
|
||||||
reset()
|
reset()
|
||||||
h('p=?')
|
h('p=?')
|
||||||
|
|||||||
Reference in New Issue
Block a user