fix(mac): always run tray_update() on the main thread

This commit is contained in:
Andy Grundman authored and Dave Lane committed 2026-06-30 18:08:50 -04:00
1 parent f449b4a909
commit ae9efa8f55
1 file changed
+17 -8
+17 -8
View File
@@ -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)];
// 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];
// 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);
}
}