Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sound param #25

Merged
merged 3 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ if __name__ == "__main__":
title="Meeting starts now!",
subtitle="Team Standup",
icon="/Users/jorrick/zoom.png",
sound="Frog",
action_button_str="Join zoom meeting",
action_callback=partial(join_zoom_meeting, conf_number=zoom_conf_number)
)
Expand All @@ -63,7 +64,7 @@ A simple example. Please look [in the docs](https://jorricks.github.io/macos-not

## Why did you create this library?
I wanted a library that did not depend on any non-python tools (so you had to go around and install that). Instead, I wanted a library where you install the pip packages, and you are done.
Later I realised how hard it was to integrate correctly with PyOBJC. Also, I had a hard time finding any examples on how to easily integrate this in a non-blocking fashion with my tool.
Later I realised how hard it was to integrate correctly with PyOBJC. Also, I had a hard time finding any examples on how to easily integrate this in a non-blocking fashion with my tool.
Hence, I figured I should set it up to be as user-friendly as possible and share it with the world ;)!


Expand All @@ -72,4 +73,4 @@ Although there are some limitations, there is no reason to not use it now :v:.
- You need to keep your application running while waiting for the callback to happen.
- We do not support raising notifications from anything but the main thread. If you wish to raise it from other threads, you need to set up a communication channel with the main thread, which in turn than raises the notification.
- Currently, we are only supporting the old deprecated [user notifications](https://developer.apple.com/documentation/foundation/nsusernotification). If you wish to use the new implementation, please feel free to propose an MR.
- You can not change the main image of the notification to be project specific. You can only change the Python interpreter image, but that would impact all notifications send by Python.
- You can not change the main image of the notification to be project specific. You can only change the Python interpreter image, but that would impact all notifications send by Python.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ if __name__ == "__main__":
title="Meeting starts now!",
subtitle="Team Standup",
icon="/Users/jorrick/zoom.png",
sound="Frog",
action_button_str="Join zoom meeting",
action_callback=partial(join_zoom_meeting, conf_number=zoom_conf_number)
)
Expand Down
2 changes: 2 additions & 0 deletions src/mac_notifications/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def create_notification(
subtitle: str | None = None,
text: str | None = None,
icon: str | Path | None = None,
sound: str | None = None,
delay: timedelta = timedelta(),
action_button_str: str | None = None,
action_callback: Callable[[], None] | None = None,
Expand All @@ -56,6 +57,7 @@ def create_notification(
subtitle=subtitle,
text=text,
icon=(str(icon.resolve()) if isinstance(icon, Path) else icon) if icon else None,
sound=sound,
delay=delay,
action_button_str=action_button_str,
action_callback=action_callback,
Expand Down
3 changes: 3 additions & 0 deletions src/mac_notifications/notification_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class NotificationConfig:
reply_button_str: str | None
reply_callback: Callable[[str], None] | None
snooze_button_str: str | None
sound: str | None
uid: str = field(default_factory=lambda: uuid.uuid4().hex)

@property
Expand All @@ -42,6 +43,7 @@ def to_json_notification(self) -> "JSONNotificationConfig":
subtitle=NotificationConfig.c_compliant(self.subtitle),
text=NotificationConfig.c_compliant(self.text),
icon=self.icon,
sound=self.sound,
delay_in_seconds=(self.delay or timedelta()).total_seconds(),
action_button_str=NotificationConfig.c_compliant(self.action_button_str),
action_callback_present=bool(self.action_callback),
Expand Down Expand Up @@ -70,6 +72,7 @@ class JSONNotificationConfig:
subtitle: str | None
text: str | None
icon: str | None
sound: str | None
delay_in_seconds: float
action_button_str: str | None
action_callback_present: bool
Expand Down
2 changes: 2 additions & 0 deletions src/mac_notifications/notification_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def send(self):
notification.setSubtitle_(config.subtitle)
if config.text is not None:
notification.setInformativeText_(config.text)
if config.sound is not None:
notification.setSoundName_(config.sound)
if config.icon is not None:
url = NSURL.alloc().initWithString_(f"file://{config.icon}")
image = NSImage.alloc().initWithContentsOfURL_(url)
Expand Down
Loading