// Path: java/src/main/java/org/rustkeylock/fxcomponents/RklStage.java
// public class RklStage {
//     private final Stage fxStage;
//     private final HostServices hostServices;
//     private RklController currentlyActiveController;
//     private AtomicBoolean loggedIn = new AtomicBoolean(false);
// 
//     public RklStage(Stage fxStage, HostServices hostServices) {
//         this.fxStage = fxStage;
//         this.hostServices = hostServices;
//     }
// 
//     public Optional<RklController> getCurrentlyActiveController() {
//         return Optional.ofNullable(currentlyActiveController);
//     }
// 
//     public void updateView(Scene scene, RklController controller) {
//         currentlyActiveController = controller;
//         fxStage.setScene(scene);
//     }
// 
//     public Stage getFxStage() {
//         return this.fxStage;
//     }
// 
//     public HostServices getHostServices() {
//         return hostServices;
//     }
// 
//     public void markLoggedIn() {
//         loggedIn.getAndSet(true);
//     }
// 
//     public boolean isLoggedIn() {
//         return loggedIn.get();
//     }
// }
// 
// Path: java/src/main/java/org/rustkeylock/ui/Defs.java
// public class Defs {
//     public static final String MENU_TRY_PASS = "TryPass";
//     public static final String MENU_CHANGE_PASS = "ChangePass";
//     public static final String MENU_MAIN = "Main";
//     public static final String MENU_SHOW_ENTRY = "ShowEntry";
//     public static final String MENU_SAVE = "Save";
//     public static final String MENU_EXIT = "Exit";
//     public static final String MENU_FORCE_EXIT = "ForceExit";
//     public static final String MENU_EDIT_ENTRY = "EditEntry";
//     public static final String MENU_DELETE_ENTRY = "DeleteEntry";
//     public static final String MENU_NEW_ENTRY = "NewEntry";
//     public static final String MENU_EXPORT_ENTRIES = "ExportEntries";
//     public static final String MENU_IMPORT_ENTRIES = "ImportEntries";
//     public static final String MENU_SHOW_CONFIGURATION = "ShowConfiguration";
//     public static final String MENU_GET_DBX_TOKEN = "GetDbxToken";
//     public static final String MENU_WAIT_FOR_DBX_TOKEN_CALLBACK = "WaitForDbxTokenCallback";
//     public static final String MENU_CURRENT = "Current";
//     public static final String MENU_PLEASE_WAIT = "PleaseWait";
//     public static final String EMPTY_ARG = "null";
//     public static final String CHECK_PASSWORDS = "CheckPasswords";
//     public static final int PrefWidthPixels = 650;
//     public static final int PrefHeightPixels = 750;
//     public static final String BACKGROUND_ERROR = "-fx-background-color: #E69269;";
//     public static final String BACKGROUND_NO_ERROR = "-fx-background-color: #FFFFFF;";
// }
// 
// Path: java/src/main/java/org/rustkeylock/ui/Utils.java
// public class Utils {
//     public static void removeChildNodeById(HBox parent, String idToRemove) {
//         Optional<Node> childFound = parent.getChildren().stream()
//                 .filter(node -> idToRemove.equals(node.getId()))
//                 .findFirst();
//         childFound.map(node -> parent.getChildren().remove(node));
//     }
// 
//     public static void addNode(HBox parent, Node node) {
//         if (!parent.getChildren().contains(node)) {
//             parent.getChildren().add(node);
//         }
//     }
// 
//     public static void applyRklCss(Scene scene) {
//         String rklCss = Utils.class.getResource("/style/rkl.css").toExternalForm();
//         scene.getStylesheets().add(rklCss);
//     }
// }


import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import org.astonbitecode.j4rs.api.invocation.NativeCallbackToRustChannelSupport;
import org.rustkeylock.controllers.*;
import org.rustkeylock.fxcomponents.RklStage;
import org.rustkeylock.ui.Defs;
import org.rustkeylock.ui.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.URL;
                        loader.setControllerFactory(clazz -> new ExitController());
                        break;
                    case Defs.MENU_CURRENT:
                        resurl = null;
                        break;
                    case Defs.MENU_MAIN:
                    default:
                        resurl = getClass().getResource("/fragments/menu_main.fxml");
                        loader.setControllerFactory(clazz -> new MainMenuController());
                        break;

                }

                // If the controller is null here, it means that we should not change view.
                // In this case, we should retrieve the currently active controller in order to set a new callback for it.
                RklController controller = null;
                if (resurl != null) {
                    loader.setLocation(resurl);
                    Parent root = loader.load();

                    controller = loader.getController();
                    Scene scene = new Scene(root);
                    Utils.applyRklCss(scene);
                    stage.updateView(scene, controller);
                } else {
                    controller = stage.getCurrentlyActiveController().orElseThrow(() -> new RuntimeException("Saved state not found!"));
                }
                controller.setCallback(this::doCallback);

            } catch (IOException error) {
// Path: java/src/main/java/org/rustkeylock/fxcomponents/RklStage.java
// public class RklStage {
//     private final Stage fxStage;
//     private final HostServices hostServices;
//     private RklController currentlyActiveController;
//     private AtomicBoolean loggedIn = new AtomicBoolean(false);
// 
//     public RklStage(Stage fxStage, HostServices hostServices) {
//         this.fxStage = fxStage;
//         this.hostServices = hostServices;
//     }
// 
//     public Optional<RklController> getCurrentlyActiveController() {
//         return Optional.ofNullable(currentlyActiveController);
//     }
// 
//     public void updateView(Scene scene, RklController controller) {
//         currentlyActiveController = controller;
//         fxStage.setScene(scene);
//     }
// 
//     public Stage getFxStage() {
//         return this.fxStage;
//     }
// 
//     public HostServices getHostServices() {
//         return hostServices;
//     }
// 
//     public void markLoggedIn() {
//         loggedIn.getAndSet(true);
//     }
// 
//     public boolean isLoggedIn() {
//         return loggedIn.get();
//     }
// }
// 
// Path: java/src/main/java/org/rustkeylock/ui/Defs.java
// public class Defs {
//     public static final String MENU_TRY_PASS = "TryPass";
//     public static final String MENU_CHANGE_PASS = "ChangePass";
//     public static final String MENU_MAIN = "Main";
//     public static final String MENU_SHOW_ENTRY = "ShowEntry";
//     public static final String MENU_SAVE = "Save";
//     public static final String MENU_EXIT = "Exit";
//     public static final String MENU_FORCE_EXIT = "ForceExit";
//     public static final String MENU_EDIT_ENTRY = "EditEntry";
//     public static final String MENU_DELETE_ENTRY = "DeleteEntry";
//     public static final String MENU_NEW_ENTRY = "NewEntry";
//     public static final String MENU_EXPORT_ENTRIES = "ExportEntries";
//     public static final String MENU_IMPORT_ENTRIES = "ImportEntries";
//     public static final String MENU_SHOW_CONFIGURATION = "ShowConfiguration";
//     public static final String MENU_GET_DBX_TOKEN = "GetDbxToken";
//     public static final String MENU_WAIT_FOR_DBX_TOKEN_CALLBACK = "WaitForDbxTokenCallback";
//     public static final String MENU_CURRENT = "Current";
//     public static final String MENU_PLEASE_WAIT = "PleaseWait";
//     public static final String EMPTY_ARG = "null";
//     public static final String CHECK_PASSWORDS = "CheckPasswords";
//     public static final int PrefWidthPixels = 650;
//     public static final int PrefHeightPixels = 750;
//     public static final String BACKGROUND_ERROR = "-fx-background-color: #E69269;";
//     public static final String BACKGROUND_NO_ERROR = "-fx-background-color: #FFFFFF;";
// }
// 
// Path: java/src/main/java/org/rustkeylock/ui/Utils.java
// public class Utils {
//     public static void removeChildNodeById(HBox parent, String idToRemove) {
//         Optional<Node> childFound = parent.getChildren().stream()
//                 .filter(node -> idToRemove.equals(node.getId()))
//                 .findFirst();
//         childFound.map(node -> parent.getChildren().remove(node));
//     }
// 
//     public static void addNode(HBox parent, Node node) {
//         if (!parent.getChildren().contains(node)) {
//             parent.getChildren().add(node);
//         }
//     }
// 
//     public static void applyRklCss(Scene scene) {
//         String rklCss = Utils.class.getResource("/style/rkl.css").toExternalForm();
//         scene.getStylesheets().add(rklCss);
//     }
// }


// Path: java/src/main/java/org/rustkeylock/ui/callbacks/ShowMenuCb.java
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import org.astonbitecode.j4rs.api.invocation.NativeCallbackToRustChannelSupport;
import org.rustkeylock.controllers.*;
import org.rustkeylock.fxcomponents.RklStage;
import org.rustkeylock.ui.Defs;
import org.rustkeylock.ui.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.URL;

                        loader.setControllerFactory(clazz -> new ExitController());
                        break;
                    case Defs.MENU_CURRENT:
                        resurl = null;
                        break;
                    case Defs.MENU_MAIN:
                    default:
                        resurl = getClass().getResource("/fragments/menu_main.fxml");
                        loader.setControllerFactory(clazz -> new MainMenuController());
                        break;

                }

                // If the controller is null here, it means that we should not change view.
                // In this case, we should retrieve the currently active controller in order to set a new callback for it.
                RklController controller = null;
                if (resurl != null) {
                    loader.setLocation(resurl);
                    Parent root = loader.load();

                    controller = loader.getController();
                    Scene scene = new Scene(root);
                    Utils.applyRklCss(scene);
                    stage.updateView(scene, controller);
                } else {
                    controller = stage.getCurrentlyActiveController().orElseThrow(() -> new RuntimeException("Saved state not found!"));
                }
                controller.setCallback(this::doCallback);

            } catch (IOException error) {
                error.printStackTrace();