Desktop: no exceptions when servers report leaving after shutdown

Quitting from the shutdown hook (SIGTERM) leaves every server, whose
disconnects then reach the mic hand-over and the notifier after their
threads have stopped. Both now drop work that comes in that late.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-14 20:30:11 +00:00
co-authored by Claude Opus 5.5
parent e9110c2767
commit 0043c03410
2 changed files with 32 additions and 7 deletions
@@ -19,6 +19,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.RejectedExecutionException;
/**
* Tells the user about pokes and private messages through the desktop's notifications
@@ -66,7 +67,7 @@ public final class DesktopNotifier {
if (!wanted()) return;
String body = BBCode.toPlain(message);
Notice notice = new Notice(from + " poked you", body, () -> open(tab, null), null);
worker.execute(() -> {
later(() -> {
DesktopNotifications out = backend();
if (out == null) return;
int id = out.show(notice, 0);
@@ -78,7 +79,7 @@ public final class DesktopNotifier {
if (!wanted()) return;
String text = ChatHtml.plainMessage(message);
Conversation key = new Conversation(tab, clientId);
worker.execute(() -> {
later(() -> {
DesktopNotifications out = backend();
if (out == null) return;
Shown shown = conversations.computeIfAbsent(key, k -> new Shown());
@@ -92,7 +93,7 @@ public final class DesktopNotifier {
/** The window is in front again: what was notified of is in plain sight. */
void windowActivated() {
worker.execute(() -> {
later(() -> {
if (backend == null) return;
conversations.values().forEach(shown -> backend.close(shown.id));
conversations.clear();
@@ -103,7 +104,7 @@ public final class DesktopNotifier {
/** A private chat on a server that went away can neither be opened nor answered. */
void forget(ServerTab tab) {
worker.execute(() -> conversations.entrySet().removeIf(e -> {
later(() -> conversations.entrySet().removeIf(e -> {
if (e.getKey().tab() != tab) return false;
if (backend != null) backend.close(e.getValue().id);
return true;
@@ -111,12 +112,23 @@ public final class DesktopNotifier {
}
void shutdown() {
worker.execute(() -> {
later(() -> {
if (backend != null) backend.shutdown();
});
worker.shutdown();
}
/**
* Runs on the worker. The frame may still pass on a server's disconnect after
* {@link #shutdown}, once the worker is gone; nothing is shown any more by then.
*/
private void later(Runnable task) {
try {
worker.execute(task);
} catch (RejectedExecutionException ignored) {
}
}
private boolean wanted() {
// Some window of ours has the focus exactly when there is an active window.
return settings.desktopNotifications.get()