asticode / go-astilectron-bootstrap

Create a one-window application using Astilectron

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Kill a Menu and set new

Fruchtgummi opened this issue · comments

Hi,

i use bootstrap and I want to switch between languages.

var ( AppName string = "Appname" BuiltAt string debug = flag.Bool("d", false, "enables the debug mode") w *astilectron.Window m *astilectron.Menu )

and the Menu-snipped

`
//my menu for switch

		{
			Label: astilectron.PtrStr(l["language"]),
			SubMenu: func() []*astilectron.MenuItemOptions {

				o := make([]*astilectron.MenuItemOptions, 0, len(langs))
				for n, lang := range langs {
					name := n
					o = append(o, &astilectron.MenuItemOptions{
						Label:   astilectron.PtrStr(lang["#name"]),
						Type:    astilectron.MenuItemTypeRadio,
						Checked: astilectron.PtrBool(lang["#name"] == l["#name"]),
						OnClick: func(e astilectron.Event) bool {
							l = langs[name]
                                                            m.Destroy() //kill menu
                                                            builtMenu()
							return false
						},
					})
				}
				sort.Slice(o, func(i, j int) bool {
					return strings.Compare(*o[i].Label, *o[j].Label) < 0
				})
				return o
			}(),
		},

`

I wand Destroy and rebuild the Menu.

ERROR: Uncaught Exception: Error: read ECONNRESET at exports._errnorException (util.js1024:11) at TCP.onread (net.js610:25)

@Fruchtgummi here's what you need to do:

  • capture the *astilectron.Astilectron in the OnWait function into an a global variable for instance
  • update the OnClick listener so that it looks like:
OnClick: func(e astilectron.Event) bool {
  l = langs[name]
  m.Destroy() / /kill menu
  m = a.NewMenu(builtMenu())
  m.Create()
  return false
},

In that case builtMenu() has to return a []*astilectron.MenuItemOptions.

Let me know how it goes.

Cheers

`panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x666c31]

goroutine 16 [running]:
github.com/asticode/go-astilectron.(*Menu).Destroy(0x0, 0xc0420fe090, 0xc04217fe80)
C:/goworkspace/src/github.com/asticode/go-astilectron/menu.go:52 +0x41
main.buildMenu.func4.1(0xc04200b900, 0x17, 0xc04200dbb8, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc0420e4d20, ...)
C:/goworkspace/src/PromilloV2/main.go:240 +0x8d
github.com/asticode/go-astilectron.(*dispatcher).dispatch.func1(0xc0420bdee0, 0xc042068a50)
C:/goworkspace/src/github.com/asticode/go-astilectron/dispatcher.go:62 +0x128
created by github.com/asticode/go-astilectron.(*dispatcher).dispatch
C:/goworkspace/src/github.com/asticode/go-astilectron/dispatcher.go:60 +0x92
Fehler: Prozess beendet mit Rückgabewert 2.`

Ok it's running...

update the onwait()

OnWait: func(_ *astilectron.Astilectron, iw *astilectron.Window, imm *astilectron.Menu, _ *astilectron.Tray, im *astilectron.Menu) error { w = iw mm = imm 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 { astilog.Error(errors.Wrap(err, "sending check.out.menu event failed")) } }() return nil },