fix crash when remote file name is untitle
This commit is contained in:
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -47,7 +47,7 @@
|
|||||||
<ConfirmationsSetting value="0" id="Add" />
|
<ConfirmationsSetting value="0" id="Add" />
|
||||||
<ConfirmationsSetting value="0" id="Remove" />
|
<ConfirmationsSetting value="0" id="Remove" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ android {
|
|||||||
applicationId "com.stardust.scriptdroid"
|
applicationId "com.stardust.scriptdroid"
|
||||||
minSdkVersion 19
|
minSdkVersion 19
|
||||||
targetSdkVersion 23
|
targetSdkVersion 23
|
||||||
versionCode 128
|
versionCode 129
|
||||||
versionName "2.0.10c Beta"
|
versionName "2.0.10c Beta"
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
multiDexEnabled true
|
multiDexEnabled true
|
||||||
|
|||||||
@@ -1,14 +1,20 @@
|
|||||||
package com.stardust.scriptdroid.sublime_plugin_client;
|
package com.stardust.scriptdroid.sublime_plugin_client;
|
||||||
|
|
||||||
|
import android.os.Looper;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import com.stardust.util.UiHandler;
|
import com.stardust.util.UiHandler;
|
||||||
|
|
||||||
|
import org.greenrobot.eventbus.EventBus;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Stardust on 2017/5/10.
|
* Created by Stardust on 2017/5/10.
|
||||||
@@ -16,18 +22,29 @@ import java.net.Socket;
|
|||||||
|
|
||||||
public class SublimePluginClient {
|
public class SublimePluginClient {
|
||||||
|
|
||||||
|
public static class ConnectionStateChangeEvent {
|
||||||
|
|
||||||
|
private boolean mConnected;
|
||||||
|
|
||||||
|
public ConnectionStateChangeEvent(boolean connected) {
|
||||||
|
mConnected = connected;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isConnected() {
|
||||||
|
return mConnected;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Socket mSocket;
|
private Socket mSocket;
|
||||||
private Handler mResponseHandler;
|
private Handler mResponseHandler;
|
||||||
private String host;
|
private String host;
|
||||||
private int port;
|
private int port;
|
||||||
private OutputStream mOutputStream;
|
private OutputStream mOutputStream;
|
||||||
private UiHandler mUiHandler;
|
private Executor mExecutor;
|
||||||
|
|
||||||
public SublimePluginClient(UiHandler handler, String host, int port) {
|
public SublimePluginClient(String host, int port) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
mUiHandler = handler;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setResponseHandler(Handler handler) {
|
public void setResponseHandler(Handler handler) {
|
||||||
@@ -43,8 +60,8 @@ public class SublimePluginClient {
|
|||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
mSocket = new Socket(host, port);
|
mSocket = new Socket(host, port);
|
||||||
|
EventBus.getDefault().post(new ConnectionStateChangeEvent(true));
|
||||||
mSocket.setTcpNoDelay(true);
|
mSocket.setTcpNoDelay(true);
|
||||||
mUiHandler.toast("Connected");
|
|
||||||
mOutputStream = mSocket.getOutputStream();
|
mOutputStream = mSocket.getOutputStream();
|
||||||
startReadLoop(mSocket.getInputStream());
|
startReadLoop(mSocket.getInputStream());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -64,13 +81,30 @@ public class SublimePluginClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(JsonObject object) throws IOException {
|
public void send(final JsonObject object) {
|
||||||
if (mSocket == null) {
|
if (mSocket == null) {
|
||||||
throw new IllegalStateException("Socket is not listening ");
|
throw new IllegalStateException("Socket is not listening ");
|
||||||
}
|
}
|
||||||
|
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||||
|
if (mExecutor == null) {
|
||||||
|
mExecutor = Executors.newSingleThreadExecutor();
|
||||||
|
}
|
||||||
|
mExecutor.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
send(object);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
try {
|
||||||
mOutputStream.write(object.toString().getBytes());
|
mOutputStream.write(object.toString().getBytes());
|
||||||
mOutputStream.write("\n".getBytes());
|
mOutputStream.write("\n".getBytes());
|
||||||
mOutputStream.flush();
|
mOutputStream.flush();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
tryClose();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
@@ -78,7 +112,7 @@ public class SublimePluginClient {
|
|||||||
mSocket.close();
|
mSocket.close();
|
||||||
mSocket = null;
|
mSocket = null;
|
||||||
mOutputStream = null;
|
mOutputStream = null;
|
||||||
mUiHandler.toast("Disconnected");
|
EventBus.getDefault().post(new ConnectionStateChangeEvent(false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public class SublimePluginClientManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void connect(String host) {
|
public static void connect(String host) {
|
||||||
client = new SublimePluginClient(AutoJs.getInstance().getUiHandler(), host, 1209);
|
client = new SublimePluginClient(host, 1209);
|
||||||
client.setResponseHandler(new SublimeResponseHandler());
|
client.setResponseHandler(new SublimeResponseHandler());
|
||||||
client.listen();
|
client.listen();
|
||||||
}
|
}
|
||||||
@@ -45,10 +45,6 @@ public class SublimePluginClientManager {
|
|||||||
JsonObject object = new JsonObject();
|
JsonObject object = new JsonObject();
|
||||||
object.addProperty("type", "log");
|
object.addProperty("type", "log");
|
||||||
object.addProperty("log", log);
|
object.addProperty("log", log);
|
||||||
try {
|
|
||||||
client.send(object);
|
client.send(object);
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package com.stardust.scriptdroid.sublime_plugin_client;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonNull;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.stardust.autojs.engine.ScriptEngine;
|
import com.stardust.autojs.engine.ScriptEngine;
|
||||||
import com.stardust.autojs.execution.ScriptExecution;
|
import com.stardust.autojs.execution.ScriptExecution;
|
||||||
@@ -24,7 +26,7 @@ public class SublimeResponseHandler implements Handler {
|
|||||||
@Override
|
@Override
|
||||||
public boolean handle(JsonObject data) {
|
public boolean handle(JsonObject data) {
|
||||||
String script = data.get("script").getAsString();
|
String script = data.get("script").getAsString();
|
||||||
String name = data.get("name").getAsString();
|
String name = getName(data);
|
||||||
int viewId = data.get("view_id").getAsInt();
|
int viewId = data.get("view_id").getAsInt();
|
||||||
runScript(viewId, name, script);
|
runScript(viewId, name, script);
|
||||||
return false;
|
return false;
|
||||||
@@ -44,7 +46,7 @@ public class SublimeResponseHandler implements Handler {
|
|||||||
public boolean handle(JsonObject data) {
|
public boolean handle(JsonObject data) {
|
||||||
int viewId = data.get("view_id").getAsInt();
|
int viewId = data.get("view_id").getAsInt();
|
||||||
String script = data.get("script").getAsString();
|
String script = data.get("script").getAsString();
|
||||||
String name = data.get("name").getAsString();
|
String name = getName(data);
|
||||||
stopScript(viewId);
|
stopScript(viewId);
|
||||||
runScript(viewId, name, script);
|
runScript(viewId, name, script);
|
||||||
return false;
|
return false;
|
||||||
@@ -82,4 +84,12 @@ public class SublimeResponseHandler implements Handler {
|
|||||||
mScriptExecutions.delete(viewId);
|
mScriptExecutions.delete(viewId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getName(JsonObject data) {
|
||||||
|
JsonElement element = data.get("name");
|
||||||
|
if (element instanceof JsonNull) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return element.getAsString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ import android.support.v7.widget.SwitchCompat;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.afollestad.materialdialogs.DialogAction;
|
||||||
import com.afollestad.materialdialogs.MaterialDialog;
|
import com.afollestad.materialdialogs.MaterialDialog;
|
||||||
import com.stardust.app.Fragment;
|
import com.stardust.app.Fragment;
|
||||||
import com.stardust.scriptdroid.R;
|
import com.stardust.scriptdroid.R;
|
||||||
@@ -18,17 +20,20 @@ import com.stardust.scriptdroid.autojs.AutoJs;
|
|||||||
import com.stardust.scriptdroid.external.floating_window.FloatingWindowManger;
|
import com.stardust.scriptdroid.external.floating_window.FloatingWindowManger;
|
||||||
import com.stardust.scriptdroid.external.floating_window.menu.HoverMenuService;
|
import com.stardust.scriptdroid.external.floating_window.menu.HoverMenuService;
|
||||||
import com.stardust.scriptdroid.service.AccessibilityWatchDogService;
|
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.SublimePluginClientManager;
|
||||||
import com.stardust.scriptdroid.tool.AccessibilityServiceTool;
|
import com.stardust.scriptdroid.tool.AccessibilityServiceTool;
|
||||||
import com.stardust.scriptdroid.tool.WifiTool;
|
import com.stardust.scriptdroid.tool.WifiTool;
|
||||||
import com.stardust.scriptdroid.ui.console.LogActivity;
|
import com.stardust.scriptdroid.ui.console.LogActivity;
|
||||||
import com.stardust.scriptdroid.ui.help.HelpCatalogueActivity;
|
import com.stardust.scriptdroid.ui.help.HelpCatalogueActivity;
|
||||||
|
import com.stardust.util.IntentUtil;
|
||||||
import com.stardust.util.UnderuseExecutors;
|
import com.stardust.util.UnderuseExecutors;
|
||||||
import com.stardust.view.ViewBinder;
|
import com.stardust.view.ViewBinder;
|
||||||
import com.stardust.view.ViewBinding;
|
import com.stardust.view.ViewBinding;
|
||||||
|
|
||||||
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.EventBus;
|
||||||
import org.greenrobot.eventbus.Subscribe;
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
|
import org.greenrobot.eventbus.ThreadMode;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
@@ -157,6 +162,13 @@ public class SlideMenuFragment extends Fragment {
|
|||||||
SublimePluginClientManager.connect(input.toString());
|
SublimePluginClientManager.connect(input.toString());
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.neutralText(R.string.text_help)
|
||||||
|
.onNeutral(new MaterialDialog.SingleButtonCallback() {
|
||||||
|
@Override
|
||||||
|
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
|
||||||
|
IntentUtil.browse(getActivity(), "https://github.com/hyb1996/AutoJs-Sublime-Plugin/blob/master/Readme.md");
|
||||||
|
}
|
||||||
|
})
|
||||||
.show();
|
.show();
|
||||||
} else if (!enabled) {
|
} else if (!enabled) {
|
||||||
SublimePluginClientManager.disconnectIfNeeded();
|
SublimePluginClientManager.disconnectIfNeeded();
|
||||||
@@ -183,4 +195,10 @@ public class SlideMenuFragment extends Fragment {
|
|||||||
mFloatingWindowSwitch.setChecked(event.state);
|
mFloatingWindowSwitch.setChecked(event.state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
|
public void onSublimeClientStateChange(SublimePluginClient.ConnectionStateChangeEvent event) {
|
||||||
|
mDebugSwith.setChecked(event.isConnected());
|
||||||
|
Toast.makeText(getActivity(), event.isConnected() ? R.string.text_connected : R.string.text_disconnected, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.1 KiB |
BIN
app/src/main/res/drawable/ic_debug.png
Normal file
BIN
app/src/main/res/drawable/ic_debug.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
@@ -178,7 +178,9 @@
|
|||||||
<string name="text_again_and_again">又双</string>
|
<string name="text_again_and_again">又双</string>
|
||||||
<string name="text_again_and_again_again">又双叒</string>
|
<string name="text_again_and_again_again">又双叒</string>
|
||||||
<string name="text_again_and_again_again_again">又双叒叕</string>
|
<string name="text_again_and_again_again_again">又双叒叕</string>
|
||||||
<string name="debug">连接调试服务器</string>
|
<string name="debug">连接电脑</string>
|
||||||
|
<string name="text_connected">已连接</string>
|
||||||
|
<string name="text_disconnected">已断开连接</string>
|
||||||
|
|
||||||
<string-array name="record_control_keys">
|
<string-array name="record_control_keys">
|
||||||
<item>无</item>
|
<item>无</item>
|
||||||
|
|||||||
10
version.json
10
version.json
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"versionCode": 119,
|
"versionCode": 127,
|
||||||
"versionName": "2.0.8 Beta",
|
"versionName": "2.0.10b Beta",
|
||||||
"releaseNotes": "* 新增 文本文件读写(参见示例)\n* 新增 代码格式化(自动缩进,排版,不支持中文)\n* 新增 真正支持作为Tasker插件使用(Tasker新建任务选择插件)\n* 新增 支持加载jar文件和模块化开发(require)\n* 新增 对文件夹的支持\n* 新增 免Root模拟返回键、Home键、电源键等(参见帮助菜单->自动操作函数)\n* 新增 任务管理\n* 优化 自动操作函数的运行方式,提高执行速度\n* 修复 某些情况下脚本运行无反应的问题\n* 修复 部分自动操作函数失效的问题\n* 修复 某些情况下关闭脚本无效的问题\n* 修复 布局范围查看点击后显示错误控件的问题",
|
"releaseNotes": "* 新增 一些脚本\n* 新增 多种对话框(参见示例 对话框)\n* 新增 悬浮窗控制台(参见示例 控制台)\n* 优化 内存占用\n* 修复 一些Bug",
|
||||||
"downloads" : [
|
"downloads" : [
|
||||||
{
|
{
|
||||||
"name": "酷安",
|
"name": "酷安",
|
||||||
@@ -10,6 +10,10 @@
|
|||||||
{
|
{
|
||||||
"name": "应用宝",
|
"name": "应用宝",
|
||||||
"url": "http://a.app.qq.com/o/simple.jsp?pkgname=com.stardust.scriptdroid"
|
"url": "http://a.app.qq.com/o/simple.jsp?pkgname=com.stardust.scriptdroid"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "百度手机助手",
|
||||||
|
"url": "https://mobile.baidu.com/item?docid=11462633"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"oldVersions": [
|
"oldVersions": [
|
||||||
|
|||||||
Reference in New Issue
Block a user