willdot / gomacosnotify

API for sending desktop notifications via Go code on macOS.
MIT License
5 stars 1 forks source link

Add more features of alerter & issue after restart #2

Open lyimmi opened 1 year ago

lyimmi commented 1 year ago

Hi @willdot, I would like to add more features of alerter to gomacosnotify, so it would be more feature complete.

I'll make a PR with the changes.

On another note: I don't know if you noticed that when an app uses gomacosnotify the first time everything seems ok, the permissions popup shows, if you accept the notifications work.

But when you restart the computer, the program has no errors, but the notifications are not shown. Now, I added the -sender ID flag from alerter and if I change the sender ID after a restart alerter works again. Have you seen any of this behavior and if so can you please tell me how to prevent it?

FYI: I'm working on a catalina VM. (Maybe that is the problem, I'm not sure.)

willdot commented 1 year ago

Hey thanks for the PR, I’ll take a look over the next few days when I get some time to test it out.

I’ve been using the library on Monterey and Ventura. But I do from time to time get the notification about permissions. I think (but will have to check) that they changed how permissions worked in Monterey which might explain why you see different behaviour.

I would have thought that changing the sender ID would trigger the permission prompt though 🧐 I’ll see if I can have a play around but could you perhaps try seeing if you get the same behaviour when calling the alerter binary manual via a CLI?

Again, thanks for the feedback and PR. I never expected someone to actually stumble across this library!

lyimmi commented 1 year ago

I'm currently implementing notifications in wails and you mentioned your package and I would like to use it for the Mac side.

I only tried this package as part of wails on this branch. I'll make a simple test binary to test that way too.

Alerter behaves that same way when it's in /var/folders used as a binary and as through this package.

I'm genuinely confused at this point. Something breaks the permissions on shutdown I think.

willdot commented 1 year ago

Hmmm so I've just tried this out.

Running my library and the first time after turning laptop on (note I rarely turn my laptop off 🤣) I get the prompt to allow my app to show notifications. Then when I accept, the notification I sent doesn't appear. If I send another notification it appears just fine. Restart the laptop and send a notification it prompts me to allow the app to show notifications.

It's almost as if the OS api is swallowing the notification when it prompts for access. There must be a way though because apps such as Slack etc don't have this problem. However I did notice when installing some applications onto a new Macbook this week during my new job onboarding, that the first starting the app I got the prompt to allow notifications. Perhaps that's how apps get over the initial prompt, by sending a dummy notification they know will get rejected? Sounds tacky though.

I have also tried setting the sender ID as you've added in your PR but that doesn't seem to solve the problem either which is strange as I would have thought that that would be how the OS knows that an app has already been allowed.

I'm going to continue to investigate when I find some time though. Thanks for helping out!