Search in sources :

Example 1 with JavaScriptFileSource

use of com.stardust.autojs.script.JavaScriptFileSource in project Auto.js by hyb1996.

the class AssetsProjectLauncher method runScript.

private void runScript() {
    try {
        JavaScriptFileSource source = new JavaScriptFileSource("main", mMainScriptFile);
        AutoJs.getInstance().getScriptEngineService().execute(source, new ExecutionConfig().executePath(mProjectDir));
    } catch (Exception e) {
        AutoJs.getInstance().getGlobalConsole().error(e);
    }
}
Also used : JavaScriptFileSource(com.stardust.autojs.script.JavaScriptFileSource) ExecutionConfig(com.stardust.autojs.execution.ExecutionConfig)

Example 2 with JavaScriptFileSource

use of com.stardust.autojs.script.JavaScriptFileSource 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)

Aggregations

ExecutionConfig (com.stardust.autojs.execution.ExecutionConfig)2 JavaScriptFileSource (com.stardust.autojs.script.JavaScriptFileSource)2 ScriptSource (com.stardust.autojs.script.ScriptSource)1 SequenceScriptSource (com.stardust.autojs.script.SequenceScriptSource)1 StringScriptSource (com.stardust.autojs.script.StringScriptSource)1 PathChecker (com.stardust.scriptdroid.model.script.PathChecker)1 File (java.io.File)1