macOS: activate correct object when using multiple QSystemTrayIcons
Since we need to set the delegate on the defaultUserNotificationCenter, which is a gobal object, we have to update the delegate when we show the message. Otherwise, the last delegate created and set will receive the notification, and the last QSystemTrayIcon created will emit the activated signal. Before clearing the delegate upon destruction, make sure that it's the right item first. Also updating coding style in the respective parts of the code, and plugging a memory leak. Change-Id: Ife62ae0776a5a610a6fd735b2959b807c3a410c7 Fixes: QTBUG-77003 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
907923b7ca
commit
de775f2e62
@ -118,11 +118,13 @@ class QSystemTrayIconSys
|
||||
public:
|
||||
QSystemTrayIconSys(QCocoaSystemTrayIcon *sys) {
|
||||
item = [[QNSStatusItem alloc] initWithSysTray:sys];
|
||||
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:item];
|
||||
NSUserNotificationCenter.defaultUserNotificationCenter.delegate = item;
|
||||
}
|
||||
~QSystemTrayIconSys() {
|
||||
[[[item item] view] setHidden: YES];
|
||||
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:nil];
|
||||
NSUserNotificationCenter *center = NSUserNotificationCenter.defaultUserNotificationCenter;
|
||||
if (center.delegate == item)
|
||||
center.delegate = nil;
|
||||
[item release];
|
||||
}
|
||||
QNSStatusItem *item;
|
||||
@ -277,7 +279,10 @@ void QCocoaSystemTrayIcon::showMessage(const QString &title, const QString &mess
|
||||
notification.contentImage = [nsimage autorelease];
|
||||
}
|
||||
|
||||
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
|
||||
NSUserNotificationCenter *center = NSUserNotificationCenter.defaultUserNotificationCenter;
|
||||
center.delegate = m_sys->item;
|
||||
[center deliverNotification:notification];
|
||||
[notification release];
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user