From f0353c8c72738647647e8793bf601a6f70aecbfa Mon Sep 17 00:00:00 2001 From: kske Date: Sat, 14 Dec 2019 14:17:24 +0100 Subject: [PATCH] Added background execution --- src/main/java/envoy/client/ui/Startup.java | 6 +++++- src/main/java/envoy/client/ui/StatusTrayIcon.java | 11 +++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/envoy/client/ui/Startup.java b/src/main/java/envoy/client/ui/Startup.java index 933890d..53cbbc0 100644 --- a/src/main/java/envoy/client/ui/Startup.java +++ b/src/main/java/envoy/client/ui/Startup.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; +import javax.swing.JFrame; import javax.swing.JOptionPane; import envoy.client.Client; @@ -84,7 +85,7 @@ public class Startup { throw new EnvoyException("Could not enter offline mode: user name unknown"); client.setSender(clientUser); } catch(Exception e2) { - JOptionPane.showMessageDialog(null, e1.toString(), "Client error", JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(null, e2.toString(), "Client error", JOptionPane.ERROR_MESSAGE); System.exit(1); return; } @@ -118,6 +119,9 @@ public class Startup { try { new StatusTrayIcon(chatWindow).show(); + + // If the tray icon is supported, hide the chat window on close + chatWindow.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); } catch (EnvoyException e) { logger.warning("The StatusTrayIcon is not supported on this platform!"); } diff --git a/src/main/java/envoy/client/ui/StatusTrayIcon.java b/src/main/java/envoy/client/ui/StatusTrayIcon.java index 01cc8d7..03380c2 100644 --- a/src/main/java/envoy/client/ui/StatusTrayIcon.java +++ b/src/main/java/envoy/client/ui/StatusTrayIcon.java @@ -75,16 +75,15 @@ public class StatusTrayIcon implements EventHandler { focusTarget.addWindowFocusListener(new WindowAdapter() { @Override - public void windowGainedFocus(WindowEvent e) { - displayMessages = false; - } + public void windowGainedFocus(WindowEvent e) { displayMessages = false; } @Override - public void windowLostFocus(WindowEvent e) { - displayMessages = true; - } + public void windowLostFocus(WindowEvent e) { displayMessages = true; } }); + // Show the window if the user clicks on the icon + trayIcon.addActionListener((evt) -> { focusTarget.setVisible(true); focusTarget.requestFocus(); }); + // Start processing message events EventBus.getInstance().register(this); }