Skip to content

Commit

Permalink
Show the tray icon busy state
Browse files Browse the repository at this point in the history
  • Loading branch information
zapek committed Nov 16, 2024
1 parent cb6cf74 commit 31e5507
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions ui/src/main/java/io/xeres/ui/support/tray/TrayService.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class TrayService

private Image image;
private Image eventImage;
private Image busyImage;

private String tooltipTitle;

Expand Down Expand Up @@ -113,6 +114,7 @@ public void addSystemTray(String title)

image = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/image/trayicon.png"));
eventImage = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/image/trayicon_event.png"));
busyImage = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/image/trayicon_busy.png"));

tooltipTitle = title;
trayIcon = new TrayIcon(image, tooltipTitle, popupMenu);
Expand Down Expand Up @@ -238,6 +240,7 @@ private void setStatus(Availability availability)
if (availability != Availability.OFFLINE)
{
setStatusItemDisabled(statusMenu, availability.ordinal());
setBusy(availability == Availability.BUSY);
}
}

Expand Down Expand Up @@ -269,7 +272,7 @@ public void mouseReleased(MouseEvent e)
if (stage.isIconified())
{
stage.setIconified(false);
setEvent(false);
clearEvent();
}
else
{
Expand All @@ -287,7 +290,7 @@ public void mouseReleased(MouseEvent e)
stage.setWidth(stage.getWidth());
stage.setHeight(stage.getHeight());
stage.show();
setEvent(false);
clearEvent();
}
}
});
Expand Down Expand Up @@ -321,14 +324,32 @@ public void setTooltip(String message)
}
}

public void setEvent(boolean pending)
private void setBusy(boolean busy)
{
trayIcon.setImage(pending ? eventImage : image);
if (busy && trayIcon.getImage() != busyImage)
{
trayIcon.setImage(busyImage);
}
else if (!busy && trayIcon.getImage() != image)
{
trayIcon.setImage(image);
}
}

public void clearEvent()
{
if (trayIcon.getImage() != busyImage)
{
trayIcon.setImage(image);
}
}

public void setEventIfIconified()
{
trayIcon.setImage(eventImage);
if (trayIcon.getImage() != busyImage)
{
trayIcon.setImage(eventImage);
}
}

private boolean isNotificationAllowed(TrayNotificationType type)
Expand Down
Binary file added ui/src/main/resources/image/trayicon_busy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 31e5507

Please sign in to comment.