Skip to content

Instantly share code, notes, and snippets.

@asticode
Last active January 12, 2020 17:08
Show Gist options
  • Select an option

  • Save asticode/47a1482f8f9dc667fd97e507b05e5f4f to your computer and use it in GitHub Desktop.

Select an option

Save asticode/47a1482f8f9dc667fd97e507b05e5f4f to your computer and use it in GitHub Desktop.
func main() {
// Create logger
l := log.New(log.Writer(), log.Prefix(), log.Flags())
// Run bootstrap
bootstrap.Run(bootstrap.Options{
MenuOptions: []*astilectron.MenuItemOptions{{
Label: astilectron.PtrStr("File"),
SubMenu: []*astilectron.MenuItemOptions{
{
Label: astilectron.PtrStr("About"),
OnClick: func(e astilectron.Event) (deleteListener bool) {
if err := bootstrap.SendMessage(w, "about", htmlAbout, func(m *bootstrap.MessageIn) {
// Unmarshal payload
var s string
if err := json.Unmarshal(m.Payload, &s); err != nil {
l.Println(errors.Wrap(err, "unmarshaling payload failed"))
return
}
l.Printf("About modal has been displayed and payload is %s!\n", s)
}); err != nil {
l.Println(errors.Wrap(err, "sending about event failed"))
}
return
},
},
{Role: astilectron.MenuItemRoleClose},
},
}},
OnWait: func(_ *astilectron.Astilectron, iw *astilectron.Window, _ *astilectron.Menu, _ *astilectron.Tray, _ *astilectron.Menu) error {
w = iw
go func() {
time.Sleep(5 * time.Second)
if err := bootstrap.SendMessage(w, "check.out.menu", "Don't forget to check out the menu!"); err != nil {
l.Println(errors.Wrap(err, "sending check.out.menu event failed"))
}
}()
return nil
},
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment