imporve script execution of tasker plugin, fix sublime plugin large file issue
This commit is contained in:
@@ -1,7 +1,18 @@
|
||||
package com.stardust.scriptdroid.external;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.stardust.autojs.script.FileScriptSource;
|
||||
import com.stardust.autojs.script.ScriptSource;
|
||||
import com.stardust.autojs.script.SequenceScriptSource;
|
||||
import com.stardust.autojs.script.StringScriptSource;
|
||||
import com.stardust.scriptdroid.script.PathChecker;
|
||||
import com.stardust.scriptdroid.script.Scripts;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/4/1.
|
||||
*/
|
||||
@@ -16,4 +27,33 @@ public class CommonUtils {
|
||||
return bundle.containsKey(CommonUtils.EXTRA_KEY_PATH) || bundle.containsKey(EXTRA_KEY_PRE_EXECUTE_SCRIPT);
|
||||
}
|
||||
|
||||
public static void handleIntent(Context context, Intent intent) {
|
||||
String path = getPath(intent);
|
||||
String directoryPath = null;
|
||||
String script = intent.getStringExtra(CommonUtils.EXTRA_KEY_PRE_EXECUTE_SCRIPT);
|
||||
ScriptSource source = null;
|
||||
if (path == null && script != null) {
|
||||
source = new StringScriptSource(script);
|
||||
} else if (path != null && new PathChecker(context).checkAndToastError(path)) {
|
||||
ScriptSource fileScriptSource = new FileScriptSource(path);
|
||||
if (script != null) {
|
||||
source = new SequenceScriptSource(fileScriptSource.getName(), new StringScriptSource(script), fileScriptSource);
|
||||
} else {
|
||||
source = fileScriptSource;
|
||||
}
|
||||
directoryPath = new File(path).getParent();
|
||||
}
|
||||
if (source != null) {
|
||||
if (directoryPath == null)
|
||||
Scripts.run(source);
|
||||
else
|
||||
Scripts.run(source, directoryPath);
|
||||
}
|
||||
}
|
||||
|
||||
private static String getPath(Intent intent) {
|
||||
if (intent.getData() != null && intent.getData().getPath() != null)
|
||||
return intent.getData().getPath();
|
||||
return intent.getStringExtra(CommonUtils.EXTRA_KEY_PATH);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,41 +27,11 @@ public class RunIntentActivity extends Activity {
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
try {
|
||||
handleIntent(getIntent());
|
||||
CommonUtils.handleIntent(this, getIntent());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(this, R.string.edit_and_run_handle_intent_error, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
private void handleIntent(Intent intent) {
|
||||
String path = getPath(intent);
|
||||
String directoryPath = null;
|
||||
String script = intent.getStringExtra(CommonUtils.EXTRA_KEY_PRE_EXECUTE_SCRIPT);
|
||||
ScriptSource source = null;
|
||||
if (path == null && script != null) {
|
||||
source = new StringScriptSource(script);
|
||||
} else if (path != null && new PathChecker(this).checkAndToastError(path)) {
|
||||
ScriptSource fileScriptSource = new FileScriptSource(path);
|
||||
if (script != null) {
|
||||
source = new SequenceScriptSource(fileScriptSource.getName(), new StringScriptSource(script), fileScriptSource);
|
||||
} else {
|
||||
source = fileScriptSource;
|
||||
}
|
||||
directoryPath = new File(path).getParent();
|
||||
}
|
||||
if (source != null) {
|
||||
if (directoryPath == null)
|
||||
Scripts.run(source);
|
||||
else
|
||||
Scripts.run(source, directoryPath);
|
||||
}
|
||||
}
|
||||
|
||||
private String getPath(Intent intent) {
|
||||
if (intent.getData() != null && intent.getData().getPath() != null)
|
||||
return intent.getData().getPath();
|
||||
return intent.getStringExtra(CommonUtils.EXTRA_KEY_PATH);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class FireSettingReceiver extends AbstractPluginSettingReceiver {
|
||||
|
||||
@Override
|
||||
protected void firePluginSetting(@NonNull Context context, @NonNull Bundle bundle) {
|
||||
context.startActivity(new Intent(App.getApp(), RunIntentActivity.class)
|
||||
CommonUtils.handleIntent(context, new Intent(App.getApp(), RunIntentActivity.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.putExtra(CommonUtils.EXTRA_KEY_PATH, bundle.getString(CommonUtils.EXTRA_KEY_PATH))
|
||||
.putExtra(CommonUtils.EXTRA_KEY_PRE_EXECUTE_SCRIPT, bundle.getString(CommonUtils.EXTRA_KEY_PRE_EXECUTE_SCRIPT)));
|
||||
|
||||
Reference in New Issue
Block a user