Skip to content

[v3] How to update the menu label in real time when the tray is open? #4630

@learning-go123

Description

@learning-go123

Calling menu.Update() doesn't re-render the UI in real time. It only changes when I reopen the System Tray menu. I'm not sure if this is due to my incorrect usage.

	app := application.New(application.Options{
		Name:        "Systray Demo",
		Description: "A demo of the Systray API",
	})

	systemTray := app.SystemTray.New()
	if runtime.GOOS == "darwin" {
		systemTray.SetTemplateIcon(icons.SystrayMacTemplate)
	}
	myMenu := app.NewMenu()
	loading := myMenu.Add("loading...")
	systemTray.SetMenu(myMenu)

	go func() {
		for i := 0; i <= 100; i++ {
			time.Sleep(1 * time.Second)
			loading.SetLabel("Loading " + strconv.Itoa(i))
			myMenu.Update()
		}
	}()

	err := app.Run()
	if err != nil {
		log.Fatal(err)
	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions