Added key shortcuts and system commands for logout, exit and settings
Additionally added **buggy** logout mechanism: LocalDB is not reset properly and IndexOutOfBoundsExceptions occur in the UI
This commit is contained in:
parent
2d9283551a
commit
05d4917bb2
@ -7,7 +7,7 @@ import java.time.Instant;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import envoy.client.event.EnvoyCloseEvent;
|
import envoy.client.event.*;
|
||||||
import envoy.data.*;
|
import envoy.data.*;
|
||||||
import envoy.event.*;
|
import envoy.event.*;
|
||||||
import envoy.exception.EnvoyException;
|
import envoy.exception.EnvoyException;
|
||||||
@ -213,11 +213,19 @@ public final class LocalDB implements EventListener {
|
|||||||
private void onNewAuthToken(NewAuthToken evt) { authToken = evt.get(); }
|
private void onNewAuthToken(NewAuthToken evt) { authToken = evt.get(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the file that stores the "remember me" feature.
|
* Deletes all associations to the current user.
|
||||||
*
|
*
|
||||||
* @since Envoy Client v0.2-beta
|
* @since Envoy Client v0.2-beta
|
||||||
*/
|
*/
|
||||||
public void deleteLoginFile() { lastLoginFile.delete(); }
|
@Event(eventType = Logout.class, priority = 100)
|
||||||
|
public void onLogout() {
|
||||||
|
lastLoginFile.delete();
|
||||||
|
userFile = null;
|
||||||
|
user = null;
|
||||||
|
authToken = null;
|
||||||
|
chats.clear();
|
||||||
|
cacheMap = new CacheMap();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return a {@code Map<String, User>} of all users stored locally with their
|
* @return a {@code Map<String, User>} of all users stored locally with their
|
||||||
|
14
client/src/main/java/envoy/client/event/Logout.java
Normal file
14
client/src/main/java/envoy/client/event/Logout.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package envoy.client.event;
|
||||||
|
|
||||||
|
import envoy.event.Event.Valueless;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that a logout has been requested.
|
||||||
|
*
|
||||||
|
* @author leon
|
||||||
|
* @since Envoy Client v0.2-beta
|
||||||
|
*/
|
||||||
|
public class Logout extends Valueless {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
}
|
@ -1,11 +1,11 @@
|
|||||||
package envoy.client.helper;
|
package envoy.client.helper;
|
||||||
|
|
||||||
import javafx.application.Platform;
|
|
||||||
import javafx.scene.control.Alert;
|
import javafx.scene.control.Alert;
|
||||||
import javafx.scene.control.Alert.AlertType;
|
import javafx.scene.control.Alert.AlertType;
|
||||||
|
|
||||||
import envoy.client.data.*;
|
import envoy.client.data.*;
|
||||||
import envoy.client.event.EnvoyCloseEvent;
|
import envoy.client.event.*;
|
||||||
|
import envoy.client.ui.SceneContext.SceneInfo;
|
||||||
|
|
||||||
import dev.kske.eventbus.EventBus;
|
import dev.kske.eventbus.EventBus;
|
||||||
|
|
||||||
@ -25,21 +25,31 @@ public class ShutdownHelper {
|
|||||||
*
|
*
|
||||||
* @since Envoy Client v0.2-beta
|
* @since Envoy Client v0.2-beta
|
||||||
*/
|
*/
|
||||||
public static void exit() { exit(Settings.getInstance().isHideOnClose(), true); }
|
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); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exits the currently open Envoy application or minimizes it.
|
* Logs the current user out and reopens
|
||||||
* Does not necessarily shutdown VM.
|
* {@link envoy.client.ui.controller.LoginScene}.
|
||||||
*
|
*
|
||||||
* @param minimize whether Envoy should be minimized instead of closed
|
|
||||||
* @param shutdownVM whether the JVM should shutdown
|
|
||||||
* @since Envoy Client v0.2-beta
|
* @since Envoy Client v0.2-beta
|
||||||
*/
|
*/
|
||||||
public static void exit(boolean minimize, boolean shutdownVM) {
|
public static void logout() {
|
||||||
if (minimize) Context.getInstance().getStage().setIconified(true);
|
final var alert = new Alert(AlertType.CONFIRMATION);
|
||||||
else {
|
alert.setTitle("Logout?");
|
||||||
|
alert.setContentText("Are you sure you want to log out?");
|
||||||
|
|
||||||
|
AlertHelper.confirmAction(alert, () -> {
|
||||||
EventBus.getInstance().dispatch(new EnvoyCloseEvent());
|
EventBus.getInstance().dispatch(new EnvoyCloseEvent());
|
||||||
if (shutdownVM) System.exit(0);
|
EventBus.getInstance().dispatch(new Logout());
|
||||||
}
|
Context.getInstance().getSceneContext().load(SceneInfo.LOGIN_SCENE);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -240,7 +240,10 @@ public final class Client implements EventListener, Closeable {
|
|||||||
logger.log(Level.INFO, "Closing connection...");
|
logger.log(Level.INFO, "Closing connection...");
|
||||||
try {
|
try {
|
||||||
socket.close();
|
socket.close();
|
||||||
} catch (final IOException e) {}
|
online = false;
|
||||||
|
} catch (final IOException e) {
|
||||||
|
logger.log(Level.WARNING, "Failed to close socket: ", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,8 +108,16 @@ public final class SceneContext implements EventListener {
|
|||||||
sceneStack.push(scene);
|
sceneStack.push(scene);
|
||||||
stage.setScene(scene);
|
stage.setScene(scene);
|
||||||
|
|
||||||
// Adding 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()
|
||||||
|
.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
|
||||||
|
// chat scene
|
||||||
|
if (sceneInfo.equals(SceneInfo.CHAT_SCENE))
|
||||||
|
scene.getAccelerators().put(new KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN), () -> load(SceneInfo.SETTINGS_SCENE));
|
||||||
|
|
||||||
// The LoginScene is the only scene not intended to be resized
|
// The LoginScene is the only scene not intended to be resized
|
||||||
// As strange as it seems, this is needed as otherwise the LoginScene won't be
|
// As strange as it seems, this is needed as otherwise the LoginScene won't be
|
||||||
|
@ -56,6 +56,8 @@ public final class Startup extends Application {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage stage) throws Exception {
|
public void start(Stage stage) throws Exception {
|
||||||
|
|
||||||
|
// Initialize config and logger
|
||||||
try {
|
try {
|
||||||
config.loadAll(Startup.class, "client.properties", getParameters().getRaw().toArray(new String[0]));
|
config.loadAll(Startup.class, "client.properties", getParameters().getRaw().toArray(new String[0]));
|
||||||
EnvoyLog.initialize(config);
|
EnvoyLog.initialize(config);
|
||||||
@ -68,7 +70,7 @@ public final class Startup extends Application {
|
|||||||
|
|
||||||
// Initialize the local database
|
// Initialize the local database
|
||||||
try {
|
try {
|
||||||
var localDBFile = new File(config.getHomeDirectory(), config.getServer());
|
final var localDBFile = new File(config.getHomeDirectory(), config.getServer());
|
||||||
logger.info("Initializing LocalDB at " + localDBFile);
|
logger.info("Initializing LocalDB at " + localDBFile);
|
||||||
localDB = new LocalDB(localDBFile);
|
localDB = new LocalDB(localDBFile);
|
||||||
} catch (IOException | EnvoyException e) {
|
} catch (IOException | EnvoyException e) {
|
||||||
|
@ -28,8 +28,10 @@ import envoy.client.data.*;
|
|||||||
import envoy.client.data.audio.AudioRecorder;
|
import envoy.client.data.audio.AudioRecorder;
|
||||||
import envoy.client.data.commands.*;
|
import envoy.client.data.commands.*;
|
||||||
import envoy.client.event.*;
|
import envoy.client.event.*;
|
||||||
|
import envoy.client.helper.ShutdownHelper;
|
||||||
import envoy.client.net.*;
|
import envoy.client.net.*;
|
||||||
import envoy.client.ui.*;
|
import envoy.client.ui.*;
|
||||||
|
import envoy.client.ui.SceneContext.SceneInfo;
|
||||||
import envoy.client.ui.custom.TextInputContextMenu;
|
import envoy.client.ui.custom.TextInputContextMenu;
|
||||||
import envoy.client.ui.listcell.*;
|
import envoy.client.ui.listcell.*;
|
||||||
import envoy.client.util.ReflectionUtil;
|
import envoy.client.util.ReflectionUtil;
|
||||||
@ -338,6 +340,19 @@ public final class ChatScene implements EventListener, Restorable {
|
|||||||
.setDescription("See for yourself :)")
|
.setDescription("See for yourself :)")
|
||||||
.setNumberOfArguments(2)
|
.setNumberOfArguments(2)
|
||||||
.build("dabr");
|
.build("dabr");
|
||||||
|
|
||||||
|
// Logout initialization
|
||||||
|
builder.setAction(text -> ShutdownHelper.logout()).setNumberOfArguments(0).setDescription("Logs you out.").build("logout");
|
||||||
|
|
||||||
|
// Exit initialization
|
||||||
|
builder.setAction(text -> ShutdownHelper.exit()).setNumberOfArguments(0).setDescription("Exits the program").build("exit", false);
|
||||||
|
builder.build("q");
|
||||||
|
|
||||||
|
// Open settings scene initialization
|
||||||
|
builder.setAction(text -> sceneContext.load(SceneInfo.SETTINGS_SCENE))
|
||||||
|
.setNumberOfArguments(0)
|
||||||
|
.setDescription("Opens the settings screen")
|
||||||
|
.build("settings");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,7 +3,8 @@ package envoy.client.ui.settings;
|
|||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
|
|
||||||
import envoy.client.data.SettingsItem;
|
import envoy.client.data.SettingsItem;
|
||||||
import envoy.client.event.*;
|
import envoy.client.event.ThemeChangeEvent;
|
||||||
|
import envoy.client.helper.ShutdownHelper;
|
||||||
import envoy.data.User.UserStatus;
|
import envoy.data.User.UserStatus;
|
||||||
|
|
||||||
import dev.kske.eventbus.EventBus;
|
import dev.kske.eventbus.EventBus;
|
||||||
@ -61,5 +62,12 @@ public final class GeneralSettingsPane extends SettingsPane {
|
|||||||
// TODO add action when value is changed
|
// TODO add action when value is changed
|
||||||
statusComboBox.setOnAction(e -> {});
|
statusComboBox.setOnAction(e -> {});
|
||||||
getChildren().add(statusComboBox);
|
getChildren().add(statusComboBox);
|
||||||
|
|
||||||
|
final var logoutButton = new Button("Logout");
|
||||||
|
logoutButton.setOnAction(e -> ShutdownHelper.logout());
|
||||||
|
final var logoutTooltip = new Tooltip("Brings you back to the login screen and removes \"remember me\" status from this account");
|
||||||
|
logoutTooltip.setWrapText(true);
|
||||||
|
logoutButton.setTooltip(logoutTooltip);
|
||||||
|
getChildren().add(logoutButton);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user