Search in sources :

Example 6 with InteractiveScriptSession

use of org.phoenicis.scripts.session.InteractiveScriptSession in project POL-POM-5 by PhoenicisOrg.

the class ConsoleController method createConsole.

public ConsoleTab createConsole() {
    final ConsoleTab consoleTab = consoleTabFactory.createInstance();
    final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
    consoleTab.setOnSendCommand(command -> {
        consoleTab.appendTextToConsole("> " + command + "\n", ConsoleTextType.NORMAL);
        consoleTab.disableCommand();
        interactiveScriptSession.eval(command, result -> {
            consoleTab.appendTextToConsole(result == null ? "null\n" : result.toString() + "\n");
            consoleTab.enableCommand();
        }, error -> {
            consoleTab.appendTextToConsole(ExceptionUtils.getFullStackTrace(error), ConsoleTextType.ERROR);
            consoleTab.enableCommand();
        });
    });
    return consoleTab;
}
Also used : ConsoleTab(org.phoenicis.javafx.views.mainwindow.console.ConsoleTab) InteractiveScriptSession(org.phoenicis.scripts.session.InteractiveScriptSession)

Example 7 with InteractiveScriptSession

use of org.phoenicis.scripts.session.InteractiveScriptSession in project POL-POM-5 by PlayOnLinux.

the class LibraryFeaturePanel method createShortcut.

/**
 * Creates a new shortcut
 *
 * @param shortcutCreationDTO DTO describing the new shortcut
 */
public void createShortcut(ShortcutCreationDTO shortcutCreationDTO) {
    // get container
    // TODO: smarter way using container manager
    final String executablePath = shortcutCreationDTO.getExecutable().getAbsolutePath();
    final String pathInContainers = executablePath.replace(getContainersPath(), "");
    final String[] split = pathInContainers.split("/");
    final String engineContainer = split[0];
    final String engine = StringUtils.capitalize(engineContainer).replace("prefix", "");
    // TODO: better way to get engine ID
    final String engineId = engine.toLowerCase();
    final String container = split[1];
    final InteractiveScriptSession interactiveScriptSession = getScriptInterpreter().createInteractiveSession();
    final String scriptInclude = "const Shortcut = include(\"engines." + engineId + ".shortcuts." + engineId + "\");";
    interactiveScriptSession.eval(scriptInclude, ignored -> interactiveScriptSession.eval("new Shortcut()", output -> {
        final Value shortcutObject = (Value) output;
        shortcutObject.invokeMember("name", shortcutCreationDTO.getName());
        shortcutObject.invokeMember("category", shortcutCreationDTO.getCategory());
        shortcutObject.invokeMember("description", shortcutCreationDTO.getDescription());
        shortcutObject.invokeMember("miniature", shortcutCreationDTO.getMiniature());
        shortcutObject.invokeMember("search", shortcutCreationDTO.getExecutable().getName());
        shortcutObject.invokeMember("prefix", container);
        shortcutObject.invokeMember("create");
    }, e -> Platform.runLater(() -> {
        final ErrorDialog errorDialog = ErrorDialog.builder().withMessage(tr("Error while creating shortcut")).withException(e).withOwner(getScene().getWindow()).build();
        errorDialog.showAndWait();
    })), e -> Platform.runLater(() -> {
        final ErrorDialog errorDialog = ErrorDialog.builder().withMessage(tr("Error while creating shortcut")).withException(e).withOwner(getScene().getWindow()).build();
        errorDialog.showAndWait();
    }));
}
Also used : FeaturePanel(org.phoenicis.javafx.components.common.control.FeaturePanel) ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) StringUtils(org.apache.commons.lang.StringUtils) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) FXCollections(javafx.collections.FXCollections) ConsoleController(org.phoenicis.javafx.controller.library.console.ConsoleController) ErrorDialog(org.phoenicis.javafx.dialogs.ErrorDialog) None(org.phoenicis.javafx.components.common.panelstates.None) ShortcutDTO(org.phoenicis.library.dto.ShortcutDTO) ObjectProperty(javafx.beans.property.ObjectProperty) Value(org.graalvm.polyglot.Value) ShortcutCreationDTO(org.phoenicis.library.dto.ShortcutCreationDTO) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) Localisation.tr(org.phoenicis.configuration.localisation.Localisation.tr) Platform(javafx.application.Platform) InteractiveScriptSession(org.phoenicis.scripts.session.InteractiveScriptSession) JavaFxSettingsManager(org.phoenicis.javafx.settings.JavaFxSettingsManager) LibraryFilter(org.phoenicis.javafx.views.mainwindow.library.LibraryFilter) ShortcutManager(org.phoenicis.library.ShortcutManager) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Tab(javafx.scene.control.Tab) ConsoleTab(org.phoenicis.javafx.views.mainwindow.console.ConsoleTab) SimpleConfirmDialog(org.phoenicis.javafx.dialogs.SimpleConfirmDialog) OpenDetailsPanel(org.phoenicis.javafx.components.common.panelstates.OpenDetailsPanel) ShortcutRunner(org.phoenicis.library.ShortcutRunner) ObservableList(javafx.collections.ObservableList) StringProperty(javafx.beans.property.StringProperty) Collections(java.util.Collections) LibraryFeaturePanelSkin(org.phoenicis.javafx.components.library.skin.LibraryFeaturePanelSkin) Value(org.graalvm.polyglot.Value) ErrorDialog(org.phoenicis.javafx.dialogs.ErrorDialog) InteractiveScriptSession(org.phoenicis.scripts.session.InteractiveScriptSession)

Example 8 with InteractiveScriptSession

use of org.phoenicis.scripts.session.InteractiveScriptSession in project POL-POM-5 by PlayOnLinux.

the class ConsoleController method createConsole.

public ConsoleTab createConsole() {
    final ConsoleTab consoleTab = consoleTabFactory.createInstance();
    final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
    consoleTab.setOnSendCommand(command -> {
        consoleTab.appendTextToConsole("> " + command + "\n", ConsoleTextType.NORMAL);
        consoleTab.disableCommand();
        interactiveScriptSession.eval(command, result -> {
            consoleTab.appendTextToConsole(result == null ? "null\n" : result.toString() + "\n");
            consoleTab.enableCommand();
        }, error -> {
            consoleTab.appendTextToConsole(ExceptionUtils.getFullStackTrace(error), ConsoleTextType.ERROR);
            consoleTab.enableCommand();
        });
    });
    return consoleTab;
}
Also used : ConsoleTab(org.phoenicis.javafx.views.mainwindow.console.ConsoleTab) InteractiveScriptSession(org.phoenicis.scripts.session.InteractiveScriptSession)

Example 9 with InteractiveScriptSession

use of org.phoenicis.scripts.session.InteractiveScriptSession in project POL-POM-5 by PlayOnLinux.

the class EngineToolsManager method runTool.

/**
 * runs a tool in a given container
 *
 * @param engineId ID of the engine which provides the tool (e.g. "Wine")
 * @param container name of the container
 * @param toolId ID of the tool
 * @param doneCallback callback executed after the script ran
 * @param errorCallback callback executed in case of an error
 */
public void runTool(String engineId, String container, String toolId, Runnable doneCallback, Consumer<Exception> errorCallback) {
    final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
    final String include = String.format("include(\"engines.%s.tools.%s\");", engineId, toolId);
    interactiveScriptSession.eval(include, output -> {
        final Value toolClass = (Value) output;
        final EngineTool tool = toolClass.newInstance().as(EngineTool.class);
        tool.run(container);
        doneCallback.run();
    }, errorCallback);
}
Also used : Value(org.graalvm.polyglot.Value) InteractiveScriptSession(org.phoenicis.scripts.session.InteractiveScriptSession)

Example 10 with InteractiveScriptSession

use of org.phoenicis.scripts.session.InteractiveScriptSession in project POL-POM-5 by PlayOnLinux.

the class VerbsManager method installVerb.

/**
 * Installs a Verb in a given container
 *
 * @param engineId ID of the engine which provides the Verb (e.g. "Wine")
 * @param container name of the container
 * @param verbId ID of the Verb
 * @param doneCallback callback executed after the script ran
 * @param errorCallback callback executed in case of an error
 */
public void installVerb(String engineId, String container, String verbId, Runnable doneCallback, Consumer<Exception> errorCallback) {
    final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
    final String script = String.format("include(\"%s\");", verbId);
    interactiveScriptSession.eval(script, output -> {
        final Value verbClass = (Value) output;
        try {
            verbClass.invokeMember("install", container);
        } catch (ScriptException se) {
            errorCallback.accept(se);
        }
        doneCallback.run();
    }, errorCallback);
}
Also used : ScriptException(org.phoenicis.scripts.exceptions.ScriptException) Value(org.graalvm.polyglot.Value) InteractiveScriptSession(org.phoenicis.scripts.session.InteractiveScriptSession)

Aggregations

InteractiveScriptSession (org.phoenicis.scripts.session.InteractiveScriptSession)16 Value (org.graalvm.polyglot.Value)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 Collections (java.util.Collections)4 ConsoleTab (org.phoenicis.javafx.views.mainwindow.console.ConsoleTab)4 ShortcutManager (org.phoenicis.library.ShortcutManager)4 ShortcutCategoryDTO (org.phoenicis.library.dto.ShortcutCategoryDTO)4 ShortcutDTO (org.phoenicis.library.dto.ShortcutDTO)4 ScriptInterpreter (org.phoenicis.scripts.interpreter.ScriptInterpreter)4 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 Consumer (java.util.function.Consumer)2 Collectors (java.util.stream.Collectors)2 Platform (javafx.application.Platform)2 ObjectProperty (javafx.beans.property.ObjectProperty)2 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)2