use of org.phoenicis.scripts.session.InteractiveScriptSession in project POL-POM-5 by PlayOnLinux.
the class GenericContainersManager method deleteContainer.
/**
* {@inheritDoc}
*/
@Override
public void deleteContainer(ContainerDTO container, Consumer<ContainerDTO> onSuccess, Consumer<Exception> onError) {
try {
final File containerFile = new File(container.getPath());
FileUtils.deleteDirectory(containerFile);
} catch (IOException e) {
LOGGER.error("Cannot delete container (" + container.getPath() + ")! Exception: " + e.toString());
onError.accept(e);
}
// TODO: better way to get engine ID
final String engineId = container.getEngine().toLowerCase();
final List<ShortcutCategoryDTO> categories = this.libraryManager.fetchShortcuts();
// remove the shortcuts leading to the container
categories.stream().flatMap(shortcutCategory -> shortcutCategory.getShortcuts().stream()).forEach(shortcut -> {
final InteractiveScriptSession interactiveScriptSession = this.scriptInterpreter.createInteractiveSession();
interactiveScriptSession.eval("include(\"engines." + engineId + ".shortcuts.reader\");", result -> {
final org.graalvm.polyglot.Value shortcutReaderClass = (org.graalvm.polyglot.Value) result;
final ShortcutReader shortcutReader = shortcutReaderClass.newInstance().as(ShortcutReader.class);
shortcutReader.of(shortcut);
final String containerName = shortcutReader.getContainer();
if (containerName.equals(container.getName())) {
this.shortcutManager.deleteShortcut(shortcut);
}
}, onError);
});
onSuccess.accept(container);
}
use of org.phoenicis.scripts.session.InteractiveScriptSession in project POL-POM-5 by PlayOnLinux.
the class ShortcutManager method uninstallFromShortcut.
public void uninstallFromShortcut(ShortcutDTO shortcutDTO, Consumer<Exception> errorCallback) {
final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
interactiveScriptSession.eval("include(\"engines.wine.shortcuts.reader\");", result -> {
Value shortcutReaderClass = (Value) result;
ShortcutReader shortcutReader = shortcutReaderClass.newInstance().as(ShortcutReader.class);
shortcutReader.of(shortcutDTO);
shortcutReader.uninstall();
}, errorCallback);
}
use of org.phoenicis.scripts.session.InteractiveScriptSession in project POL-POM-5 by PlayOnLinux.
the class ShortcutRunner method stop.
public void stop(ShortcutDTO shortcutDTO, Consumer<Exception> errorCallback) {
final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
interactiveScriptSession.eval("include(\"engines.wine.shortcuts.reader\");", result -> {
Value shortcutReaderClass = (Value) result;
ShortcutReader shortcutReader = shortcutReaderClass.newInstance().as(ShortcutReader.class);
shortcutReader.of(shortcutDTO);
shortcutReader.stop();
}, errorCallback);
}
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;
}
Aggregations