use of jdk.nashorn.api.scripting.ScriptObjectMirror in project POL-POM-5 by PlayOnLinux.
the class NashornEngineFactory method createEngine.
NashornEngine createEngine() {
final Set<List<String>> includedScripts = new HashSet<>();
final NashornEngine nashornEngine = new NashornEngine(new ScriptEngineManager().getEngineByName("nashorn"));
nashornEngine.eval(new InputStreamReader(getClass().getResourceAsStream("utils.js")), this::throwException);
nashornEngine.put("Bean", (Function<String, Object>) title -> applicationContext.getBean(title), this::throwException);
nashornEngine.put("SetupWizard", (Function<String, UiSetupWizardImplementation>) (name) -> {
final UiSetupWizardImplementation uiSetupWizardImplementation = uiSetupWizardFactory.create(name);
nashornEngine.addErrorHandler(e -> uiSetupWizardImplementation.close());
return uiSetupWizardImplementation;
}, this::throwException);
nashornEngine.put("EngineProgressUi", (Function<String, UiProgressWizardImplementation>) (name) -> {
final UiProgressWizardImplementation uiProgressWizardImplementation = uiProgressWizardFactory.create(name);
nashornEngine.addErrorHandler(e -> uiProgressWizardImplementation.close());
return uiProgressWizardImplementation;
}, this::throwException);
nashornEngine.put("include", (Consumer<ScriptObjectMirror>) args -> {
final String[] arguments = args.to(String[].class);
final String script = scriptFetcher.getScript(arguments);
if (script == null) {
throwException(new ScriptException(Arrays.asList(arguments).toString() + " is not found"));
}
if (includedScripts.add(Arrays.asList(arguments))) {
nashornEngine.eval("//# sourceURL=" + Arrays.asList(arguments).toString() + "\n" + script, this::throwException);
}
}, this::throwException);
return nashornEngine;
}
use of jdk.nashorn.api.scripting.ScriptObjectMirror in project POL-POM-5 by PlayOnLinux.
the class WinePrefixContainerController method repairPrefix.
public void repairPrefix(WinePrefixContainerDTO winePrefix, Runnable doneCallback, Consumer<Exception> errorCallback) {
// FIXME
final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
interactiveScriptSession.eval("include([\"Functions\", \"Engines\", \"Wine\"]);", ignored -> interactiveScriptSession.eval("new Wine()", output -> {
final ScriptObjectMirror wine = (ScriptObjectMirror) output;
wine.callMember("prefix", winePrefix.getName());
wine.callMember("run", "wineboot");
wine.callMember("wait");
doneCallback.run();
}, errorCallback), errorCallback);
}
use of jdk.nashorn.api.scripting.ScriptObjectMirror in project POL-POM-5 by PlayOnLinux.
the class WinePrefixContainerController method deletePrefix.
public void deletePrefix(WinePrefixContainerDTO winePrefix, Consumer<Exception> errorCallback) {
try {
fileUtilities.remove(new File(winePrefix.getPath()));
} catch (IOException e) {
LOGGER.error("Cannot delete Wine prefix (" + winePrefix.getPath() + ")! Exception: " + e.toString());
errorCallback.accept(e);
}
List<ShortcutCategoryDTO> categories = libraryManager.fetchShortcuts();
categories.stream().flatMap(shortcutCategoryDTO -> shortcutCategoryDTO.getShortcuts().stream()).forEach(shortcutDTO -> {
final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
interactiveScriptSession.eval("include([\"Functions\", \"Shortcuts\", \"Reader\"]);", ignored -> interactiveScriptSession.eval("new ShortcutReader()", output -> {
final ScriptObjectMirror shortcutReader = (ScriptObjectMirror) output;
shortcutReader.callMember("of", shortcutDTO);
final String container = (String) shortcutReader.callMember("container");
if (container.equals(winePrefix.getName())) {
shortcutManager.deleteShortcut(shortcutDTO);
}
}, errorCallback), errorCallback);
});
}
use of jdk.nashorn.api.scripting.ScriptObjectMirror in project POL-POM-5 by PlayOnLinux.
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([\"Functions\", \"Engines\", \"Wine\"]);", 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);
}
use of jdk.nashorn.api.scripting.ScriptObjectMirror in project POL-POM-5 by PlayOnLinux.
the class WinePrefixContainerController method createShortcut.
/**
* creates a shortcut for a given executable in a Wine prefix
* @param winePrefix the Wine prefix
* @param name name which is shown in the library
* @param executable filename of the executable (WineShortcut will search for this file in the given prefix)
* @param doneCallback callback executed after the shortcut has been created
* @param errorCallback callback executed if there is an error
*/
public void createShortcut(WinePrefixContainerDTO winePrefix, String name, String executable, Runnable doneCallback, Consumer<Exception> errorCallback) {
final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
interactiveScriptSession.eval("include([\"Functions\", \"Shortcuts\", \"Wine\"]);", ignored -> interactiveScriptSession.eval("new WineShortcut()", output -> {
final ScriptObjectMirror wine = (ScriptObjectMirror) output;
wine.callMember("name", name);
wine.callMember("search", executable);
wine.callMember("prefix", winePrefix.getName());
wine.callMember("create");
doneCallback.run();
}, errorCallback), errorCallback);
}
Aggregations