mirror of
https://github.com/LizardByte/tray.git
synced 2026-12-06 15:12:48 +09:00
fix(mac): always run tray_update() on the main thread
This commit is contained in:
1 parent
f449b4a909
commit
ae9efa8f55
1 file changed
+17
-8
+17
-8
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user