Add Ability to Logout #50
@@ -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);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
			}
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -117,7 +117,6 @@ public final class Startup extends Application {
 | 
			
		||||
		cacheMap.put(MessageStatusChange.class, new Cache<MessageStatusChange>());
 | 
			
		||||
		cacheMap.put(GroupMessageStatusChange.class, new Cache<GroupMessageStatusChange>());
 | 
			
		||||
		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
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user