diff --git a/platform/darwin/tray.m b/platform/darwin/tray.m index c4112df..0c3e21c 100644 --- a/platform/darwin/tray.m +++ b/platform/darwin/tray.m @@ -1,6 +1,7 @@ #import NSMenu * appMenu; +NSStatusItem * appStatusItem; char * clipboardString; extern void tray_callback(int itemId); @@ -8,6 +9,8 @@ extern void notification_callback(); extern struct image invert_png_image(struct image img); +void set_status_item_icon(struct image img); + @interface ManageHandler : NSObject - (void)manage:(id)sender; - (BOOL)validateMenuItem:(NSMenuItem *)menuItem; @@ -112,6 +115,16 @@ int init(const char * title, struct image img) { [self userNotificationCenter: nil didActivateNotification: launchNotification]; }*/ + appStatusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain]; + [appStatusItem setMenu:appMenu]; + [appStatusItem setHighlightMode:YES]; + [appStatusItem setToolTip:[NSString stringWithUTF8String:title]]; + set_status_item_icon(img); + + return 0; +} + +void set_status_item_icon(struct image img) { NSSize iconSize = NSMakeSize(16, 16); NSImage * icon = [[NSImage alloc] initWithSize:iconSize]; NSData * iconData = [NSData dataWithBytes:img.bytes length:img.length]; @@ -123,14 +136,8 @@ int init(const char * title, struct image img) { NSData * icon2Data = [NSData dataWithBytes:img.bytes length:img.length]; [icon2 addRepresentation:[NSBitmapImageRep imageRepWithData:icon2Data]]; - NSStatusItem * statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain]; - [statusItem setMenu:appMenu]; - [statusItem setImage:icon]; - [statusItem setAlternateImage:icon2]; - [statusItem setHighlightMode:YES]; - [statusItem setToolTip:[NSString stringWithUTF8String:title]]; - - return 0; + [appStatusItem setImage:icon]; + [appStatusItem setAlternateImage:icon2]; } void set_clipboard_string(const char * string) { diff --git a/platform/linux/tray.c b/platform/linux/tray.c index 4e9f286..f35d789 100644 --- a/platform/linux/tray.c +++ b/platform/linux/tray.c @@ -34,6 +34,9 @@ void display_notification(int id, const char* title, const char* body, struct im // TODO: Implement. void clear_menu_items() {} +// TODO: Implement. +void set_status_item_icon(struct image img) {} + // TODO: Implement. struct clipboard_content get_clipboard_content() { diff --git a/platform/windows/tray.c b/platform/windows/tray.c index 104728a..fb3e920 100644 --- a/platform/windows/tray.c +++ b/platform/windows/tray.c @@ -225,3 +225,7 @@ struct clipboard_content get_clipboard_content() { void display_notification(int notificationId, const char * title, const char * body, struct image img, double timeout) { // TODO: Implement. } + +// TODO: Implement. +void set_status_item_icon(struct image img) {} + diff --git a/trayhost.go b/trayhost.go index 928be1a..e94fe94 100644 --- a/trayhost.go +++ b/trayhost.go @@ -56,6 +56,13 @@ func Initialize(title string, imageData []byte, items []MenuItem) { } } +// SetStatusIcon replaces the icon image data. +func SetStatusIcon(imageData []byte) { + img, freeImg := create_image(Image{Kind: "png", Bytes: imageData}) + defer freeImg() + C.set_status_item_icon(img) +} + // EnterLoop enters main loop. func EnterLoop() { C.native_loop() diff --git a/trayhost_exports.go b/trayhost_exports.go index ef195a2..0cbf0a1 100644 --- a/trayhost_exports.go +++ b/trayhost_exports.go @@ -92,7 +92,10 @@ func invertPngImage(imageData []byte) []byte { panic(err) } - invertImageNrgba(m.(*image.NRGBA)) + switch m.(type) { + case *image.NRGBA: + invertImageNrgba(m.(*image.NRGBA)) + } var buf bytes.Buffer err = png.Encode(&buf, m)