From d1c3f8af7a21f694f1296c7f4315153ab66f7ca9 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Sun, 22 Oct 2023 14:34:04 +1100 Subject: [PATCH] [darwin] Fix menu icon --- v3/examples/binding/go.mod | 2 +- v3/examples/binding/go.sum | 1 + v3/examples/dev/go.mod | 2 +- v3/examples/dev/go.sum | 1 + v3/examples/frameless/go.mod | 2 +- v3/examples/frameless/go.sum | 1 + v3/examples/plugins/go.mod | 2 +- v3/examples/plugins/go.sum | 1 + v3/examples/server/go.mod | 2 +- v3/examples/server/go.sum | 1 + v3/pkg/application/menu_darwin.go | 4 +++- v3/pkg/application/menuitem_darwin.go | 2 +- 12 files changed, 14 insertions(+), 7 deletions(-) diff --git a/v3/examples/binding/go.mod b/v3/examples/binding/go.mod index 6c100a63..f89872e2 100644 --- a/v3/examples/binding/go.mod +++ b/v3/examples/binding/go.mod @@ -36,7 +36,7 @@ require ( github.com/samber/lo v1.38.1 // indirect github.com/sergi/go-diff v1.2.0 // indirect github.com/stretchr/testify v1.8.4 // indirect - github.com/wailsapp/go-webview2 v1.0.8 // indirect + github.com/wailsapp/go-webview2 v1.0.9 // indirect github.com/wailsapp/mimetype v1.4.1 // indirect github.com/xanzy/ssh-agent v0.3.0 // indirect golang.org/x/crypto v0.9.0 // indirect diff --git a/v3/examples/binding/go.sum b/v3/examples/binding/go.sum index 6569d45a..c65cbb6d 100644 --- a/v3/examples/binding/go.sum +++ b/v3/examples/binding/go.sum @@ -107,6 +107,7 @@ github.com/tmclane/purego v0.0.0-20230601213035-1f25e70d7b01 h1:oQwu3iNDywGp1Hry github.com/tmclane/purego v0.0.0-20230601213035-1f25e70d7b01/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ= github.com/wailsapp/go-webview2 v1.0.8 h1:hyoFPlMSfb/NM64wuVbgBaq1MASJjqsSUYhN+Rbcr9Y= github.com/wailsapp/go-webview2 v1.0.8/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo= +github.com/wailsapp/go-webview2 v1.0.9/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo= github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs= github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4XlAL3U+j3o= github.com/xanzy/ssh-agent v0.3.0 h1:wUMzuKtKilRgBAD1sUb8gOwwRr2FGoBVumcjoOACClI= diff --git a/v3/examples/dev/go.mod b/v3/examples/dev/go.mod index 2122e235..a4b028b7 100644 --- a/v3/examples/dev/go.mod +++ b/v3/examples/dev/go.mod @@ -33,7 +33,7 @@ require ( github.com/samber/lo v1.38.1 // indirect github.com/sergi/go-diff v1.2.0 // indirect github.com/stretchr/testify v1.8.4 // indirect - github.com/wailsapp/go-webview2 v1.0.8 // indirect + github.com/wailsapp/go-webview2 v1.0.9 // indirect github.com/wailsapp/mimetype v1.4.1 // indirect github.com/xanzy/ssh-agent v0.3.0 // indirect golang.org/x/crypto v0.9.0 // indirect diff --git a/v3/examples/dev/go.sum b/v3/examples/dev/go.sum index 6b30d677..ab2b768d 100644 --- a/v3/examples/dev/go.sum +++ b/v3/examples/dev/go.sum @@ -107,6 +107,7 @@ github.com/wailsapp/go-webview2 v1.0.7 h1:s95+7irJsAsTy1RsjJ6N0cYX7tZ4gP7Uzawds0 github.com/wailsapp/go-webview2 v1.0.7/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo= github.com/wailsapp/go-webview2 v1.0.8-0.20231010092311-42cbb98eb53b/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo= github.com/wailsapp/go-webview2 v1.0.8/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo= +github.com/wailsapp/go-webview2 v1.0.9/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo= github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs= github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4XlAL3U+j3o= github.com/xanzy/ssh-agent v0.3.0 h1:wUMzuKtKilRgBAD1sUb8gOwwRr2FGoBVumcjoOACClI= diff --git a/v3/examples/frameless/go.mod b/v3/examples/frameless/go.mod index 993f2633..bd4ee919 100644 --- a/v3/examples/frameless/go.mod +++ b/v3/examples/frameless/go.mod @@ -33,7 +33,7 @@ require ( github.com/rivo/uniseg v0.4.4 // indirect github.com/samber/lo v1.38.1 // indirect github.com/sergi/go-diff v1.2.0 // indirect - github.com/wailsapp/go-webview2 v1.0.8 // indirect + github.com/wailsapp/go-webview2 v1.0.9 // indirect github.com/wailsapp/mimetype v1.4.1 // indirect github.com/xanzy/ssh-agent v0.3.0 // indirect golang.org/x/crypto v0.9.0 // indirect diff --git a/v3/examples/frameless/go.sum b/v3/examples/frameless/go.sum index 1f616510..9147345a 100644 --- a/v3/examples/frameless/go.sum +++ b/v3/examples/frameless/go.sum @@ -101,6 +101,7 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/wailsapp/go-webview2 v1.0.8 h1:hyoFPlMSfb/NM64wuVbgBaq1MASJjqsSUYhN+Rbcr9Y= github.com/wailsapp/go-webview2 v1.0.8/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo= +github.com/wailsapp/go-webview2 v1.0.9/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo= github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs= github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4XlAL3U+j3o= github.com/xanzy/ssh-agent v0.3.0 h1:wUMzuKtKilRgBAD1sUb8gOwwRr2FGoBVumcjoOACClI= diff --git a/v3/examples/plugins/go.mod b/v3/examples/plugins/go.mod index e5194639..f96af757 100644 --- a/v3/examples/plugins/go.mod +++ b/v3/examples/plugins/go.mod @@ -40,7 +40,7 @@ require ( github.com/samber/lo v1.38.1 // indirect github.com/sergi/go-diff v1.2.0 // indirect github.com/stretchr/testify v1.8.4 // indirect - github.com/wailsapp/go-webview2 v1.0.8 // indirect + github.com/wailsapp/go-webview2 v1.0.9 // indirect github.com/wailsapp/mimetype v1.4.1 // indirect github.com/xanzy/ssh-agent v0.3.0 // indirect golang.org/x/crypto v0.9.0 // indirect diff --git a/v3/examples/plugins/go.sum b/v3/examples/plugins/go.sum index c8f278d4..0671c68c 100644 --- a/v3/examples/plugins/go.sum +++ b/v3/examples/plugins/go.sum @@ -118,6 +118,7 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/wailsapp/go-webview2 v1.0.8 h1:hyoFPlMSfb/NM64wuVbgBaq1MASJjqsSUYhN+Rbcr9Y= github.com/wailsapp/go-webview2 v1.0.8/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo= +github.com/wailsapp/go-webview2 v1.0.9/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo= github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs= github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4XlAL3U+j3o= github.com/xanzy/ssh-agent v0.3.0 h1:wUMzuKtKilRgBAD1sUb8gOwwRr2FGoBVumcjoOACClI= diff --git a/v3/examples/server/go.mod b/v3/examples/server/go.mod index 96ae314c..0f7a3a9b 100644 --- a/v3/examples/server/go.mod +++ b/v3/examples/server/go.mod @@ -35,7 +35,7 @@ require ( github.com/samber/lo v1.38.1 // indirect github.com/sergi/go-diff v1.2.0 // indirect github.com/stretchr/testify v1.8.4 // indirect - github.com/wailsapp/go-webview2 v1.0.8 // indirect + github.com/wailsapp/go-webview2 v1.0.9 // indirect github.com/wailsapp/mimetype v1.4.1 // indirect github.com/xanzy/ssh-agent v0.3.0 // indirect golang.org/x/crypto v0.9.0 // indirect diff --git a/v3/examples/server/go.sum b/v3/examples/server/go.sum index 6b30d677..ab2b768d 100644 --- a/v3/examples/server/go.sum +++ b/v3/examples/server/go.sum @@ -107,6 +107,7 @@ github.com/wailsapp/go-webview2 v1.0.7 h1:s95+7irJsAsTy1RsjJ6N0cYX7tZ4gP7Uzawds0 github.com/wailsapp/go-webview2 v1.0.7/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo= github.com/wailsapp/go-webview2 v1.0.8-0.20231010092311-42cbb98eb53b/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo= github.com/wailsapp/go-webview2 v1.0.8/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo= +github.com/wailsapp/go-webview2 v1.0.9/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo= github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs= github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4XlAL3U+j3o= github.com/xanzy/ssh-agent v0.3.0 h1:wUMzuKtKilRgBAD1sUb8gOwwRr2FGoBVumcjoOACClI= diff --git a/v3/pkg/application/menu_darwin.go b/v3/pkg/application/menu_darwin.go index 0bea925b..1c9c98e1 100644 --- a/v3/pkg/application/menu_darwin.go +++ b/v3/pkg/application/menu_darwin.go @@ -9,6 +9,7 @@ package application #include "menuitem_darwin.h" extern void setMenuItemChecked(void*, unsigned int, bool); +extern void setMenuItemBitmap(void*, unsigned char*, int); // Clear and release all menu items in the menu void clearMenu(void* nsMenu) { @@ -101,7 +102,8 @@ func (m *macosMenu) processMenu(parent unsafe.Pointer, menu *Menu) { C.addMenuSeparator(parent) } if item.bitmap != nil { - C.setMenuItemBitmap(item.impl, (*C.uchar)(&item.bitmap[0]), C.int(len(item.bitmap))) + macMenuItem := item.impl.(*macosMenuItem) + C.setMenuItemBitmap(macMenuItem.nsMenuItem, (*C.uchar)(&item.bitmap[0]), C.int(len(item.bitmap))) } } diff --git a/v3/pkg/application/menuitem_darwin.go b/v3/pkg/application/menuitem_darwin.go index f8e8fb0f..2093d15f 100644 --- a/v3/pkg/application/menuitem_darwin.go +++ b/v3/pkg/application/menuitem_darwin.go @@ -332,7 +332,7 @@ static void showAll(void) { [[NSApplication sharedApplication] unhideAllApplications:nil]; } -static void setMenuItemBitmap(void* nsMenuItem, unsigned char *bitmap, int length) { +void setMenuItemBitmap(void* nsMenuItem, unsigned char *bitmap, int length) { MenuItem *menuItem = (MenuItem *)nsMenuItem; NSImage *image = [[NSImage alloc] initWithData:[NSData dataWithBytes:bitmap length:length]]; [menuItem setImage:image];