Files
Victor Lyuboslavsky 002c381c97 Refactored and fixed Fleet Desktop menu. (#31649)
Fixes #31129 

Also refactored some of the menu code into its own package with tests.

# Checklist for submitter
- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.

## Testing

- [x] Added/updated automated tests
- [x] QA'd all new/changed functionality manually

## fleetd/orbit/Fleet Desktop

- [x] Verified compatibility with the latest released version of Fleet
(see [Must
rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md))
- [x] Verified that fleetd runs on macOS, Linux and Windows
- [x] Verified auto-update works from the released version of component
to the new version (see [tools/tuf/test](../tools/tuf/test/README.md))


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* The "Self-service" option in the Fleet Desktop menu is now hidden when
the device is offline.

* **Refactor**
* The Fleet Desktop menu system has been restructured for improved
reliability and maintainability. Menu items are now managed through a
unified menu manager, resulting in a cleaner and more consistent user
experience.

* **New Features**
* Introduced a new menu manager to dynamically update menu items based
on connection status and device policies.
* Added a system tray menu factory for consistent menu item creation and
interaction.

* **Tests**
* Added comprehensive tests to ensure correct menu behavior and state
transitions.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-08-08 17:50:11 +02:00

38 lines
1.0 KiB
Go

package menu
import "fyne.io/systray"
// SystrayFactory implements Factory interface for the actual systray
type SystrayFactory struct{}
// Ensure SystrayFactory implements Factory
var _ Factory = &SystrayFactory{}
// NewSystrayFactory creates a new systray factory
func NewSystrayFactory() *SystrayFactory {
return &SystrayFactory{}
}
// AddMenuItem creates a new menu item using systray
func (s *SystrayFactory) AddMenuItem(title string, tooltip string) Item {
return &SystrayMenuItem{
MenuItem: systray.AddMenuItem(title, tooltip),
}
}
// AddSeparator adds a separator to the menu
func (s *SystrayFactory) AddSeparator() {
systray.AddSeparator()
}
// SystrayMenuItem is a thin wrapper around systray.MenuItem that adds the ClickedCh method
// This is needed because systray.MenuItem has ClickedCh as a field, not a method
type SystrayMenuItem struct {
*systray.MenuItem
}
// ClickedCh returns the channel that's notified when the menu item is clicked
func (s *SystrayMenuItem) ClickedCh() <-chan struct{} {
return s.MenuItem.ClickedCh
}