Notify of pokes and private messages on the desktop
While none of the client's windows has the focus, a poke or a private message shows a desktop notification, which the desktop's notification centre keeps. A private conversation keeps one notification, updated as messages come; clicking it brings the window forward with that chat open, and they all go once a window of the client is in front again. On Linux they go to the freedesktop.org notification service, spoken to over the session bus by a small D-Bus client of our own on Java's Unix sockets, so no library or native code is involved; Plasma also takes a reply typed into the notification. Elsewhere they are AWT tray messages, which Windows and macOS put in their notification centres. The options can turn them off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -21,6 +21,8 @@ public final class AwtTray implements TrayBackend {
|
||||
|
||||
private final TrayIcon icon;
|
||||
private final int size;
|
||||
/** What a click on the message last shown does, until it is used. */
|
||||
private volatile Runnable messageClick;
|
||||
|
||||
/**
|
||||
* @param menu the icon's context menu, or {@code null} to have right clicks
|
||||
@@ -64,9 +66,24 @@ public final class AwtTray implements TrayBackend {
|
||||
}
|
||||
}
|
||||
});
|
||||
// Fired by a click on a message (and on some desktops a double click on the icon).
|
||||
icon.addActionListener(e -> {
|
||||
Runnable click = messageClick;
|
||||
messageClick = null;
|
||||
if (click != null) click.run();
|
||||
});
|
||||
SystemTray.getSystemTray().add(icon);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a message by the icon, which Windows turns into a toast in its notification
|
||||
* centre and macOS into a banner in its own.
|
||||
*/
|
||||
public void showMessage(String title, String body, Runnable onClick) {
|
||||
messageClick = onClick;
|
||||
icon.displayMessage(title, body, TrayIcon.MessageType.NONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIcon(IntFunction<Image> render) {
|
||||
Image image = render.apply(size);
|
||||
|
||||
Reference in New Issue
Block a user