caseymrm / menuet

Go library to create menubar apps- programs that live only in OSX's NSStatusBar
MIT License
281 stars 20 forks source link

defer functions doesn't execute when application exit #17

Closed pelenthium closed 1 year ago

pelenthium commented 4 years ago

Hi, thanks for this cool library, this awesome, and exactly what I need. But I see that we exit the application from native code, so it breaks golang spec - we can't execute defer functions :(

Can you please give a point on how to fix it?

caseymrm commented 4 years ago

Interesting, thanks for the report.

This will probably require some experimentation. It may be that inside menuet.m's applicationShouldTerminate (https://github.com/caseymrm/menuet/blob/master/menuet.m#L225) we need to call back into go to clean up before returning NSTerminateNow.

Based on this: https://stackoverflow.com/questions/27629380/how-to-exit-a-go-program-honoring-deferred-calls this might be as simple as calling runtime.Goexit(), or maybe we would need to do the panic/recover mentioned in a later answer.

(This might also require making sure applicationWillTerminate is set to NO in your Info.plist, because nothing is ever easy.)

forfuncsake commented 1 year ago

Fixed by #20?