Search in sources :

Example 1 with ScriptSource

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;
}
Also used : ThreadCompat(com.stardust.lang.ThreadCompat) JavaScriptSource(com.stardust.autojs.script.JavaScriptSource) RunnableScriptExecution(com.stardust.autojs.execution.RunnableScriptExecution) LoopedBasedJavaScriptExecution(com.stardust.autojs.execution.LoopedBasedJavaScriptExecution) JavaScriptSource(com.stardust.autojs.script.JavaScriptSource) ScriptSource(com.stardust.autojs.script.ScriptSource) ScriptExecutionObserver(com.stardust.autojs.execution.ScriptExecutionObserver)

Example 2 with ScriptSource

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;
}
Also used : StringScriptSource(com.stardust.autojs.script.StringScriptSource) JavaScriptFileSource(com.stardust.autojs.script.JavaScriptFileSource) SequenceScriptSource(com.stardust.autojs.script.SequenceScriptSource) ExecutionConfig(com.stardust.autojs.execution.ExecutionConfig) ScriptSource(com.stardust.autojs.script.ScriptSource) StringScriptSource(com.stardust.autojs.script.StringScriptSource) SequenceScriptSource(com.stardust.autojs.script.SequenceScriptSource) File(java.io.File) PathChecker(com.stardust.scriptdroid.model.script.PathChecker)

Example 3 with ScriptSource

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));
}
Also used : ExecutionConfig(com.stardust.autojs.execution.ExecutionConfig) ScriptSource(com.stardust.autojs.script.ScriptSource)

Example 4 with ScriptSource

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;
}
Also used : ScriptSource(com.stardust.autojs.script.ScriptSource)

Aggregations

ScriptSource (com.stardust.autojs.script.ScriptSource)4 ExecutionConfig (com.stardust.autojs.execution.ExecutionConfig)2 LoopedBasedJavaScriptExecution (com.stardust.autojs.execution.LoopedBasedJavaScriptExecution)1 RunnableScriptExecution (com.stardust.autojs.execution.RunnableScriptExecution)1 ScriptExecutionObserver (com.stardust.autojs.execution.ScriptExecutionObserver)1 JavaScriptFileSource (com.stardust.autojs.script.JavaScriptFileSource)1 JavaScriptSource (com.stardust.autojs.script.JavaScriptSource)1 SequenceScriptSource (com.stardust.autojs.script.SequenceScriptSource)1 StringScriptSource (com.stardust.autojs.script.StringScriptSource)1 ThreadCompat (com.stardust.lang.ThreadCompat)1 PathChecker (com.stardust.scriptdroid.model.script.PathChecker)1 File (java.io.File)1