Search in sources :

Example 1 with StringScriptSource

use of com.stardust.autojs.script.StringScriptSource 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 2 with StringScriptSource

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

the class RunIntentActivity method handleIntent.

private void handleIntent(Intent intent) throws FileNotFoundException {
    Uri uri = intent.getData();
    if (uri != null && "content".equals(uri.getScheme())) {
        InputStream stream = getContentResolver().openInputStream(uri);
        Scripts.run(new StringScriptSource(PFiles.read(stream)));
    } else {
        ScriptIntents.handleIntent(this, intent);
    }
}
Also used : StringScriptSource(com.stardust.autojs.script.StringScriptSource) InputStream(java.io.InputStream) Uri(android.net.Uri)

Aggregations

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