Jorricks/macos-notifications

MacOSNotification is overriding existing Objective-C class

Closed this issue · 11 comments

Hi,
I get this whenever I try to create the second notification. The first one goes out okay and any further call will result in this error. The first notification is still visible, so no one has closed it yet. I suppose that's the problem and it's trying to override the notification that is currently active and visible instead of creating a new one, like slack or any other chat normally does.

I'm using python 3.9 and Mac OS Big Sur.

python3.9/site-packages/mac_notifications/notification_sender.py", line 29, in create_notification
    class MacOSNotification(NSObject):
objc.error: MacOSNotification is overriding existing Objective-C class

Hi @nullcode,
Sad to hear you are having issues. I'm not directly able to replicate this.
Could you please provide a minimal example to replicate the issue :)?

from mac_notifications import client

client.create_notification(
    title="Meeting starts now!",
    subtitle="Team Standup",
)
client.create_notification(
    title="Meeting 2 starts now!",
    subtitle="Team Standup",
)

throws this on the second call:

Traceback (most recent call last):
  File "notification.py", line 7, in <module>
    client.create_notification(
  File "/.virtualenvs/blink/lib/python3.9/site-packages/mac_notifications/client.py", line 66, in create_notification
    get_notification_manager().create_notification(notification_config)
  File "/.virtualenvs/blink/lib/python3.9/site-packages/mac_notifications/manager.py", line 69, in create_notification
    notification_sender.create_notification(json_config, None).send()
  File "/.virtualenvs/blink/lib/python3.9/site-packages/mac_notifications/notification_sender.py", line 29, in create_notification
    class MacOSNotification(NSObject):
objc.error: MacOSNotification is overriding existing Objective-C class

@Jorricks my first assumption wasn't true with it only might happen if the first notification is still active. I made an example where I put a 1 minute sleep inbetween the two calls and it still failed the same way.

can you try to define and move the MacOSNotification(NSObject) class outside of the create_notification function? If my hunch is right that should fix it.

can you try to define and move the MacOSNotification(NSObject) class outside of the create_notification function? If my hunch is right that should fix it.

Unfortunately, that's not as easy as it seems.
These functions need the variables that are passed by the function and given these function interfaces need to match with what is provided by pyobjc, we can't simply add or remove arguments inside the class.
If you have an idea on how to fix it, please let me know.

I am able to replicate your issue now.
I'm confused that our example multiple_notifications_with_callbacks does not face this issue.
I'll see if I can convert that into this issue and see if I can discover what triggers this.

Alright, it has to do with creating the notifications twice from inside the same process. I'll work on a bugfix and keep you posted. Thanks for reporting it mate ✌️!

Releasing a new version in a minute.
You'll have to add if __name__ == "__main__": though :'(

@nullcode please give the new 0.1.4 a try and let me know if it works for you as well :)

thanks @Jorricks , it does work now. Great work on this library!

Thank you :)! I will close this issue.

Please let me know if anything else pops up that you'd like me to look at.