Search in sources :

Example 26 with InteractiveScriptSession

use of org.phoenicis.scripts.interpreter.InteractiveScriptSession in project phoenicis by PhoenicisOrg.

the class WinePrefixContainerController method changeSetting.

public void changeSetting(WinePrefixContainerDTO winePrefix, RegistryParameter setting, Runnable doneCallback, Consumer<Exception> errorCallback) {
    final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
    final String registryPatch = registryWriter.generateRegFileContent(setting.toRegistryPatch());
    LOGGER.info("Updating registry for prefix: " + winePrefix.getPath());
    LOGGER.info(registryPatch);
    interactiveScriptSession.eval("include([\"Engines\", \"Wine\", \"Engine\", \"Object\"]);", ignored -> interactiveScriptSession.eval("new Wine()", output -> {
        final ScriptObjectMirror wine = (ScriptObjectMirror) output;
        wine.callMember("prefix", winePrefix.getName());
        final ScriptObjectMirror regedit = (ScriptObjectMirror) wine.callMember("regedit");
        regedit.callMember("patch", registryPatch);
        wine.callMember("wait");
        doneCallback.run();
    }, errorCallback), errorCallback);
}
Also used : Consumer(java.util.function.Consumer) RegistryWriter(org.phoenicis.win32.registry.RegistryWriter) RegistryParameter(org.phoenicis.containers.wine.parameters.RegistryParameter) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) WinePrefixContainerDTO(org.phoenicis.containers.dto.WinePrefixContainerDTO) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) ContainerDTO(org.phoenicis.containers.dto.ContainerDTO) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession)

Example 27 with InteractiveScriptSession

use of org.phoenicis.scripts.interpreter.InteractiveScriptSession in project phoenicis by PhoenicisOrg.

the class WinePrefixContainerController method runInContainer.

public void runInContainer(ContainerDTO container, String command, Runnable doneCallback, Consumer<Exception> errorCallback) {
    final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
    interactiveScriptSession.eval("include([\"Engines\", \"" + container.getEngine() + "\", \"Engine\", \"Object\"]);", ignored -> interactiveScriptSession.eval("new " + container.getEngine() + "()", output -> {
        final ScriptObjectMirror wine = (ScriptObjectMirror) output;
        wine.callMember("prefix", container.getName());
        wine.callMember("run", command);
        wine.callMember("wait");
        doneCallback.run();
    }, errorCallback), errorCallback);
}
Also used : Consumer(java.util.function.Consumer) RegistryWriter(org.phoenicis.win32.registry.RegistryWriter) RegistryParameter(org.phoenicis.containers.wine.parameters.RegistryParameter) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) WinePrefixContainerDTO(org.phoenicis.containers.dto.WinePrefixContainerDTO) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) ContainerDTO(org.phoenicis.containers.dto.ContainerDTO) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession)

Example 28 with InteractiveScriptSession

use of org.phoenicis.scripts.interpreter.InteractiveScriptSession in project phoenicis 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.interpreter.InteractiveScriptSession)

Aggregations

InteractiveScriptSession (org.phoenicis.scripts.interpreter.InteractiveScriptSession)28 ScriptInterpreter (org.phoenicis.scripts.interpreter.ScriptInterpreter)27 Consumer (java.util.function.Consumer)25 ScriptObjectMirror (jdk.nashorn.api.scripting.ScriptObjectMirror)24 List (java.util.List)22 LoggerFactory (org.slf4j.LoggerFactory)22 IOException (java.io.IOException)18 Logger (org.slf4j.Logger)16 File (java.io.File)15 WinePrefixContainerDTO (org.phoenicis.containers.dto.WinePrefixContainerDTO)12 Map (java.util.Map)11 ArrayList (java.util.ArrayList)10 RegistryParameter (org.phoenicis.containers.wine.parameters.RegistryParameter)10 LibraryManager (org.phoenicis.library.LibraryManager)10 ShortcutManager (org.phoenicis.library.ShortcutManager)10 ShortcutCategoryDTO (org.phoenicis.library.dto.ShortcutCategoryDTO)10 RegistryWriter (org.phoenicis.win32.registry.RegistryWriter)10 Platform (javafx.application.Platform)8 Localisation.tr (org.phoenicis.configuration.localisation.Localisation.tr)8 ConfirmMessage (org.phoenicis.javafx.views.common.ConfirmMessage)8