deckarep / gosx-notifier

gosx-notifier is a Go framework for sending desktop notifications to OSX 10.8 or higher
MIT License
588 stars 51 forks source link

How to embed binary #4

Closed bscott closed 10 years ago

bscott commented 10 years ago

How did you statically import the binary?

deckarep commented 10 years ago

Hello @bscott,

Are you asking because something is not working correctly or just curious?

This was a little tricky but I pulled it off using the following solution:

  1. I built the original terminal-notifier project in XCode to generate a native osx package
  2. Since native osx packages are really just special directories with various files, I zipped it up into one file.
  3. I then used this Go package: https://github.com/jteeuwen/go-bindata (which allows you to convert a file to a static Go source file)
  4. I then referenced the static Go file in my project which basically allows me to get at the raw bytes of the terminal-notifier package
  5. Using Go code, I basically unzip the raw bytes into a temp directory to finish out installing the component.
  6. I then reference the temp directory and executable using Command.Output() everytime a notifcation is "pushed"

I hope that is helpful, and I'm happy to answer more questions.

Note: While this solution works, I think I have a better way of doing this that no longer requires embedding the terminal-notifier binary. I can probably pull it off using pure Cgo and invoking native OSX calls directly. Keep an eye out for that version one day.

bscott commented 10 years ago

@deckarep I'm just curious

bscott commented 10 years ago

@deckarep Thanks that helps.