Add a option to turn on saving and choose a folder of notifications.
This commit is contained in:
@@ -39,6 +39,12 @@ def up(
|
|||||||
5555, "--port", "-p",
|
5555, "--port", "-p",
|
||||||
help="The server's port to notify [b]clients[/].",
|
help="The server's port to notify [b]clients[/].",
|
||||||
rich_help_panel="Connection",
|
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:
|
try:
|
||||||
client = Client(ip, port)
|
client = Client(ip, port, notification_dir)
|
||||||
asyncio.run(client.connect())
|
asyncio.run(client.connect())
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
MessagePrinter.bye()
|
MessagePrinter.bye()
|
||||||
|
|||||||
@@ -29,9 +29,9 @@ from notification_client.notification_saver import NotificationSaver
|
|||||||
|
|
||||||
class Client:
|
class Client:
|
||||||
BUFFER_SIZE = 1024
|
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.__ip = ip
|
||||||
self.__port = port
|
self.__port = port
|
||||||
self.NOTIFICATION_DIR = notification_dir
|
self.NOTIFICATION_DIR = notification_dir
|
||||||
@@ -65,6 +65,7 @@ class Client:
|
|||||||
|
|
||||||
Notification.notify(title, message)
|
Notification.notify(title, message)
|
||||||
|
|
||||||
|
if not self.NOTIFICATION_DIR is None:
|
||||||
NotificationSaver.save_notification(self.NOTIFICATION_DIR, title, message, now)
|
NotificationSaver.save_notification(self.NOTIFICATION_DIR, title, message, now)
|
||||||
|
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
|
|||||||
Reference in New Issue
Block a user