Jorricks / macos-notifications

Create interactable notifications in the Notification Centre on any Mac using Python
https://jorricks.github.io/macos-notifications/
MIT License
74 stars 4 forks source link

[WIP] Don't instantiate SimpleQueue until needed to allow execution from daemons and servers #24

Closed michelcrypt4d4mus closed 5 months ago

michelcrypt4d4mus commented 5 months ago

This is a pretty horrible and hacky workaround so I'm not sure you should actually merge this pull request but I figured it would be helpful for you to to see the v. limited changed I needed to get your code to work in the context of being run from a server or daemon. Maybe you have some better ideas about how to go about actually implementing this in your codebase? Happy to help.

See discussion

michelcrypt4d4mus commented 5 months ago

Did some additional digging into what might be causing the issue... I know launchd is finicky and I stumbled upon this discussion of issues with python fork() in macOS as well as similar discussions for ruby and php having to do with some recent macOS changes... however setting OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES did not seem to fix my issue with the unpatched version of this package.

michelcrypt4d4mus commented 5 months ago

So... this actually doesn't quite work. It works great... once. The next time it fails with:

error: MacOSNotification is overriding existing Objective-C class

This is because every call to notification_sender.create_notification() redefines the class MacOSNotification. In your implementation this isn't a problem because you are forking a process and there's no collision, but in my situation that's no bueno.

So I pulled the MacOSNotification class outside of the function over on another branch (that also includes the sound parameter, sorry) and it works great. However I have not tested it with any kind of callback as per the usual setup.

Closing this because it's not a valid fix.