feat: Add desktop notification functionality with icon

Adds functionality to send desktop notifications with an icon. The `notify()` function now accepts an optional `urgency` parameter and a `timeout` parameter. The notification is sent using the `notify-send` command and includes an icon. The icon used is the "parcel-delivery-icon.webp" file located in the assets folder.
This commit is contained in:
Kumi 2023-08-21 09:14:25 +02:00
parent 69e5023994
commit 3a36b18d65
Signed by: kumi
GPG key ID: ECBCC9082395383F
3 changed files with 14 additions and 2 deletions

View file

@ -0,0 +1,3 @@
Icon taken from uxwing.com: https://uxwing.com/parcel-delivery-icon/
License for the icon: https://uxwing.com/license/

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View file

@ -7,6 +7,7 @@ import subprocess
import argparse import argparse
import logging import logging
from pathlib import Path
from typing import Tuple, Never from typing import Tuple, Never
# Print date and time and level with message # Print date and time and level with message
@ -16,7 +17,7 @@ logging.basicConfig(
datefmt="%Y-%m-%d %H:%M:%S", datefmt="%Y-%m-%d %H:%M:%S",
) )
def notify(title: str, message: str): def notify(title: str, message: str, urgency: str = "normal", timeout: int = 5000):
"""Send a desktop notification """Send a desktop notification
If notify-send is not found, this function will do nothing. If notify-send is not found, this function will do nothing.
@ -32,9 +33,12 @@ def notify(title: str, message: str):
subprocess.run( subprocess.run(
[ [
"notify-send", "notify-send",
"-a", "trackbert",
"-u", urgency,
"-t", str(timeout),
"-i", str(Path(__file__).parent / "assets" / "parcel-delivery-icon.webp"),
title, title,
message, message,
# TODO: Look into other options, like adding an icon
] ]
) )
@ -256,9 +260,14 @@ if __name__ == "__main__":
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
# Shipment creation arguments
parser.add_argument("--tracking-number", "-n", type=str, required=False) parser.add_argument("--tracking-number", "-n", type=str, required=False)
parser.add_argument("--carrier", "-c", type=str, required=False) parser.add_argument("--carrier", "-c", type=str, required=False)
parser.add_argument("--description", "-d", type=str, required=False) parser.add_argument("--description", "-d", type=str, required=False)
# Notification arguments
args = parser.parse_args() args = parser.parse_args()
# If the user specified a tracking number and carrier, create a shipment and exit # If the user specified a tracking number and carrier, create a shipment and exit