Added background execution

This commit is contained in:
Kai S. K. Engelbart 2019-12-14 14:17:24 +01:00
parent 6ae43fc810
commit f0353c8c72
2 changed files with 10 additions and 7 deletions

View File

@ -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!");
}

View File

@ -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);
}