5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-21 19:39:29 +08:00

tray menu Icon->Image. Support template images.

This commit is contained in:
Lea Anthony 2021-03-17 22:24:09 +11:00
parent 237d25089d
commit c7dee158ba
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405
4 changed files with 28 additions and 15 deletions

View File

@ -31,7 +31,8 @@ TrayMenu* NewTrayMenu(const char* menuJSON) {
result->ID = mustJSONString(processedJSON, "ID");
result->label = mustJSONString(processedJSON, "Label");
result->icon = mustJSONString(processedJSON, "Icon");
result->icon = mustJSONString(processedJSON, "Image");
getJSONBool(processedJSON, "MacTemplateImage", &result->templateImage);
JsonNode* processedMenu = mustJSONObject(processedJSON, "ProcessedMenu");
// Create the menu
@ -89,6 +90,10 @@ void UpdateTrayIcon(TrayMenu *trayMenu) {
id imageData = msg(data, s("initWithBase64EncodedString:options:"), str(trayMenu->icon), 0);
trayImage = ALLOC("NSImage");
msg(trayImage, s("initWithData:"), imageData);
if( trayMenu->templateImage ) {
msg(trayImage, s("setTemplate:"), YES);
}
}
msg(statusBarButton, s("setImagePosition:"), trayMenu->trayIconPosition);

View File

@ -14,6 +14,8 @@ typedef struct {
const char *icon;
const char *ID;
bool templateImage;
Menu* menu;
id statusbaritem;

View File

@ -23,13 +23,14 @@ func generateTrayID() string {
}
type TrayMenu struct {
ID string
Label string
Icon string
menuItemMap *MenuItemMap
menu *menu.Menu
ProcessedMenu *WailsMenu
trayMenu *menu.TrayMenu
ID string
Label string
Image string
MacTemplateImage bool
menuItemMap *MenuItemMap
menu *menu.Menu
ProcessedMenu *WailsMenu
trayMenu *menu.TrayMenu
}
func (t *TrayMenu) AsJSON() (string, error) {
@ -43,11 +44,12 @@ func (t *TrayMenu) AsJSON() (string, error) {
func NewTrayMenu(trayMenu *menu.TrayMenu) *TrayMenu {
result := &TrayMenu{
Label: trayMenu.Label,
Icon: trayMenu.Icon,
menu: trayMenu.Menu,
menuItemMap: NewMenuItemMap(),
trayMenu: trayMenu,
Label: trayMenu.Label,
Image: trayMenu.Image,
MacTemplateImage: trayMenu.MacTemplateImage,
menu: trayMenu.Menu,
menuItemMap: NewMenuItemMap(),
trayMenu: trayMenu,
}
result.menuItemMap.AddMenu(trayMenu.Menu)

View File

@ -6,11 +6,15 @@ type TrayMenu struct {
// Label is the text we wish to display in the tray
Label string
// Icon is the name of the tray icon we wish to display.
// Image is the name of the tray icon we wish to display.
// These are read up during build from <projectdir>/trayicons and
// the filenames are used as IDs, minus the extension
// EG: <projectdir>/trayicons/main.png can be referenced here with "main"
Icon string
// If the image is not a filename, it will be treated as base64 image data
Image string
// MacTemplateImage indicates that on a Mac, this image is a template image
MacTemplateImage bool
// Menu is the initial menu we wish to use for the tray
Menu *Menu