Fixed bug not re-performing handshake on logout

Fixes #31
This commit is contained in:
Leon Hofmeister 2020-09-25 22:00:34 +02:00
parent af219274f5
commit 108db1ae11
Signed by: delvh
GPG Key ID: 3DECE05F6D9A647C
5 changed files with 14 additions and 13 deletions

View File

@ -31,10 +31,8 @@ public class ShutdownHelper {
public static void exit() { public static void exit() {
if (Settings.getInstance().isHideOnClose()) Context.getInstance().getStage().setIconified(true); if (Settings.getInstance().isHideOnClose()) Context.getInstance().getStage().setIconified(true);
else { else {
final var alert = new Alert(AlertType.CONFIRMATION); EventBus.getInstance().dispatch(new EnvoyCloseEvent());
alert.setTitle("Exit?"); System.exit(0);
alert.setContentText("Are you sure you want to exit Envoy?");
AlertHelper.confirmAction(alert, () -> { EventBus.getInstance().dispatch(new EnvoyCloseEvent()); System.exit(0); });
} }
} }

View File

@ -240,8 +240,11 @@ public final class Client implements EventListener, Closeable {
if (online) { if (online) {
logger.log(Level.INFO, "Closing connection..."); logger.log(Level.INFO, "Closing connection...");
try { try {
// The sender must be reset as otherwise the handshake is immediately closed
sender = null;
online = false;
socket.close(); socket.close();
online = false;
} catch (final IOException e) { } catch (final IOException e) {
logger.log(Level.WARNING, "Failed to close socket: ", e); logger.log(Level.WARNING, "Failed to close socket: ", e);
} }

View File

@ -111,8 +111,9 @@ public final class SceneContext implements EventListener {
// Add the option to exit Linux-like with "Control" + "Q" // Add the option to exit Linux-like with "Control" + "Q"
scene.getAccelerators().put(new KeyCodeCombination(KeyCode.Q, KeyCombination.CONTROL_DOWN), ShutdownHelper::exit); scene.getAccelerators().put(new KeyCodeCombination(KeyCode.Q, KeyCombination.CONTROL_DOWN), ShutdownHelper::exit);
// Add the option to logout using "Control"+"Shift"+"L"
scene.getAccelerators() // Add the option to logout using "Control"+"Shift"+"L" if not in login scene
if (sceneInfo != SceneInfo.LOGIN_SCENE) scene.getAccelerators()
.put(new KeyCodeCombination(KeyCode.L, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN), ShutdownHelper::logout); .put(new KeyCodeCombination(KeyCode.L, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN), ShutdownHelper::logout);
// Add the option to open the settings scene with "Control"+"S", if being in // Add the option to open the settings scene with "Control"+"S", if being in

View File

@ -117,7 +117,6 @@ public final class Startup extends Application {
cacheMap.put(MessageStatusChange.class, new Cache<MessageStatusChange>()); cacheMap.put(MessageStatusChange.class, new Cache<MessageStatusChange>());
cacheMap.put(GroupMessageStatusChange.class, new Cache<GroupMessageStatusChange>()); cacheMap.put(GroupMessageStatusChange.class, new Cache<GroupMessageStatusChange>());
try { try {
final var client = context.getClient();
client.performHandshake(credentials, cacheMap); client.performHandshake(credentials, cacheMap);
if (client.isOnline()) { if (client.isOnline()) {
loadChatScene(); loadChatScene();
@ -211,7 +210,7 @@ public final class Startup extends Application {
if (StatusTrayIcon.isSupported()) { if (StatusTrayIcon.isSupported()) {
// Configure hide on close // Exit or minimize the stage when a close request occurs
stage.setOnCloseRequest(e -> { ShutdownHelper.exit(); if (Settings.getInstance().isHideOnClose()) e.consume(); }); stage.setOnCloseRequest(e -> { ShutdownHelper.exit(); if (Settings.getInstance().isHideOnClose()) e.consume(); });
// Initialize status tray icon // Initialize status tray icon

View File

@ -72,7 +72,7 @@ public class ContactSearchTab implements EventListener {
} }
/** /**
* Disables the clear and search button if no text is present in the search bar. * If text is present, sends a request to the server.
* *
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
@ -111,12 +111,12 @@ public class ContactSearchTab implements EventListener {
} }
} }
private void addAsContact() { private void addAsContact() {
// Sends the event to the server // Sends the event to the server
final var event = new ContactOperation(currentlySelectedUser, ElementOperation.ADD); final var event = new ContactOperation(currentlySelectedUser, ElementOperation.ADD);
eventBus.dispatch(new SendEvent(event)); eventBus.dispatch(new SendEvent(event));
// Removes the chosen user and updates the UI // Removes the chosen user and updates the UI
userList.getItems().remove(currentlySelectedUser); userList.getItems().remove(currentlySelectedUser);
eventBus.dispatch(event); eventBus.dispatch(event);