From 5fab671af371a1fc52ecf7527073676683c2034d Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Sat, 8 Oct 2022 07:45:29 +1100 Subject: [PATCH] Support Hidden attribute. Add SetTooltip & SetIcons to SystemTray. Add Show & Hide to menuItem --- v2/internal/platform/systray/menu.go | 3 +++ v2/pkg/application/systray.go | 18 ++++++++++++++++++ v2/pkg/menu/menuitem.go | 10 ++++++++++ 3 files changed, 31 insertions(+) diff --git a/v2/internal/platform/systray/menu.go b/v2/internal/platform/systray/menu.go index 1e15edbf5..057d5bf37 100644 --- a/v2/internal/platform/systray/menu.go +++ b/v2/internal/platform/systray/menu.go @@ -16,6 +16,9 @@ type PopupMenu struct { func (p *PopupMenu) buildMenu(parentMenu win32.PopupMenu, inputMenu *menu.Menu, startindex int) error { for index, item := range inputMenu.Items { + if item.Hidden { + continue + } var ret bool itemID := index + startindex flags := win32.MF_STRING diff --git a/v2/pkg/application/systray.go b/v2/pkg/application/systray.go index ba52d097c..00965e41f 100644 --- a/v2/pkg/application/systray.go +++ b/v2/pkg/application/systray.go @@ -77,3 +77,21 @@ func (t *SystemTray) Update() error { } return nil } + +func (t *SystemTray) SetTooltip(s string) { + if t.impl != nil { + t.impl.SetTooltip(s) + } else { + t.tooltip = s + } +} + +func (t *SystemTray) SetIcons(lightModeIcon *options.SystemTrayIcon, darkModeIcon *options.SystemTrayIcon) { + if t.impl != nil { + t.impl.SetIcons(lightModeIcon, darkModeIcon) + } else { + t.lightModeIcon = lightModeIcon + t.darkModeIcon = darkModeIcon + } + +} diff --git a/v2/pkg/menu/menuitem.go b/v2/pkg/menu/menuitem.go index 6ab928857..013eb6bf2 100644 --- a/v2/pkg/menu/menuitem.go +++ b/v2/pkg/menu/menuitem.go @@ -257,6 +257,16 @@ func (m *MenuItem) SetChecked(value bool) *MenuItem { return m } +func (m *MenuItem) Hide() *MenuItem { + m.Hidden = true + return m +} + +func (m *MenuItem) Show() *MenuItem { + m.Hidden = false + return m +} + func Label(label string) *MenuItem { return &MenuItem{ Type: TextType,