Add a option to turn on saving and choose a folder of notifications.

main
KKlochko 1 year ago
parent 694b1934ac
commit 1c829cf7cc

@ -39,6 +39,12 @@ def up(
5555, "--port", "-p",
help="The server's port to notify [b]clients[/].",
rich_help_panel="Connection",
),
notification_dir: str = typer.Option(
None, "--notification-dir", "-d",
help="The client will save notifications to the directory by the path. Does not save if this option is not provided.",
rich_help_panel="Persistence",
show_default=False,
)
):
"""
@ -46,7 +52,7 @@ def up(
"""
try:
client = Client(ip, port)
client = Client(ip, port, notification_dir)
asyncio.run(client.connect())
except KeyboardInterrupt:
MessagePrinter.bye()

@ -29,9 +29,9 @@ from notification_client.notification_saver import NotificationSaver
class Client:
BUFFER_SIZE = 1024
NOTIFICATION_DIR = 'notifications'
NOTIFICATION_DIR = None
def __init__(self, ip: str, port: int, notification_dir: str = 'notifications'):
def __init__(self, ip: str, port: int, notification_dir: str | None = None):
self.__ip = ip
self.__port = port
self.NOTIFICATION_DIR = notification_dir
@ -65,7 +65,8 @@ class Client:
Notification.notify(title, message)
NotificationSaver.save_notification(self.NOTIFICATION_DIR, title, message, now)
if not self.NOTIFICATION_DIR is None:
NotificationSaver.save_notification(self.NOTIFICATION_DIR, title, message, now)
except asyncio.CancelledError:
print('Something went wrong')

Loading…
Cancel
Save