Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions src/tray_darwin.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,24 @@ int tray_loop(int blocking) {
}

void tray_update(struct tray *tray) {
NSImage *image = [[NSImage alloc] initWithContentsOfFile:[NSString stringWithUTF8String:tray->icon]];
NSSize size = NSMakeSize(16, 16);
[image setSize:NSMakeSize(16, 16)];
statusItem.button.image = image;
[statusItem setMenu:_tray_menu(tray->menu)];

// Set tooltip if provided
if (tray->tooltip != NULL) {
statusItem.button.toolTip = [NSString stringWithUTF8String:tray->tooltip];
// This must run on the main thread
void (^updateBlock)(void) = ^{
NSImage *image = [[NSImage alloc] initWithContentsOfFile:[NSString stringWithUTF8String:tray->icon]];
NSSize size = NSMakeSize(16, 16);
[image setSize:NSMakeSize(16, 16)];
statusItem.button.image = image;
[statusItem setMenu:_tray_menu(tray->menu)];

// Set tooltip if provided
if (tray->tooltip != NULL) {
statusItem.button.toolTip = [NSString stringWithUTF8String:tray->tooltip];
}
};

if ([NSThread isMainThread]) {
updateBlock();
} else {
dispatch_sync(dispatch_get_main_queue(), updateBlock);
}
}

Expand Down
Loading