Search in sources :

Example 1 with InteractiveScriptSession

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);
}
Also used : ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) ContainerCategoryDTO(org.phoenicis.containers.dto.ContainerCategoryDTO) LoggerFactory(org.slf4j.LoggerFactory) ShortcutReader(org.phoenicis.library.ShortcutReader) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) Map(java.util.Map) ShortcutDTO(org.phoenicis.library.dto.ShortcutDTO) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ContainerDTO(org.phoenicis.containers.dto.ContainerDTO) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) InteractiveScriptSession(org.phoenicis.scripts.session.InteractiveScriptSession) Consumer(java.util.function.Consumer) List(java.util.List) ShortcutManager(org.phoenicis.library.ShortcutManager) ConfigFile(org.phoenicis.tools.config.ConfigFile) Safe(org.phoenicis.configuration.security.Safe) CompatibleConfigFileFormatFactory(org.phoenicis.tools.config.CompatibleConfigFileFormatFactory) CollectionUtils(org.springframework.util.CollectionUtils) WinePrefixContainerDTO(org.phoenicis.containers.dto.WinePrefixContainerDTO) LibraryManager(org.phoenicis.library.LibraryManager) Collections(java.util.Collections) IOException(java.io.IOException) ShortcutReader(org.phoenicis.library.ShortcutReader) Value(org.springframework.beans.factory.annotation.Value) ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) InteractiveScriptSession(org.phoenicis.scripts.session.InteractiveScriptSession) File(java.io.File) ConfigFile(org.phoenicis.tools.config.ConfigFile)

Example 2 with InteractiveScriptSession

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);
}
Also used : Value(org.graalvm.polyglot.Value) InteractiveScriptSession(org.phoenicis.scripts.session.InteractiveScriptSession)

Example 3 with InteractiveScriptSession

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);
}
Also used : Value(org.graalvm.polyglot.Value) InteractiveScriptSession(org.phoenicis.scripts.session.InteractiveScriptSession)

Example 4 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 5 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)

Aggregations

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