feat(autojs): engines.myEngine().execArgv
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
module.exports = function(__runtime__, scope){
|
module.exports = function(__runtime__, scope){
|
||||||
var rtEngines = __runtime__.engines;
|
var rtEngines = __runtime__.engines;
|
||||||
|
var execArgv = null;
|
||||||
|
|
||||||
var engines = {};
|
var engines = {};
|
||||||
|
|
||||||
@@ -17,7 +18,17 @@ module.exports = function(__runtime__, scope){
|
|||||||
}
|
}
|
||||||
|
|
||||||
engines.myEngine = function(){
|
engines.myEngine = function(){
|
||||||
return rtEngines.myEngine();
|
var engine = Object.create(rtEngines.myEngine());
|
||||||
|
if(!execArgv){
|
||||||
|
execArgv = {};
|
||||||
|
var iter = engine.getTag("execution.config").getArguments().entrySet().iterator();
|
||||||
|
while(iter.hasNext()){
|
||||||
|
var entry = iter.next();
|
||||||
|
execArgv[entry.getKey()] = entry.getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
engine.execArgv = execArgv;
|
||||||
|
return engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
engines.all = function(){
|
engines.all = function(){
|
||||||
@@ -44,6 +55,14 @@ module.exports = function(__runtime__, scope){
|
|||||||
c.interval = c.interval || 0;
|
c.interval = c.interval || 0;
|
||||||
c.loopTimes = c.loopTimes || 1;
|
c.loopTimes = c.loopTimes || 1;
|
||||||
config.loop(c.delay, c.loopTimes, c.interval);
|
config.loop(c.delay, c.loopTimes, c.interval);
|
||||||
|
if(c.arguments){
|
||||||
|
var arguments = c.arguments;
|
||||||
|
for(var key in arguments){
|
||||||
|
if(arguments.hasOwnProperty(key)){
|
||||||
|
config.setArgument(key, arguments[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,22 +4,25 @@ import java.io.Serializable;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Stardust on 2017/2/1.
|
* Created by Stardust on 2017/2/1.
|
||||||
*/
|
*/
|
||||||
public class ExecutionConfig implements Serializable {
|
public class ExecutionConfig implements Serializable {
|
||||||
|
|
||||||
|
public static final String TAG = "execution.config";
|
||||||
private List<String> mRequirePath = Collections.emptyList();
|
private List<String> mRequirePath = Collections.emptyList();
|
||||||
private String mExecutePath;
|
private String mExecutePath;
|
||||||
private static final ExecutionConfig DEFAULT = new ExecutionConfig();
|
|
||||||
public long delay = 0;
|
public long delay = 0;
|
||||||
public long interval = 0;
|
public long interval = 0;
|
||||||
public int loopTimes = 1;
|
public int loopTimes = 1;
|
||||||
|
private Map<String, Object> mArguments = new HashMap<>();
|
||||||
|
|
||||||
public static ExecutionConfig getDefault() {
|
public static ExecutionConfig getDefault() {
|
||||||
return DEFAULT;
|
return new ExecutionConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean runInNewThread = true;
|
public boolean runInNewThread = true;
|
||||||
@@ -50,6 +53,18 @@ public class ExecutionConfig implements Serializable {
|
|||||||
return mExecutePath;
|
return mExecutePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setArgument(String key, Object object){
|
||||||
|
mArguments.put(key, object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getArgument(String key){
|
||||||
|
return mArguments.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getArguments() {
|
||||||
|
return mArguments;
|
||||||
|
}
|
||||||
|
|
||||||
public ExecutionConfig loop(long delay, int loopTimes, long interval) {
|
public ExecutionConfig loop(long delay, int loopTimes, long interval) {
|
||||||
this.delay = delay;
|
this.delay = delay;
|
||||||
this.loopTimes = loopTimes;
|
this.loopTimes = loopTimes;
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ public class RunnableScriptExecution extends ScriptExecution.AbstractScriptExecu
|
|||||||
|
|
||||||
public Object execute() {
|
public Object execute() {
|
||||||
mScriptEngine = mScriptEngineManager.createEngineOfSourceOrThrow(getSource(), getId());
|
mScriptEngine = mScriptEngineManager.createEngineOfSourceOrThrow(getSource(), getId());
|
||||||
|
mScriptEngine.setTag(ExecutionConfig.TAG, getConfig());
|
||||||
return execute(mScriptEngine);
|
return execute(mScriptEngine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -252,6 +252,7 @@ public class ScriptExecuteActivity extends AppCompatActivity {
|
|||||||
mScriptEngine.forceStop();
|
mScriptEngine.forceStop();
|
||||||
}
|
}
|
||||||
mScriptEngine = mScriptEngineManager.createEngineOfSourceOrThrow(getSource());
|
mScriptEngine = mScriptEngineManager.createEngineOfSourceOrThrow(getSource());
|
||||||
|
mScriptEngine.setTag(ExecutionConfig.TAG, getConfig());
|
||||||
return mScriptEngine;
|
return mScriptEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user