Skip to content

Commit

Permalink
Catch exception at the SystemTray.isSupported call and creating the A…
Browse files Browse the repository at this point in the history
…wtNotificationDelegate. Seems either SystemTray.isSupported throws or returns true but AwtNotificationDelegate fails then.
  • Loading branch information
HenrikJannsen committed Sep 29, 2024
1 parent 9d0091e commit 70c7b09
Showing 1 changed file with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
import bisq.settings.SettingsService;
import lombok.extern.slf4j.Slf4j;

import java.awt.*;
import java.awt.SystemTray;
import java.nio.file.Path;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;

@Slf4j
Expand Down Expand Up @@ -55,20 +56,32 @@ public CompletableFuture<Boolean> shutdown() {

public void show(Notification notification) {
if (isInitialized) {
getDelegate().show(notification.getTitle(), notification.getMessage());
getDelegate().ifPresent(delegate -> delegate.show(notification.getTitle(), notification.getMessage()));
}
}

private SystemNotificationDelegate getDelegate() {
private Optional<SystemNotificationDelegate> getDelegate() {
if (delegate == null) {
if (OS.isLinux() && LinuxNotificationDelegate.isSupported()) {
delegate = new LinuxNotificationDelegate(baseDir, settingsService);
} else if (OS.isMacOs() && OsxNotificationDelegate.isSupported()) {
delegate = new OsxNotificationDelegate();
} else if (SystemTray.isSupported()) {
delegate = new AwtNotificationDelegate();
} else {
boolean supported = false;
try {
supported = SystemTray.isSupported();
} catch (Exception e) {
log.warn("SystemTray.isSupported call failed", e);
}
try {
if (supported) {
delegate = new AwtNotificationDelegate();
}
} catch (Exception e) {
log.warn("Creating AwtNotificationDelegate failed, even SystemTray.isSupported() returned true", e);
}
}
}
return delegate;
return Optional.ofNullable(delegate);
}
}

0 comments on commit 70c7b09

Please sign in to comment.