Skip to content

Race condition during system tray menu refresh #4697

Closed
@gabe565

Description

Checklist

  • I have searched the issue tracker for open issues that relate to the same problem, before opening a new one.
  • This issue only relates to a single bug. I will open new issues for any other problems.

Describe the bug

Hello! I am porting a systray application to fyne, and I believe I have found a race condition. If an application refreshes the system tray menu from a Goroutine, menu items can be duplicated.

How to reproduce

  1. Create an application with a system tray menu.
  2. Add a lifecycle hook which refreshes the menu from a Goroutine (see example code)
  3. When run, menu items will be duplicated.

Screenshots

image

Example code

package main

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/driver/desktop"
)

func main() {
	a := app.New()

	if desk, ok := a.(desktop.App); ok {
		m := fyne.NewMenu("MyApp",
			fyne.NewMenuItem("Example", nil),
		)
		desk.SetSystemTrayMenu(m)
		a.Lifecycle().SetOnStarted(func() {
			go func() {
				m.Refresh()
			}()
		})
	}

	a.Run()
}

Fyne version

2.4.4

Go compiler version

1.22.0

Operating system and version

macOS Sonoma

Additional Information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    unverifiedA bug that has been reported but not verified

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions