use of com.stardust.autojs.script.ScriptSource in project Auto.js by hyb1996.
the class ScriptEngineService method execute.
public ScriptExecution execute(ScriptExecutionTask task) {
if (task.getListener() != null) {
task.setExecutionListener(new ScriptExecutionObserver.Wrapper(mScriptExecutionObserver, task.getListener()));
} else {
task.setExecutionListener(mScriptExecutionObserver);
}
ScriptSource source = task.getSource();
if (source instanceof JavaScriptSource) {
int mode = ((JavaScriptSource) source).getExecutionMode();
if ((mode & JavaScriptSource.EXECUTION_MODE_UI) != 0) {
return ScriptExecuteActivity.execute(mContext, mScriptEngineManager, task);
}
}
RunnableScriptExecution r;
if (source instanceof JavaScriptSource) {
r = new LoopedBasedJavaScriptExecution(mScriptEngineManager, task);
} else {
r = new RunnableScriptExecution(mScriptEngineManager, task);
}
if (task.getConfig().runInNewThread) {
new ThreadCompat(r).start();
} else {
r.run();
}
return r;
}
use of com.stardust.autojs.script.ScriptSource in project Auto.js by hyb1996.
the class ScriptIntents method handleIntent.
public static boolean handleIntent(Context context, Intent intent) {
String path = getPath(intent);
String script = intent.getStringExtra(ScriptIntents.EXTRA_KEY_PRE_EXECUTE_SCRIPT);
int loopTimes = intent.getIntExtra(EXTRA_KEY_LOOP_TIMES, 1);
long delay = intent.getLongExtra(EXTRA_KEY_DELAY, 0);
long interval = intent.getLongExtra(EXTRA_KEY_LOOP_INTERVAL, 0);
ScriptSource source = null;
ExecutionConfig config = new ExecutionConfig().loop(delay, loopTimes, interval);
if (path == null && script != null) {
source = new StringScriptSource(script);
} else if (path != null && new PathChecker(context).checkAndToastError(path)) {
JavaScriptFileSource fileScriptSource = new JavaScriptFileSource(path);
if (script != null) {
source = new SequenceScriptSource(fileScriptSource.getName(), new StringScriptSource(script), fileScriptSource);
} else {
source = fileScriptSource;
}
config.executePath(new File(path).getParent());
} else {
config.executePath(StorageFileProvider.DEFAULT_DIRECTORY_PATH);
}
if (source == null) {
return false;
}
AutoJs.getInstance().getScriptEngineService().execute(source, config);
return true;
}
use of com.stardust.autojs.script.ScriptSource in project Auto.js by hyb1996.
the class Scripts method runRepeatedly.
public static ScriptExecution runRepeatedly(ScriptFile scriptFile, int loopTimes, long delay, long interval) {
ScriptSource source = scriptFile.toSource();
String directoryPath = scriptFile.getParent();
return AutoJs.getInstance().getScriptEngineService().execute(source, new ExecutionConfig().executePath(directoryPath).loop(delay, loopTimes, interval));
}
use of com.stardust.autojs.script.ScriptSource in project Auto.js by hyb1996.
the class RunnableScriptExecution method doExecution.
protected Object doExecution(ScriptEngine engine) {
engine.setTag(ScriptEngine.TAG_SOURCE, getSource());
getListener().onStart(this);
Object result = null;
long delay = getConfig().delay;
int times = getConfig().loopTimes;
if (times == 0) {
times = Integer.MAX_VALUE;
}
long interval = getConfig().interval;
sleep(delay);
ScriptSource source = getSource();
for (int i = 0; i < times; i++) {
result = execute(engine, source);
sleep(interval);
}
return result;
}
Aggregations