Simplified logic for initializing AWT and creating the tray on EDT (as necessary)
This commit is contained in:
parent
43c6c73ce3
commit
90df1d7eca
|
@ -967,24 +967,30 @@ class SystemTray {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isTrayType(trayType, TrayType.Swing) || isTrayType(trayType, TrayType.AWT) || isTrayType(trayType, TrayType.WindowsNotifyIcon)) {
|
||||||
|
// ensure AWT toolkit is initialized.
|
||||||
|
java.awt.Toolkit.getDefaultToolkit();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// javaFX and SWT **CAN NOT** start on the EDT!!
|
// javaFX and SWT **CAN NOT** start on the EDT!!
|
||||||
// linux + GTK/AppIndicator menus must not start on the EDT!
|
// linux + GTK/AppIndicator + windows-native menus must not start on the EDT!
|
||||||
systemTray = new SystemTray();
|
systemTray = new SystemTray();
|
||||||
|
|
||||||
// AWT/Swing must be constructed on the EDT however...
|
// AWT/Swing must be constructed on the EDT however...
|
||||||
if (JavaFX.isLoaded || Swt.isLoaded ||
|
if (JavaFX.isLoaded ||
|
||||||
(isNix && (isTrayType(trayType, TrayType.GtkStatusIcon) || isTrayType(trayType, TrayType.AppIndicator)))
|
Swt.isLoaded ||
|
||||||
) {
|
(isNix && (isTrayType(trayType, TrayType.GtkStatusIcon) || isTrayType(trayType, TrayType.AppIndicator))) ||
|
||||||
|
isTrayType(trayType, TrayType.WindowsNotifyIcon)) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
reference.set((Tray) trayType.getConstructors()[0].newInstance(systemTray));
|
reference.set((Tray) trayType.getConstructors()[0].newInstance(systemTray));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Unable to create tray type: '" + trayType.getSimpleName() + "'", e);
|
logger.error("Unable to create tray type: '" + trayType.getSimpleName() + "'", e);
|
||||||
}
|
}
|
||||||
} else if (isTrayType(trayType, TrayType.Swing) || isTrayType(trayType, TrayType.AWT)) {
|
}
|
||||||
// ensure AWT toolkit is initialized.
|
else if (isTrayType(trayType, TrayType.Swing) || isTrayType(trayType, TrayType.AWT)) {
|
||||||
java.awt.Toolkit.getDefaultToolkit();
|
|
||||||
|
|
||||||
// have to construct swing stuff inside the swing EDT
|
// have to construct swing stuff inside the swing EDT
|
||||||
final Class<? extends Menu> finalTrayType = trayType;
|
final Class<? extends Menu> finalTrayType = trayType;
|
||||||
SwingUtil.invokeAndWait(new Runnable() {
|
SwingUtil.invokeAndWait(new Runnable() {
|
||||||
|
@ -998,17 +1004,8 @@ class SystemTray {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (isTrayType(trayType, TrayType.WindowsNotifyIcon)) {
|
}
|
||||||
// ensure AWT toolkit is initialized.
|
else {
|
||||||
java.awt.Toolkit.getDefaultToolkit();
|
|
||||||
|
|
||||||
// difference from above, is we do not need to do anything inside the swing EDT
|
|
||||||
try {
|
|
||||||
reference.set((Tray) trayType.getConstructors()[0].newInstance(systemTray));
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("Unable to create tray type: '" + trayType.getSimpleName() + "'", e);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
logger.error("Unable to create tray type: '{}'. Aborting!", trayType.getSimpleName());
|
logger.error("Unable to create tray type: '{}'. Aborting!", trayType.getSimpleName());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user