mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 22:55:48 +01:00
Refactor radio item management in handleMenuItemClick to prevent unnecessary state updates during radio group changes
This commit is contained in:
parent
5f6d40c881
commit
c3e06aeb83
4 changed files with 31 additions and 14 deletions
|
|
@ -22,6 +22,8 @@ import (
|
|||
"github.com/wailsapp/wails/v2/pkg/menu"
|
||||
)
|
||||
|
||||
var radioUpdating bool
|
||||
|
||||
func GtkMenuItemWithLabel(label string) *C.GtkWidget {
|
||||
cLabel := C.CString(label)
|
||||
result := C.gtk_menu_item_new_with_label(cLabel)
|
||||
|
|
@ -90,12 +92,16 @@ func handleMenuItemClick(gtkWidget unsafe.Pointer) {
|
|||
C.unblockClick(gtkRadioItem, handler)
|
||||
}
|
||||
}
|
||||
radioUpdating = true
|
||||
updateRadio(appMenuCache)
|
||||
updateRadio(trayMenuCache)
|
||||
radioUpdating = false
|
||||
item.Checked = true
|
||||
go item.Click(&menu.CallbackData{MenuItem: item})
|
||||
} else {
|
||||
item.Checked = false
|
||||
if !radioUpdating {
|
||||
item.Checked = false
|
||||
}
|
||||
}
|
||||
default:
|
||||
go item.Click(&menu.CallbackData{MenuItem: item})
|
||||
|
|
|
|||
|
|
@ -968,6 +968,10 @@ void TraySetSystemTray(GtkWindow *window, const char *label, const guchar *image
|
|||
else
|
||||
{
|
||||
unlink(filename);
|
||||
if (indicator_temp_icon_path == filename)
|
||||
{
|
||||
indicator_temp_icon_path = NULL;
|
||||
}
|
||||
g_free(filename);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -433,9 +433,10 @@ func (w *Window) TraySetSystemTray(trayMenu *menu.TrayMenu) {
|
|||
func (w *Window) loadTrayIcon(image string) (w32.HICON, error) {
|
||||
if _, err := os.Stat(image); err == nil {
|
||||
ico, err := winc.NewIconFromFile(image)
|
||||
if err == nil {
|
||||
return w32.HICON(ico.Handle()), nil
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to load icon from file %q: %w", image, err)
|
||||
}
|
||||
return w32.HICON(ico.Handle()), nil
|
||||
}
|
||||
|
||||
data, err := base64.StdEncoding.DecodeString(image)
|
||||
|
|
|
|||
|
|
@ -40,17 +40,19 @@ type Experimental struct{}
|
|||
|
||||
// App contains options for creating the App
|
||||
type App struct {
|
||||
Title string
|
||||
Width int
|
||||
Height int
|
||||
DisableResize bool
|
||||
Fullscreen bool
|
||||
Frameless bool
|
||||
MinWidth int
|
||||
MinHeight int
|
||||
MaxWidth int
|
||||
MaxHeight int
|
||||
StartHidden bool
|
||||
Title string
|
||||
Width int
|
||||
Height int
|
||||
DisableResize bool
|
||||
Fullscreen bool
|
||||
Frameless bool
|
||||
MinWidth int
|
||||
MinHeight int
|
||||
MaxWidth int
|
||||
MaxHeight int
|
||||
StartHidden bool
|
||||
// HideWindowOnClose is deprecated. Use WindowCloseBehaviour instead.
|
||||
// If set to true, WindowCloseBehaviour will be set to HideWindow if it is currently CloseWindow.
|
||||
HideWindowOnClose bool
|
||||
WindowCloseBehaviour WindowCloseBehaviour
|
||||
AlwaysOnTop bool
|
||||
|
|
@ -187,6 +189,10 @@ func MergeDefaults(appoptions *App) {
|
|||
}
|
||||
}
|
||||
|
||||
if appoptions.HideWindowOnClose && appoptions.WindowCloseBehaviour == CloseWindow {
|
||||
appoptions.WindowCloseBehaviour = HideWindow
|
||||
}
|
||||
|
||||
// Ensure max and min are valid
|
||||
processMinMaxConstraints(appoptions)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue