Merge pull request #53 from informatik-ag-ngl/f/background_execution

Added background execution
This commit is contained in:
Kai S. K. Engelbart 2019-12-14 14:30:19 +01:00 committed by GitHub
commit 12b0cc1d0b
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.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import envoy.client.Client; import envoy.client.Client;
@ -84,7 +85,7 @@ public class Startup {
throw new EnvoyException("Could not enter offline mode: user name unknown"); throw new EnvoyException("Could not enter offline mode: user name unknown");
client.setSender(clientUser); client.setSender(clientUser);
} catch(Exception e2) { } 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); System.exit(1);
return; return;
} }
@ -118,6 +119,9 @@ public class Startup {
try { try {
new StatusTrayIcon(chatWindow).show(); 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) { } catch (EnvoyException e) {
logger.warning("The StatusTrayIcon is not supported on this platform!"); 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() { focusTarget.addWindowFocusListener(new WindowAdapter() {
@Override @Override
public void windowGainedFocus(WindowEvent e) { public void windowGainedFocus(WindowEvent e) { displayMessages = false; }
displayMessages = false;
}
@Override @Override
public void windowLostFocus(WindowEvent e) { public void windowLostFocus(WindowEvent e) { displayMessages = true; }
displayMessages = true;
}
}); });
// Show the window if the user clicks on the icon
trayIcon.addActionListener((evt) -> { focusTarget.setVisible(true); focusTarget.requestFocus(); });
// Start processing message events // Start processing message events
EventBus.getInstance().register(this); EventBus.getInstance().register(this);
} }