From 6a2d8c587c6aa548884ef4e98ef1658b7db7ed86 Mon Sep 17 00:00:00 2001 From: f43nd1r Date: Sat, 9 Feb 2019 02:16:46 +0100 Subject: [PATCH] fix executor issues by utilizing already present code --- app/llx/app/src/main/AndroidManifest.xml | 1 + .../util/PluginService.java | 32 +------------------ .../lightning_launcher/script/Script.java | 1 + .../script/ScriptExecutor.java | 11 +++++++ 4 files changed, 14 insertions(+), 31 deletions(-) diff --git a/app/llx/app/src/main/AndroidManifest.xml b/app/llx/app/src/main/AndroidManifest.xml index 3863939..b512f26 100644 --- a/app/llx/app/src/main/AndroidManifest.xml +++ b/app/llx/app/src/main/AndroidManifest.xml @@ -27,6 +27,7 @@ + diff --git a/app/llx/app/src/main/java/net/pierrox/lightning_launcher/util/PluginService.java b/app/llx/app/src/main/java/net/pierrox/lightning_launcher/util/PluginService.java index ee8a926..378cf27 100644 --- a/app/llx/app/src/main/java/net/pierrox/lightning_launcher/util/PluginService.java +++ b/app/llx/app/src/main/java/net/pierrox/lightning_launcher/util/PluginService.java @@ -3,7 +3,6 @@ package net.pierrox.lightning_launcher.util; import android.app.Service; import android.content.Intent; import android.os.IBinder; -import com.faendir.rhino_android.RhinoAndroidHelper; import net.pierrox.lightning_launcher.LLApp; import net.pierrox.lightning_launcher.api.ScreenIdentity; import net.pierrox.lightning_launcher.api.ScreenNotAvailableException; @@ -16,11 +15,6 @@ import net.pierrox.lightning_launcher.plugin.IPluginService; import net.pierrox.lightning_launcher.plugin.IPluginService_Stub; import net.pierrox.lightning_launcher.script.ScriptExecutor; import net.pierrox.lightning_launcher.script.ScriptManager; -import org.mozilla.javascript.RhinoException; -import org.mozilla.javascript.Scriptable; -import org.mozilla.javascript.ScriptableObject; - -import static net.pierrox.lightning_launcher.script.ScriptExecutor.PROPERTY_EVENT_SCREEN; /** * @author lukas @@ -104,30 +98,6 @@ public class PluginService extends Service implements IPluginService { throw new ScreenNotAvailableException(); } ScriptExecutor executor = mEngine.getScriptExecutor(); - if (executor.canRunScriptGlobally()) { - Scriptable scope = executor.prepareScriptScope(); - org.mozilla.javascript.Context cx = RhinoAndroidHelper.prepareContext(); - - ScriptableObject.putProperty(scope, PROPERTY_EVENT_SCREEN, screen); - ScriptableObject.putProperty(scope, "ev_se", "DIRECT_PLUGIN"); - ScriptableObject.putProperty(scope, "ev_d", null); - ScriptableObject.putProperty(scope, "ev_t", System.currentTimeMillis()); - ScriptableObject.putProperty(scope, "ev_il", null); - ScriptableObject.putProperty(scope, "ev_iv", null); - try { - String script = "javascript:(function() {var _event = createEvent(ev_sc, ev_se, ev_d, ev_t, ev_il, ev_iv); var getEvent = function() { return _event;};\n" + code + "\n})();"; - cx.setOptimizationLevel(-1); - org.mozilla.javascript.Script compiledScript = cx.compileString(script, null, 0, null); - if (compiledScript != null) { - return String.valueOf(compiledScript.exec(cx, scope)); - } - } catch (RhinoException e) { - e.printStackTrace(); - } finally { - // Exit from the context. - org.mozilla.javascript.Context.exit(); - } - } - return null; + return String.valueOf(executor.runScriptAsFunction(screen, code, "", new Object[0], false, true)); } } diff --git a/app/llx/core/src/main/java/net/pierrox/lightning_launcher/script/Script.java b/app/llx/core/src/main/java/net/pierrox/lightning_launcher/script/Script.java index 611b697..cf9e698 100644 --- a/app/llx/core/src/main/java/net/pierrox/lightning_launcher/script/Script.java +++ b/app/llx/core/src/main/java/net/pierrox/lightning_launcher/script/Script.java @@ -17,6 +17,7 @@ public class Script extends JsonLoader { public static final int TYPE_BUILTIN = 1; public static final int TYPE_TARGET = 2; public static final int TYPE_SET_VARIABLE = 3; + public static final int TYPE_IN_MEMORY = 4; public static final int TARGET_NONE = -1; public static final int TARGET_DESKTOP = 0; diff --git a/app/llx/core/src/main/java/net/pierrox/lightning_launcher/script/ScriptExecutor.java b/app/llx/core/src/main/java/net/pierrox/lightning_launcher/script/ScriptExecutor.java index f946238..d1d8ece 100644 --- a/app/llx/core/src/main/java/net/pierrox/lightning_launcher/script/ScriptExecutor.java +++ b/app/llx/core/src/main/java/net/pierrox/lightning_launcher/script/ScriptExecutor.java @@ -671,7 +671,18 @@ public class ScriptExecutor { if(!canRunScript(script)) { return null; } + return runScriptAsFunction(screen, script, parameters, arguments, allow_continuation, display_errors); + } + public Object runScriptAsFunction(Screen screen, String code, String parameters, Object[] arguments, boolean allow_continuation, boolean display_errors) { + if(!canRunScriptGlobally()) { + return null; + } + Script script = new Script(mEngine.getScriptManager(), Script.TYPE_IN_MEMORY, Script.NO_ID, null, code, null); + return runScriptAsFunction(screen, script, parameters, arguments, allow_continuation, display_errors); + } + + private Object runScriptAsFunction(Screen screen, Script script, String parameters, Object[] arguments, boolean allow_continuation, boolean display_errors) { mCurrentScript = script; if(mCurrentScript != null && !mCurrentScript.hasFlag(Script.FLAG_DISABLED)) { prepareScriptScope();