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;
}
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();
}));
}
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;
}
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);
}
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);
}
Aggregations