Fixed Saving When Using Alt F4 and Disabled Hiding If StatusTrayIcon is not supported(#65)

Fixed potentially not saving when using alt f4 and disabled hiding if
StatusTrayIcon is not supported
Reviewed-on: https://git.kske.dev/zdm/envoy/pulls/65
Reviewed-by: kske <kai@kske.dev>
Reviewed-by: DieGurke <maxi@kske.dev>
This commit is contained in:
Leon Hofmeister 2020-09-28 15:58:42 +02:00
parent 3f0267624c
commit a4e9474b97
5 changed files with 36 additions and 24 deletions

View File

@ -235,7 +235,7 @@ public final class LocalDB implements EventListener {
@Event(priority = 150)
private void onUserStatusChange(UserStatusChange evt) {
this.getChat(evt.getID()).map(Chat::getRecipient).map(User.class::cast).ifPresent(u -> u.setStatus(evt.get()));
getChat(evt.getID()).map(Chat::getRecipient).map(User.class::cast).ifPresent(u -> u.setStatus(evt.get()));
}
@Event(priority = 150)

View File

@ -8,6 +8,7 @@ import javafx.scene.control.Alert.AlertType;
import envoy.client.data.*;
import envoy.client.event.*;
import envoy.client.ui.SceneContext.SceneInfo;
import envoy.client.ui.StatusTrayIcon;
import envoy.util.EnvoyLog;
import dev.kske.eventbus.EventBus;
@ -24,12 +25,12 @@ public final class ShutdownHelper {
/**
* Exits Envoy or minimizes it, depending on the current state of
* {@link Settings#isHideOnClose()}.
* {@link Settings#isHideOnClose()} and {@link StatusTrayIcon#isSupported()}.
*
* @since Envoy Client v0.2-beta
*/
public static void exit() {
if (Settings.getInstance().isHideOnClose()) Context.getInstance().getStage().setIconified(true);
if (Settings.getInstance().isHideOnClose() && StatusTrayIcon.isSupported()) Context.getInstance().getStage().setIconified(true);
else {
EventBus.getInstance().dispatch(new EnvoyCloseEvent());
System.exit(0);

View File

@ -105,17 +105,7 @@ public final class SceneContext implements EventListener {
sceneStack.push(scene);
stage.setScene(scene);
// 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" 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
// chat scene
if (sceneInfo.equals(SceneInfo.CHAT_SCENE))
scene.getAccelerators().put(new KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN), () -> load(SceneInfo.SETTINGS_SCENE));
supplyKeyboardShortcuts(sceneInfo, scene);
// 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
@ -130,6 +120,22 @@ public final class SceneContext implements EventListener {
}
}
private void supplyKeyboardShortcuts(SceneInfo sceneInfo, final Scene scene) {
final var accelerators = scene.getAccelerators();
// Add the option to exit Linux-like with "Control" + "Q" or "Alt" + "F4"
accelerators.put(new KeyCodeCombination(KeyCode.Q, KeyCombination.CONTROL_DOWN), ShutdownHelper::exit);
// Add the option to logout using "Control"+"Shift"+"L" if not in login scene
if (sceneInfo != SceneInfo.LOGIN_SCENE)
accelerators.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 == SceneInfo.CHAT_SCENE)
accelerators.put(new KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN), () -> load(SceneInfo.SETTINGS_SCENE));
}
/**
* Removes the current scene and displays the previous one.
*

View File

@ -205,10 +205,11 @@ public final class Startup extends Application {
context.getSceneContext().load(SceneContext.SceneInfo.CHAT_SCENE);
stage.centerOnScreen();
if (StatusTrayIcon.isSupported()) {
// 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() && StatusTrayIcon.isSupported()) e.consume(); });
if (StatusTrayIcon.isSupported()) {
// Initialize status tray icon
final var trayIcon = new StatusTrayIcon(stage);

View File

@ -5,6 +5,7 @@ import javafx.scene.control.*;
import envoy.client.data.SettingsItem;
import envoy.client.event.ThemeChangeEvent;
import envoy.client.helper.ShutdownHelper;
import envoy.client.ui.StatusTrayIcon;
import envoy.data.User.UserStatus;
import dev.kske.eventbus.EventBus;
@ -22,13 +23,16 @@ public final class GeneralSettingsPane extends SettingsPane {
super("General");
setSpacing(10);
// TODO: Support other value types
final var settingsItems = settings.getItems();
// Add hide on close if supported
if (StatusTrayIcon.isSupported()) {
final var hideOnCloseCheckbox = new SettingsCheckbox((SettingsItem<Boolean>) settingsItems.get("hideOnClose"));
final var hideOnCloseTooltip = new Tooltip("If selected, Envoy will still be present in the task bar when closed.");
hideOnCloseTooltip.setWrapText(true);
hideOnCloseCheckbox.setTooltip(hideOnCloseTooltip);
getChildren().add(hideOnCloseCheckbox);
}
final var enterToSendCheckbox = new SettingsCheckbox((SettingsItem<Boolean>) settingsItems.get("enterToSend"));
final var enterToSendTooltip = new Tooltip(