From 108db1ae1188f1342e427fb3eccc1b2c2e3c62a8 Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 25 Sep 2020 22:00:34 +0200 Subject: [PATCH] Fixed bug not re-performing handshake on logout Fixes #31 --- .../src/main/java/envoy/client/helper/ShutdownHelper.java | 6 ++---- client/src/main/java/envoy/client/net/Client.java | 5 ++++- client/src/main/java/envoy/client/ui/SceneContext.java | 5 +++-- client/src/main/java/envoy/client/ui/Startup.java | 3 +-- .../java/envoy/client/ui/controller/ContactSearchTab.java | 8 ++++---- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/client/src/main/java/envoy/client/helper/ShutdownHelper.java b/client/src/main/java/envoy/client/helper/ShutdownHelper.java index e871936..fa39b69 100644 --- a/client/src/main/java/envoy/client/helper/ShutdownHelper.java +++ b/client/src/main/java/envoy/client/helper/ShutdownHelper.java @@ -31,10 +31,8 @@ public class ShutdownHelper { public static void exit() { if (Settings.getInstance().isHideOnClose()) Context.getInstance().getStage().setIconified(true); else { - final var alert = new Alert(AlertType.CONFIRMATION); - alert.setTitle("Exit?"); - alert.setContentText("Are you sure you want to exit Envoy?"); - AlertHelper.confirmAction(alert, () -> { EventBus.getInstance().dispatch(new EnvoyCloseEvent()); System.exit(0); }); + EventBus.getInstance().dispatch(new EnvoyCloseEvent()); + System.exit(0); } } diff --git a/client/src/main/java/envoy/client/net/Client.java b/client/src/main/java/envoy/client/net/Client.java index 1833109..63a3e3b 100644 --- a/client/src/main/java/envoy/client/net/Client.java +++ b/client/src/main/java/envoy/client/net/Client.java @@ -240,8 +240,11 @@ public final class Client implements EventListener, Closeable { if (online) { logger.log(Level.INFO, "Closing connection..."); try { + + // The sender must be reset as otherwise the handshake is immediately closed + sender = null; + online = false; socket.close(); - online = false; } catch (final IOException e) { logger.log(Level.WARNING, "Failed to close socket: ", e); } diff --git a/client/src/main/java/envoy/client/ui/SceneContext.java b/client/src/main/java/envoy/client/ui/SceneContext.java index d5b280c..67dcc20 100644 --- a/client/src/main/java/envoy/client/ui/SceneContext.java +++ b/client/src/main/java/envoy/client/ui/SceneContext.java @@ -111,8 +111,9 @@ public final class SceneContext implements EventListener { // Add the option to exit Linux-like with "Control" + "Q" 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); // Add the option to open the settings scene with "Control"+"S", if being in diff --git a/client/src/main/java/envoy/client/ui/Startup.java b/client/src/main/java/envoy/client/ui/Startup.java index 1bbc7b6..9411644 100644 --- a/client/src/main/java/envoy/client/ui/Startup.java +++ b/client/src/main/java/envoy/client/ui/Startup.java @@ -117,7 +117,6 @@ public final class Startup extends Application { cacheMap.put(MessageStatusChange.class, new Cache()); cacheMap.put(GroupMessageStatusChange.class, new Cache()); try { - final var client = context.getClient(); client.performHandshake(credentials, cacheMap); if (client.isOnline()) { loadChatScene(); @@ -211,7 +210,7 @@ public final class Startup extends Application { 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(); }); // Initialize status tray icon diff --git a/client/src/main/java/envoy/client/ui/controller/ContactSearchTab.java b/client/src/main/java/envoy/client/ui/controller/ContactSearchTab.java index ed800a7..a6aec3e 100644 --- a/client/src/main/java/envoy/client/ui/controller/ContactSearchTab.java +++ b/client/src/main/java/envoy/client/ui/controller/ContactSearchTab.java @@ -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 */ @@ -111,12 +111,12 @@ public class ContactSearchTab implements EventListener { } } - private void addAsContact() { - + private void addAsContact() { + // Sends the event to the server final var event = new ContactOperation(currentlySelectedUser, ElementOperation.ADD); eventBus.dispatch(new SendEvent(event)); - + // Removes the chosen user and updates the UI userList.getItems().remove(currentlySelectedUser); eventBus.dispatch(event);