imporve script execution of tasker plugin, fix sublime plugin large file issue
This commit is contained in:
@@ -27,6 +27,9 @@ import com.stardust.theme.ThemeColor;
|
||||
import com.stardust.theme.ThemeColorManager;
|
||||
import com.stardust.util.ScreenMetrics;
|
||||
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.mozilla.javascript.tools.debugger.GuiCallback;
|
||||
public class Pref {
|
||||
|
||||
private static final SharedPreferences DISPOSABLE_BOOLEAN = App.getApp().getSharedPreferences("DISPOSABLE_BOOLEAN", Context.MODE_PRIVATE);
|
||||
private static final String KEY_SERVER_ADDRESS = "Still love you...17.5.14";
|
||||
private static SharedPreferences.OnSharedPreferenceChangeListener onSharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
@@ -116,4 +117,11 @@ public class Pref {
|
||||
return getDisposableBoolean("Still Love Eating 17.4.6", true);
|
||||
}
|
||||
|
||||
public static String getServerAddressOrDefault(String defaultAddress) {
|
||||
return def().getString(KEY_SERVER_ADDRESS, defaultAddress);
|
||||
}
|
||||
|
||||
public static void saveServerAddress(String address) {
|
||||
def().edit().putString(KEY_SERVER_ADDRESS, address).apply();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.stardust.scriptdroid.script;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.Toast;
|
||||
@@ -17,10 +18,10 @@ import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||
public class PathChecker {
|
||||
public static final int CHECK_RESULT_OK = 0;
|
||||
|
||||
private Activity mActivity;
|
||||
private Context mContext;
|
||||
|
||||
public PathChecker(Activity activity) {
|
||||
mActivity = activity;
|
||||
public PathChecker(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,14 +36,14 @@ public class PathChecker {
|
||||
public boolean checkAndToastError(String path) {
|
||||
int result = checkWithStoragePermission(path);
|
||||
if (result != CHECK_RESULT_OK) {
|
||||
Toast.makeText(mActivity, result, Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(mContext, mContext.getString(result) + ":" + path, Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private int checkWithStoragePermission(String path) {
|
||||
if (!hasStorageReadPermission(mActivity)) {
|
||||
if (mContext instanceof Activity && !hasStorageReadPermission((Activity) mContext)) {
|
||||
return com.stardust.autojs.R.string.text_no_file_rw_permission;
|
||||
}
|
||||
return check(path);
|
||||
|
||||
@@ -9,8 +9,10 @@ import com.stardust.util.UiHandler;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
import java.util.concurrent.Executor;
|
||||
@@ -117,15 +119,14 @@ public class SublimePluginClient {
|
||||
}
|
||||
|
||||
private void startReadLoop(InputStream stream) throws IOException {
|
||||
byte[] buffer = new byte[8192];
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
int len = stream.read(buffer);
|
||||
if (len <= 0) {
|
||||
String line = reader.readLine();
|
||||
if (line == null) {
|
||||
return;
|
||||
}
|
||||
if (mResponseHandler != null) {
|
||||
String str = new String(buffer, 0, len);
|
||||
JsonElement jsonElement = new JsonParser().parse(str);
|
||||
JsonElement jsonElement = new JsonParser().parse(line);
|
||||
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
||||
mResponseHandler.handle(jsonObject);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.io.IOException;
|
||||
* Created by Stardust on 2017/5/11.
|
||||
*/
|
||||
|
||||
public class SublimePluginClientManager {
|
||||
public class SublimePluginService {
|
||||
|
||||
private static SublimePluginClient client;
|
||||
|
||||
@@ -10,7 +10,7 @@ import android.util.SparseArray;
|
||||
import com.jraska.console.Console;
|
||||
import com.stardust.autojs.runtime.api.AbstractConsole;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.sublime_plugin_client.SublimePluginClientManager;
|
||||
import com.stardust.scriptdroid.sublime_plugin_client.SublimePluginService;
|
||||
import com.stardust.util.SparseArrayEntries;
|
||||
import com.stardust.util.TextUtils;
|
||||
|
||||
@@ -49,14 +49,14 @@ public class JraskaConsole extends AbstractConsole {
|
||||
public void println(int level, CharSequence charSequence) {
|
||||
Console.write(getLevelSpannable(level, getTag(level)));
|
||||
Console.writeLine(getLevelSpannable(level, charSequence));
|
||||
SublimePluginClientManager.log(getTag(level) + charSequence.toString());
|
||||
SublimePluginService.log(getTag(level) + charSequence.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int level, CharSequence data) {
|
||||
Console.write(getLevelSpannable(level, getTag(level)));
|
||||
Console.write(getLevelSpannable(level, data));
|
||||
SublimePluginClientManager.log(getTag(level) + data.toString());
|
||||
SublimePluginService.log(getTag(level) + data.toString());
|
||||
}
|
||||
|
||||
private CharSequence getTag(int level) {
|
||||
|
||||
@@ -16,7 +16,6 @@ import android.support.v4.view.ViewPager;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
@@ -25,7 +24,6 @@ import android.widget.Toast;
|
||||
|
||||
import com.afollestad.materialdialogs.DialogAction;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.stardust.app.FragmentPagerAdapterBuilder;
|
||||
import com.stardust.app.NotAskAgainDialog;
|
||||
import com.stardust.app.OnActivityResultDelegate;
|
||||
@@ -38,8 +36,6 @@ import com.stardust.scriptdroid.script.ScriptFile;
|
||||
import com.stardust.scriptdroid.script.StorageScriptProvider;
|
||||
import com.stardust.scriptdroid.script.sample.Sample;
|
||||
import com.stardust.scriptdroid.service.AccessibilityWatchDogService;
|
||||
import com.stardust.scriptdroid.sublime_plugin_client.SublimePluginClient;
|
||||
import com.stardust.scriptdroid.sublime_plugin_client.SublimeResponseHandler;
|
||||
import com.stardust.scriptdroid.tool.AccessibilityServiceTool;
|
||||
import com.stardust.scriptdroid.tool.DrawableSaver;
|
||||
import com.stardust.scriptdroid.ui.BaseActivity;
|
||||
@@ -148,7 +144,7 @@ public class MainActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
private void setUpFragment() {
|
||||
SlideMenuFragment.setFragment(this, R.id.fragment_slide_menu);
|
||||
SideMenuFragment.setFragment(this, R.id.fragment_slide_menu);
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
|
||||
@@ -15,13 +15,14 @@ import android.widget.Toast;
|
||||
import com.afollestad.materialdialogs.DialogAction;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.stardust.app.Fragment;
|
||||
import com.stardust.scriptdroid.Pref;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import com.stardust.scriptdroid.external.floating_window.FloatingWindowManger;
|
||||
import com.stardust.scriptdroid.external.floating_window.menu.HoverMenuService;
|
||||
import com.stardust.scriptdroid.service.AccessibilityWatchDogService;
|
||||
import com.stardust.scriptdroid.sublime_plugin_client.SublimePluginClient;
|
||||
import com.stardust.scriptdroid.sublime_plugin_client.SublimePluginClientManager;
|
||||
import com.stardust.scriptdroid.sublime_plugin_client.SublimePluginService;
|
||||
import com.stardust.scriptdroid.tool.AccessibilityServiceTool;
|
||||
import com.stardust.scriptdroid.tool.WifiTool;
|
||||
import com.stardust.scriptdroid.ui.console.LogActivity;
|
||||
@@ -42,11 +43,11 @@ import java.util.concurrent.Executor;
|
||||
* Created by Stardust on 2017/1/30.
|
||||
*/
|
||||
|
||||
public class SlideMenuFragment extends Fragment {
|
||||
public class SideMenuFragment extends Fragment {
|
||||
|
||||
|
||||
public static void setFragment(FragmentActivity activity, int viewId) {
|
||||
SlideMenuFragment fragment = new SlideMenuFragment();
|
||||
SideMenuFragment fragment = new SideMenuFragment();
|
||||
activity.getSupportFragmentManager().beginTransaction().replace(viewId, fragment).commit();
|
||||
}
|
||||
|
||||
@@ -153,13 +154,14 @@ public class SlideMenuFragment extends Fragment {
|
||||
|
||||
@ViewBinding.Check(R.id.sw_debug)
|
||||
private void setDebugEnabled(boolean enabled) {
|
||||
if (enabled && !SublimePluginClientManager.isConnected()) {
|
||||
if (enabled && !SublimePluginService.isConnected()) {
|
||||
new MaterialDialog.Builder(getActivity())
|
||||
.title("服务器地址")
|
||||
.input("", WifiTool.getWifiAddress(getActivity()), new MaterialDialog.InputCallback() {
|
||||
.title(R.string.text_server_address)
|
||||
.input("", getServerAddress(), new MaterialDialog.InputCallback() {
|
||||
@Override
|
||||
public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
|
||||
SublimePluginClientManager.connect(input.toString());
|
||||
Pref.saveServerAddress(input.toString());
|
||||
SublimePluginService.connect(input.toString());
|
||||
}
|
||||
})
|
||||
.neutralText(R.string.text_help)
|
||||
@@ -171,10 +173,14 @@ public class SlideMenuFragment extends Fragment {
|
||||
})
|
||||
.show();
|
||||
} else if (!enabled) {
|
||||
SublimePluginClientManager.disconnectIfNeeded();
|
||||
SublimePluginService.disconnectIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
private CharSequence getServerAddress() {
|
||||
return Pref.getServerAddressOrDefault(WifiTool.getWifiAddress(getActivity()));
|
||||
}
|
||||
|
||||
@ViewBinding.Click(R.id.stop_all_running_scripts)
|
||||
private void stopAllRunningScripts() {
|
||||
int n = AutoJs.getInstance().getScriptEngineService().stopAll();
|
||||
Reference in New Issue
Block a user