Added option to close Envoy Linux-like with "Control"+"Q"

This commit is contained in:
Leon Hofmeister 2020-09-20 22:11:15 +02:00
parent 7cc4928826
commit d394c2d058
Signed by: delvh
GPG Key ID: 3DECE05F6D9A647C
2 changed files with 15 additions and 7 deletions

View File

@ -7,6 +7,7 @@ import java.util.logging.Level;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.*;
import javafx.scene.input.*;
import javafx.stage.Stage;
import envoy.client.data.Settings;
@ -105,6 +106,17 @@ public final class SceneContext implements EventListener {
sceneStack.push(scene);
stage.setScene(scene);
// Adding the option to exit Linux-like with "Control" + "Q"
scene.getAccelerators()
.put(new KeyCodeCombination(KeyCode.Q, KeyCombination.CONTROL_DOWN),
() -> {
// Presumably no Settings are loaded in the login scene, hence Envoy is closed
// directly
if (sceneInfo != SceneInfo.LOGIN_SCENE && settings.isHideOnClose()) stage.setIconified(true);
else System.exit(0);
});
// 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
// displayed on some OS (...Debian...)

View File

@ -67,7 +67,7 @@ public final class Startup extends Application {
// Initialize the local database
try {
File localDBDir = new File(config.getHomeDirectory(), config.getLocalDB().getPath());
final var localDBDir = new File(config.getHomeDirectory(), config.getLocalDB().getPath());
logger.info("Initializing LocalDB at " + localDBDir);
localDB = new LocalDB(localDBDir);
localDB.lock();
@ -99,12 +99,10 @@ public final class Startup extends Application {
if (!performHandshake(
LoginCredentials.loginWithToken(localDB.getUser().getName(), localDB.getAuthToken(), VERSION, localDB.getLastSync())))
sceneContext.load(SceneInfo.LOGIN_SCENE);
} else {
} else
// Load login scene
sceneContext.load(SceneInfo.LOGIN_SCENE);
}
}
/**
* Tries to perform a Handshake with the server.
@ -126,9 +124,7 @@ public final class Startup extends Application {
loadChatScene();
client.initReceiver(localDB, cacheMap);
return true;
} else {
return false;
}
} else return false;
} catch (IOException | InterruptedException | TimeoutException e) {
logger.log(Level.INFO, "Could not connect to server. Entering offline mode...");
return attemptOfflineMode(credentials.getIdentifier());