-
Notifications
You must be signed in to change notification settings - Fork 4
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
#14 Implement notification cancellation #15
Conversation
Hello @basilevs, |
I don't see the suggestion make sure you've posted them (they are organized in reviews and are only published when the review is published) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woops. I use Gitlab during the day so sometimes it's a bit searching on Github. Thanks for the pointer ✌️
if __name__ == "__main__": | ||
print("Sending meeting notification.") | ||
|
||
sent: [Notification] = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is correct Python3.8 syntax.
sent: [Notification] = [] | |
sent: List[Notification] = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to add the from typing import List
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with list
builtin
@@ -107,3 +106,9 @@ def userNotificationCenter_didActivateNotification_( | |||
|
|||
# return notification | |||
return new_notif | |||
|
|||
|
|||
def cancel_notification(uid:str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def cancel_notification(uid:str): | |
def cancel_notification(uid: str) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/mac_notifications/manager.py
Outdated
@@ -30,6 +31,15 @@ | |||
logger = logging.getLogger() | |||
|
|||
|
|||
class Notification(object): | |||
def __init__(self, uid): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def __init__(self, uid): | |
def __init__(self, uid: str) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/mac_notifications/manager.py
Outdated
def __init__(self, uid): | ||
self.uid = uid | ||
|
||
def cancel(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def cancel(self): | |
def cancel(self) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/mac_notifications/manager.py
Outdated
@@ -12,6 +12,7 @@ | |||
from mac_notifications.listener_process import NotificationProcess | |||
from mac_notifications.notification_config import NotificationConfig | |||
from mac_notifications.singleton import Singleton | |||
from .notification_sender import cancel_notification |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from .notification_sender import cancel_notification | |
from mac_notifications import notification_sender |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced with
from mac_notifications.notification_sender import cancel_notification
self.uid = uid | ||
|
||
def cancel(self): | ||
cancel_notification(self.uid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cancel_notification(self.uid) | |
notification_sender.cancel_notification(self.uid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above
All suggestions have been acted upon |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Let's merge it :)
Fixes #14
This introduces a way for user to cancel previously sent notification.
The implementation is naive and dirty - no threading or processes involved, notification is cancelled by its ID.
I've tried a "proper" solution with remote controlled singular side-car process, but found, that this is much simpler, as actual notification object is not needed to cancel it, and cancellation is a non-blocking operation.
Usage example: