Search in sources :

Example 21 with InteractiveScriptSession

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

the class EnginesController method deleteEngine.

private void deleteEngine(EngineDTO engineDTO, Consumer<Exception> errorCallback) {
    final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
    interactiveScriptSession.eval("include([\"Engines\", \"" + engineDTO.getCategory() + "\", \"Engine\", \"Object\"]);", ignored -> interactiveScriptSession.eval("new Wine()", output -> {
        final ScriptObjectMirror wine = (ScriptObjectMirror) output;
        wine.callMember("delete", engineDTO.getCategory(), engineDTO.getSubCategory(), engineDTO.getVersion(), engineDTO.getUserData());
    }, errorCallback), errorCallback);
}
Also used : RepositoryDTO(org.phoenicis.repository.dto.RepositoryDTO) LoggerFactory(org.slf4j.LoggerFactory) AppsController(org.phoenicis.javafx.controller.apps.AppsController) ArrayList(java.util.ArrayList) TypeDTO(org.phoenicis.repository.dto.TypeDTO) EnginesSource(org.phoenicis.engines.EnginesSource) ConfirmMessage(org.phoenicis.javafx.views.common.ConfirmMessage) URI(java.net.URI) Path(java.nio.file.Path) CategoryDTO(org.phoenicis.repository.dto.CategoryDTO) Files(java.nio.file.Files) ErrorMessage(org.phoenicis.javafx.views.common.ErrorMessage) RepositoryManager(org.phoenicis.repository.RepositoryManager) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) IOException(java.io.IOException) Localisation.tr(org.phoenicis.configuration.localisation.Localisation.tr) File(java.io.File) Platform(javafx.application.Platform) Consumer(java.util.function.Consumer) List(java.util.List) EngineDTO(org.phoenicis.engines.dto.EngineDTO) Optional(java.util.Optional) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) ThemeManager(org.phoenicis.javafx.views.common.ThemeManager) EnginesView(org.phoenicis.javafx.views.mainwindow.engines.EnginesView) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession)

Example 22 with InteractiveScriptSession

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

the class LibraryController method createShortcut.

/**
 * creates a new shortcut
 * @param shortcutCreationDTO DTO describing the new shortcut
 */
private void createShortcut(ShortcutCreationDTO shortcutCreationDTO) {
    // get container
    // TODO: smarter way using container manager
    final String executablePath = shortcutCreationDTO.getExecutable().getAbsolutePath();
    final String pathInContainers = executablePath.replace(containersPath, "");
    final String[] split = pathInContainers.split("/");
    final String engineContainer = split[0];
    final String engine = (Character.toUpperCase(engineContainer.charAt(0)) + engineContainer.substring(1)).replace("prefix", "");
    final String container = split[1];
    final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
    interactiveScriptSession.eval("include([\"Engines\", \"" + engine + "\", \"Shortcuts\", \"" + engine + "\"]);", ignored -> interactiveScriptSession.eval("new " + engine + "Shortcut()", output -> {
        final ScriptObjectMirror shortcutObject = (ScriptObjectMirror) output;
        shortcutObject.callMember("name", shortcutCreationDTO.getName());
        shortcutObject.callMember("category", shortcutCreationDTO.getCategory());
        shortcutObject.callMember("description", shortcutCreationDTO.getDescription());
        shortcutObject.callMember("miniature", shortcutCreationDTO.getMiniature());
        shortcutObject.callMember("search", shortcutCreationDTO.getExecutable().getName());
        shortcutObject.callMember("prefix", container);
        shortcutObject.callMember("create");
    }, e -> this.showErrorMessage(e, tr("Error while creating shortcut"))), e -> this.showErrorMessage(e, tr("Error while creating shortcut")));
}
Also used : ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) LibraryView(org.phoenicis.javafx.views.mainwindow.library.LibraryView) RepositoryDTO(org.phoenicis.repository.dto.RepositoryDTO) ErrorMessage(org.phoenicis.javafx.views.common.ErrorMessage) ShortcutCreationDTO(org.phoenicis.library.dto.ShortcutCreationDTO) RepositoryManager(org.phoenicis.repository.RepositoryManager) ConsoleController(org.phoenicis.javafx.controller.library.console.ConsoleController) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) Localisation.tr(org.phoenicis.configuration.localisation.Localisation.tr) Platform(javafx.application.Platform) Value(org.springframework.beans.factory.annotation.Value) List(java.util.List) ShortcutManager(org.phoenicis.library.ShortcutManager) ShortcutDTO(org.phoenicis.library.dto.ShortcutDTO) ShortcutRunner(org.phoenicis.library.ShortcutRunner) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) ConfirmMessage(org.phoenicis.javafx.views.common.ConfirmMessage) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) LibraryManager(org.phoenicis.library.LibraryManager) Collections(java.util.Collections) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession)

Example 23 with InteractiveScriptSession

use of org.phoenicis.scripts.interpreter.InteractiveScriptSession in project POL-POM-5 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 24 with InteractiveScriptSession

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

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\"]);", ignored -> interactiveScriptSession.eval("new ShortcutReader()", output -> {
        final ScriptObjectMirror shortcutReader = (ScriptObjectMirror) output;
        shortcutReader.callMember("of", shortcutDTO);
        shortcutReader.callMember("uninstall");
    }, errorCallback), errorCallback);
}
Also used : Logger(org.slf4j.Logger) Files(java.nio.file.Files) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LoggerFactory(org.slf4j.LoggerFactory) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) File(java.io.File) ShortcutInfoDTO(org.phoenicis.library.dto.ShortcutInfoDTO) Consumer(java.util.function.Consumer) Safe(org.phoenicis.configuration.security.Safe) ShortcutDTO(org.phoenicis.library.dto.ShortcutDTO) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) URI(java.net.URI) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession)

Example 25 with InteractiveScriptSession

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

the class EnginesSource method fetchAvailableEngines.

public void fetchAvailableEngines(List<CategoryDTO> categoryDTOS, Consumer<List<EngineCategoryDTO>> callback) {
    final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
    StringBuilder includesBuilder = new StringBuilder();
    StringBuilder constructorsBuilder = new StringBuilder();
    constructorsBuilder.append("function fetchEngines() {\n");
    constructorsBuilder.append("var engines = [];\n");
    for (CategoryDTO categoryDTO : categoryDTOS) {
        final String engineName = categoryDTO.getName();
        includesBuilder.append("include([\"Engines\", \"" + engineName + "\", \"Engine\", \"Object\"]);\n");
        constructorsBuilder.append("engines[\"" + engineName + "\"] = new " + engineName + "().getAvailableVersions();\n");
    }
    constructorsBuilder.append("return engines;\n");
    constructorsBuilder.append("}\n");
    constructorsBuilder.append("fetchEngines();");
    interactiveScriptSession.eval(includesBuilder.toString(), ignored -> interactiveScriptSession.eval(constructorsBuilder.toString(), output -> {
        List<EngineCategoryDTO> engines = new ArrayList<>();
        for (Map.Entry<String, Object> entry : ((Map<String, Object>) output).entrySet()) {
            final EngineCategoryDTO engineCategoryDTO = new EngineCategoryDTO.Builder().withName(entry.getKey()).withDescription(entry.getKey()).withSubCategories(unSerialize(entry.getValue())).build();
            engines.add(engineCategoryDTO);
        }
        callback.accept(engines);
    }, this::throwError), this::throwError);
}
Also used : CategoryDTO(org.phoenicis.repository.dto.CategoryDTO) EngineCategoryDTO(org.phoenicis.engines.dto.EngineCategoryDTO) EngineSubCategoryDTO(org.phoenicis.engines.dto.EngineSubCategoryDTO) CategoryDTO(org.phoenicis.repository.dto.CategoryDTO) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LoggerFactory(org.slf4j.LoggerFactory) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) IOException(java.io.IOException) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) List(java.util.List) EngineCategoryDTO(org.phoenicis.engines.dto.EngineCategoryDTO) Safe(org.phoenicis.configuration.security.Safe) Map(java.util.Map) TypeReference(com.fasterxml.jackson.core.type.TypeReference) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) EngineSubCategoryDTO(org.phoenicis.engines.dto.EngineSubCategoryDTO) Collections(java.util.Collections) EngineCategoryDTO(org.phoenicis.engines.dto.EngineCategoryDTO) ArrayList(java.util.ArrayList) List(java.util.List) 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