Skip to content

Commit

Permalink
Merge pull request #2872 from HenrikJannsen/fix-exception-when-system…
Browse files Browse the repository at this point in the history
…-tray-is-not-supported

Fix exception when SystemTray is not supported
  • Loading branch information
HenrikJannsen authored Sep 29, 2024
2 parents 9d0091e + 70c7b09 commit 87483b7
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 87483b7

Please sign in to comment.