fix: connection and log of SublimePluginClient
add: VSCode Extension support
This commit is contained in:
3
.idea/modules.xml
generated
3
.idea/modules.xml
generated
@@ -2,7 +2,8 @@
|
|||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectModuleManager">
|
<component name="ProjectModuleManager">
|
||||||
<modules>
|
<modules>
|
||||||
<module fileurl="file://$PROJECT_DIR$/NoRootScriptDroid.iml" filepath="$PROJECT_DIR$/NoRootScriptDroid.iml" />
|
<module fileurl="file://$PROJECT_DIR$/Auto.js.iml" filepath="$PROJECT_DIR$/Auto.js.iml" />
|
||||||
|
<module fileurl="file://C:\Users\Stardust\Documents\AndroidProjects\Auto.js\NoRootScriptDroid.iml" filepath="C:\Users\Stardust\Documents\AndroidProjects\Auto.js\NoRootScriptDroid.iml" />
|
||||||
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
|
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
|
||||||
<module fileurl="file://$PROJECT_DIR$/autojs/autojs.iml" filepath="$PROJECT_DIR$/autojs/autojs.iml" />
|
<module fileurl="file://$PROJECT_DIR$/autojs/autojs.iml" filepath="$PROJECT_DIR$/autojs/autojs.iml" />
|
||||||
<module fileurl="file://$PROJECT_DIR$/automator/automator.iml" filepath="$PROJECT_DIR$/automator/automator.iml" />
|
<module fileurl="file://$PROJECT_DIR$/automator/automator.iml" filepath="$PROJECT_DIR$/automator/automator.iml" />
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ android {
|
|||||||
applicationId "com.stardust.scriptdroid"
|
applicationId "com.stardust.scriptdroid"
|
||||||
minSdkVersion 17
|
minSdkVersion 17
|
||||||
targetSdkVersion 23
|
targetSdkVersion 23
|
||||||
versionCode 215
|
versionCode 217
|
||||||
versionName "3.0.0 Alpha16"
|
versionName "3.0.0 Alpha17"
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
multiDexEnabled true
|
multiDexEnabled true
|
||||||
ndk {
|
ndk {
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import com.stardust.scriptdroid.R;
|
|||||||
import com.stardust.autojs.core.image.ScreenCaptureRequestActivity;
|
import com.stardust.autojs.core.image.ScreenCaptureRequestActivity;
|
||||||
import com.stardust.autojs.core.util.Shell;
|
import com.stardust.autojs.core.util.Shell;
|
||||||
import com.stardust.autojs.core.console.StardustConsole;
|
import com.stardust.autojs.core.console.StardustConsole;
|
||||||
|
import com.stardust.scriptdroid.sublime.SublimePluginService;
|
||||||
import com.stardust.util.ScreenMetrics;
|
import com.stardust.util.ScreenMetrics;
|
||||||
import com.stardust.util.Supplier;
|
import com.stardust.util.Supplier;
|
||||||
import com.stardust.util.UiHandler;
|
import com.stardust.util.UiHandler;
|
||||||
@@ -76,7 +77,14 @@ public class AutoJs {
|
|||||||
mContext = context;
|
mContext = context;
|
||||||
mUiHandler = new UiHandler(context);
|
mUiHandler = new UiHandler(context);
|
||||||
mAppUtils = new AppUtils(context);
|
mAppUtils = new AppUtils(context);
|
||||||
mGlobalConsole = new GlobalStardustConsole(mUiHandler);
|
mGlobalConsole = new GlobalStardustConsole(mUiHandler){
|
||||||
|
@Override
|
||||||
|
public String println(int level, CharSequence charSequence) {
|
||||||
|
String log = super.println(level, charSequence);
|
||||||
|
SublimePluginService.log(log);
|
||||||
|
return log;
|
||||||
|
}
|
||||||
|
};
|
||||||
mNotificationObserver = new NotificationListener.Observer(context);
|
mNotificationObserver = new NotificationListener.Observer(context);
|
||||||
mAccessibilityInfoProvider = new AccessibilityInfoProvider(context.getPackageManager());
|
mAccessibilityInfoProvider = new AccessibilityInfoProvider(context.getPackageManager());
|
||||||
mScriptEngineService = buildScriptEngineService();
|
mScriptEngineService = buildScriptEngineService();
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
package com.stardust.scriptdroid.sublime;
|
package com.stardust.scriptdroid.sublime;
|
||||||
|
|
||||||
import android.graphics.BitmapFactory;
|
import android.os.Build;
|
||||||
|
|
||||||
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.enhancedfloaty.FloatyWindow;
|
|
||||||
import com.stardust.enhancedfloaty.ResizableFloaty;
|
|
||||||
|
|
||||||
import org.greenrobot.eventbus.EventBus;
|
|
||||||
import org.reactivestreams.Publisher;
|
import org.reactivestreams.Publisher;
|
||||||
import org.reactivestreams.Subscriber;
|
import org.reactivestreams.Subscriber;
|
||||||
|
|
||||||
@@ -72,15 +69,29 @@ public class SublimePluginClient {
|
|||||||
mSocket.setTcpNoDelay(true);
|
mSocket.setTcpNoDelay(true);
|
||||||
mOutputStream = mSocket.getOutputStream();
|
mOutputStream = mSocket.getOutputStream();
|
||||||
s.onComplete();
|
s.onComplete();
|
||||||
readLoop(mSocket.getInputStream());
|
sendDeviceName();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
s.onError(e);
|
s.onError(e);
|
||||||
} finally {
|
tryClose();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
readLoop(mSocket.getInputStream());
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}finally {
|
||||||
tryClose();
|
tryClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendDeviceName() {
|
||||||
|
JsonObject object = new JsonObject();
|
||||||
|
object.addProperty("type", "device_name");
|
||||||
|
object.addProperty("device_name", Build.MODEL);
|
||||||
|
send(object).subscribe();
|
||||||
|
}
|
||||||
|
|
||||||
public PublishSubject<Boolean> getConnectionState() {
|
public PublishSubject<Boolean> getConnectionState() {
|
||||||
return mConnectionState;
|
return mConnectionState;
|
||||||
}
|
}
|
||||||
@@ -97,18 +108,15 @@ public class SublimePluginClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Observable<Void> send(final JsonObject object) {
|
public Observable<JsonObject> send(final JsonObject object) {
|
||||||
if (mSocket == null) {
|
if (mSocket == null) {
|
||||||
throw new IllegalStateException("Socket is not listening ");
|
throw new IllegalStateException("Socket is not listening ");
|
||||||
}
|
}
|
||||||
return Observable.fromCallable(new Callable<Void>() {
|
return Observable.fromCallable(() -> {
|
||||||
@Override
|
mOutputStream.write(object.toString().getBytes());
|
||||||
public Void call() throws Exception {
|
mOutputStream.write("\n".getBytes());
|
||||||
mOutputStream.write(object.toString().getBytes());
|
mOutputStream.flush();
|
||||||
mOutputStream.write("\n".getBytes());
|
return object;
|
||||||
mOutputStream.flush();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package com.stardust.scriptdroid.sublime;
|
|||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
|
import io.reactivex.Scheduler;
|
||||||
|
import io.reactivex.schedulers.Schedulers;
|
||||||
import io.reactivex.subjects.PublishSubject;
|
import io.reactivex.subjects.PublishSubject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,11 +52,9 @@ public class SublimePluginService {
|
|||||||
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);
|
.subscribeOn(Schedulers.io())
|
||||||
} catch (Exception e) {
|
.subscribe(ignored -> {
|
||||||
e.printStackTrace();
|
}, Throwable::printStackTrace);
|
||||||
disconnect();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import com.stardust.scriptdroid.autojs.AutoJs;
|
|||||||
import com.stardust.scriptdroid.model.script.Scripts;
|
import com.stardust.scriptdroid.model.script.Scripts;
|
||||||
import com.stardust.scriptdroid.io.StorageFileProvider;
|
import com.stardust.scriptdroid.io.StorageFileProvider;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Stardust on 2017/5/11.
|
* Created by Stardust on 2017/5/11.
|
||||||
*/
|
*/
|
||||||
@@ -29,7 +31,7 @@ public class SublimeResponseHandler implements Handler {
|
|||||||
public boolean handle(JsonObject data) {
|
public boolean handle(JsonObject data) {
|
||||||
String script = data.get("script").getAsString();
|
String script = data.get("script").getAsString();
|
||||||
String name = getName(data);
|
String name = getName(data);
|
||||||
int viewId = data.get("view_id").getAsInt();
|
String viewId = data.get("view_id").getAsString();
|
||||||
runScript(viewId, name, script);
|
runScript(viewId, name, script);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -37,7 +39,7 @@ public class SublimeResponseHandler implements Handler {
|
|||||||
.handler("stop", new Handler() {
|
.handler("stop", new Handler() {
|
||||||
@Override
|
@Override
|
||||||
public boolean handle(JsonObject data) {
|
public boolean handle(JsonObject data) {
|
||||||
int viewId = data.get("view_id").getAsInt();
|
String viewId = data.get("view_id").getAsString();
|
||||||
stopScript(viewId);
|
stopScript(viewId);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -55,7 +57,7 @@ public class SublimeResponseHandler implements Handler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handle(JsonObject data) {
|
public boolean handle(JsonObject data) {
|
||||||
int viewId = data.get("view_id").getAsInt();
|
String viewId = data.get("view_id").getAsString();
|
||||||
String script = data.get("script").getAsString();
|
String script = data.get("script").getAsString();
|
||||||
String name = getName(data);
|
String name = getName(data);
|
||||||
stopScript(viewId);
|
stopScript(viewId);
|
||||||
@@ -72,14 +74,14 @@ public class SublimeResponseHandler implements Handler {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
private SparseArray<ScriptExecution> mScriptExecutions = new SparseArray<>();
|
private HashMap<String, ScriptExecution> mScriptExecutions = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handle(JsonObject data) {
|
public boolean handle(JsonObject data) {
|
||||||
return mRouter.handle(data);
|
return mRouter.handle(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runScript(int viewId, String name, String script) {
|
private void runScript(String viewId, String name, String script) {
|
||||||
if (TextUtils.isEmpty(name)) {
|
if (TextUtils.isEmpty(name)) {
|
||||||
name = "[" + viewId + "]";
|
name = "[" + viewId + "]";
|
||||||
} else {
|
} else {
|
||||||
@@ -88,11 +90,11 @@ public class SublimeResponseHandler implements Handler {
|
|||||||
mScriptExecutions.put(viewId, Scripts.run(new StringScriptSource("<remote>:" + name, script)));
|
mScriptExecutions.put(viewId, Scripts.run(new StringScriptSource("<remote>:" + name, script)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopScript(int viewId) {
|
private void stopScript(String viewId) {
|
||||||
ScriptExecution execution = mScriptExecutions.get(viewId);
|
ScriptExecution execution = mScriptExecutions.get(viewId);
|
||||||
if (execution != null) {
|
if (execution != null) {
|
||||||
execution.getEngine().forceStop();
|
execution.getEngine().forceStop();
|
||||||
mScriptExecutions.delete(viewId);
|
mScriptExecutions.remove(viewId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.stardust.scriptdroid.tool;
|
package com.stardust.scriptdroid.tool;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.net.DhcpInfo;
|
||||||
import android.net.wifi.WifiInfo;
|
import android.net.wifi.WifiInfo;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.text.format.Formatter;
|
import android.text.format.Formatter;
|
||||||
@@ -17,8 +18,20 @@ public class WifiTool {
|
|||||||
|
|
||||||
public static String getWifiAddress(Context context) {
|
public static String getWifiAddress(Context context) {
|
||||||
WifiManager wifiMgr = (WifiManager) context.getApplicationContext().getSystemService(WIFI_SERVICE);
|
WifiManager wifiMgr = (WifiManager) context.getApplicationContext().getSystemService(WIFI_SERVICE);
|
||||||
|
if(wifiMgr == null){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
|
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
|
||||||
int ip = wifiInfo.getIpAddress();
|
int ip = wifiInfo.getIpAddress();
|
||||||
return Formatter.formatIpAddress(ip);
|
return Formatter.formatIpAddress(ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getRouterIp(Context context){
|
||||||
|
WifiManager wifiService = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
||||||
|
if(wifiService == null){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
DhcpInfo dhcpInfo = wifiService.getDhcpInfo();
|
||||||
|
return Formatter.formatIpAddress(dhcpInfo.gateway);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ import org.androidannotations.annotations.EActivity;
|
|||||||
import org.androidannotations.annotations.ViewById;
|
import org.androidannotations.annotations.ViewById;
|
||||||
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.EventBus;
|
||||||
|
|
||||||
|
import java.net.Socket;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@EActivity(R.layout.activity_main)
|
@EActivity(R.layout.activity_main)
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ public class DrawerFragment extends android.support.v4.app.Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void inputRemoteHost() {
|
private void inputRemoteHost() {
|
||||||
String host = Pref.getServerAddressOrDefault(WifiTool.getWifiAddress(getActivity()));
|
String host = Pref.getServerAddressOrDefault(WifiTool.getRouterIp(getActivity()));
|
||||||
new MaterialDialog.Builder(getActivity())
|
new MaterialDialog.Builder(getActivity())
|
||||||
.title(R.string.text_server_address)
|
.title(R.string.text_server_address)
|
||||||
.input("", host, (dialog, input) -> {
|
.input("", host, (dialog, input) -> {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:foreground="?selectableItemBackground"
|
android:foreground="?selectableItemBackground"
|
||||||
app:cardBackgroundColor="#ffffff"
|
app:cardBackgroundColor="#ffffff"
|
||||||
app:cardElevation="0.5dp"
|
app:cardElevation="0.618dp"
|
||||||
app:cardUseCompatPadding="true">
|
app:cardUseCompatPadding="true">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
|||||||
@@ -30,10 +30,11 @@ public class GlobalStardustConsole extends StardustConsole {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void println(int level, CharSequence charSequence) {
|
public String println(int level, CharSequence charSequence) {
|
||||||
charSequence = String.format(Locale.getDefault(), "%s/%s: %s",
|
String log = String.format(Locale.getDefault(), "%s/%s: %s",
|
||||||
DATE_FORMAT.format(new Date()), getLevelChar(level), charSequence.toString());
|
DATE_FORMAT.format(new Date()), getLevelChar(level), charSequence.toString());
|
||||||
super.println(level, charSequence);
|
super.println(level, log);
|
||||||
|
return log;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getLevelChar(int level) {
|
private String getLevelChar(int level) {
|
||||||
|
|||||||
@@ -60,8 +60,9 @@ public class NoOpConsole implements Console {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void println(int level, CharSequence charSequence) {
|
public String println(int level, CharSequence charSequence) {
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ public class StardustConsole extends AbstractConsole {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void println(int level, CharSequence charSequence) {
|
public String println(int level, CharSequence charSequence) {
|
||||||
Log log = new Log(mIdCounter.getAndIncrement(), level, charSequence, true);
|
Log log = new Log(mIdCounter.getAndIncrement(), level, charSequence, true);
|
||||||
mLogs.add(log);
|
mLogs.add(log);
|
||||||
if (mGlobalConsole != null) {
|
if (mGlobalConsole != null) {
|
||||||
@@ -115,6 +115,7 @@ public class StardustConsole extends AbstractConsole {
|
|||||||
if (mLogListener != null && mLogListener.get() != null) {
|
if (mLogListener != null && mLogListener.get() != null) {
|
||||||
mLogListener.get().onNewLog(log);
|
mLogListener.get().onNewLog(log);
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public interface Console {
|
|||||||
@ScriptInterface
|
@ScriptInterface
|
||||||
void hide();
|
void hide();
|
||||||
|
|
||||||
void println(int level, CharSequence charSequence);
|
String println(int level, CharSequence charSequence);
|
||||||
|
|
||||||
void setTitle(CharSequence title);
|
void setTitle(CharSequence title);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package com.stardust;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.net.Socket;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -12,6 +14,6 @@ import static org.junit.Assert.*;
|
|||||||
public class ExampleUnitTest {
|
public class ExampleUnitTest {
|
||||||
@Test
|
@Test
|
||||||
public void addition_isCorrect() throws Exception {
|
public void addition_isCorrect() throws Exception {
|
||||||
assertEquals(4, 2 + 2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user