fyne icon indicating copy to clipboard operation
fyne copied to clipboard

Race condition during system tray menu refresh

Open gabe565 opened this issue 11 months ago • 0 comments

Checklist

  • [X] I have searched the issue tracker for open issues that relate to the same problem, before opening a new one.
  • [X] 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

gabe565 avatar Mar 04 '24 03:03 gabe565