From 429407ed2d3930b7eca19d67c026ac2d4af5dad1 Mon Sep 17 00:00:00 2001 From: hyb1996 <946994919@qq.com> Date: Mon, 15 Oct 2018 00:08:53 +0800 Subject: [PATCH] fix: floaty --- autojs/src/main/assets/modules/__floaty__.js | 8 +++---- .../stardust/autojs/ScriptEngineService.java | 15 +++++++++++- .../core/ui/attribute/TextViewAttributes.java | 1 - .../core/ui/nativeview/ViewPrototype.java | 23 ++++++++++++++++--- .../stardust/autojs/runtime/api/Images.java | 1 + common/release/output.json | 2 +- project-versions.json | 4 ++-- 7 files changed, 42 insertions(+), 12 deletions(-) diff --git a/autojs/src/main/assets/modules/__floaty__.js b/autojs/src/main/assets/modules/__floaty__.js index c15a52b7..fcbf56d6 100644 --- a/autojs/src/main/assets/modules/__floaty__.js +++ b/autojs/src/main/assets/modules/__floaty__.js @@ -2,23 +2,23 @@ module.exports = function(runtime, global){ var floaty = {}; - floaty.window = function(layout){ + floaty.window = function(xml){ if(typeof(xml) == 'xml'){ xml = xml.toXMLString(); } return wrap(runtime.floaty.window(function(context, parent){ runtime.ui.layoutInflater.setContext(context); - return ui.__inflate__(runtime.ui.layoutInflater.inflate(xml.toString(), parent, true)); + return runtime.ui.layoutInflater.inflate(xml.toString(), parent, true); })); } - floaty.rawWindow = function(layout){ + floaty.rawWindow = function(xml){ if(typeof(xml) == 'xml'){ xml = xml.toXMLString(); } return wrap(runtime.floaty.rawWindow(function(context, parent){ runtime.ui.layoutInflater.setContext(context); - return ui.__inflate__(runtime.ui.layoutInflater.inflate(xml.toString(), parent, true)); + return runtime.ui.layoutInflater.inflate(xml.toString(), parent, true); })); } diff --git a/autojs/src/main/java/com/stardust/autojs/ScriptEngineService.java b/autojs/src/main/java/com/stardust/autojs/ScriptEngineService.java index 5ece07b1..ddba7aaf 100644 --- a/autojs/src/main/java/com/stardust/autojs/ScriptEngineService.java +++ b/autojs/src/main/java/com/stardust/autojs/ScriptEngineService.java @@ -70,14 +70,27 @@ public class ScriptEngineService { public void onException(ScriptExecution execution, Exception e) { e.printStackTrace(); onFinish(execution); + String message = null; if (!causedByInterrupted(e)) { + message = e.getMessage(); if (execution.getEngine() instanceof JavaScriptEngine) { ((JavaScriptEngine) execution.getEngine()).getRuntime() .console.error(e); } - EVENT_BUS.post(new ScriptExecutionEvent(ScriptExecutionEvent.ON_EXCEPTION, e.getMessage())); + } + if (execution.getEngine() instanceof JavaScriptEngine) { + JavaScriptEngine engine = (JavaScriptEngine) execution.getEngine(); + Exception uncaughtException = engine.getUncaughtException(); + if (uncaughtException != null) { + engine.getRuntime().console.error(uncaughtException); + message = uncaughtException.getMessage(); + } + } + if (message != null) { + EVENT_BUS.post(new ScriptExecutionEvent(ScriptExecutionEvent.ON_EXCEPTION, message)); } } + }; diff --git a/autojs/src/main/java/com/stardust/autojs/core/ui/attribute/TextViewAttributes.java b/autojs/src/main/java/com/stardust/autojs/core/ui/attribute/TextViewAttributes.java index b4e0ce1c..91768efc 100644 --- a/autojs/src/main/java/com/stardust/autojs/core/ui/attribute/TextViewAttributes.java +++ b/autojs/src/main/java/com/stardust/autojs/core/ui/attribute/TextViewAttributes.java @@ -14,7 +14,6 @@ public class TextViewAttributes extends ViewAttributes { @Override protected void onRegisterAttrs() { super.onRegisterAttrs(); - } @Override diff --git a/autojs/src/main/java/com/stardust/autojs/core/ui/nativeview/ViewPrototype.java b/autojs/src/main/java/com/stardust/autojs/core/ui/nativeview/ViewPrototype.java index e4007e61..a8e3ff4f 100644 --- a/autojs/src/main/java/com/stardust/autojs/core/ui/nativeview/ViewPrototype.java +++ b/autojs/src/main/java/com/stardust/autojs/core/ui/nativeview/ViewPrototype.java @@ -2,6 +2,8 @@ package com.stardust.autojs.core.ui.nativeview; import android.annotation.SuppressLint; import android.os.Build; +import android.os.Looper; +import android.support.v4.view.ViewCompat; import android.view.View; import android.widget.CompoundButton; @@ -14,13 +16,16 @@ import com.stardust.autojs.runtime.ScriptRuntime; import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.Undefined; +import java.util.Collections; import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; public class ViewPrototype { private final EventEmitter mEventEmitter; private final View mView; - private final HashSet mRegisteredEvents = new HashSet<>(); + private final Set mRegisteredEvents = Collections.newSetFromMap(new ConcurrentHashMap<>()); private final Scriptable mScope; private final ViewAttributes mViewAttributes; private Object mWidget; @@ -94,9 +99,21 @@ public class ViewPrototype { if (mRegisteredEvents.contains(eventName)) { return; } - if (registerEvent(eventName)) { - mRegisteredEvents.add(eventName); + if (Looper.getMainLooper() == Looper.myLooper()) { + if (registerEvent(eventName)) { + mRegisteredEvents.add(eventName); + } + } else { + mView.post(() -> { + if (mRegisteredEvents.contains(eventName)) { + return; + } + if (registerEvent(eventName)) { + mRegisteredEvents.add(eventName); + } + }); } + } @SuppressLint("ClickableViewAccessibility") diff --git a/autojs/src/main/java/com/stardust/autojs/runtime/api/Images.java b/autojs/src/main/java/com/stardust/autojs/runtime/api/Images.java index 90bb1fe1..c97e7318 100644 --- a/autojs/src/main/java/com/stardust/autojs/runtime/api/Images.java +++ b/autojs/src/main/java/com/stardust/autojs/runtime/api/Images.java @@ -14,6 +14,7 @@ import android.util.Base64; import android.view.Display; import android.view.Surface; import android.view.WindowManager; +import android.widget.ListView; import com.stardust.autojs.annotation.ScriptVariable; import com.stardust.autojs.core.image.ColorFinder; diff --git a/common/release/output.json b/common/release/output.json index 09010d13..558cdd3f 100644 --- a/common/release/output.json +++ b/common/release/output.json @@ -1 +1 @@ -[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":426,"versionName":"4.0.3 Alpha7","enabled":true,"outputFile":"commonRelease-4.0.3 Alpha7.apk","fullName":"commonRelease","baseName":"common-release"},"path":"commonRelease-4.0.3 Alpha7.apk","properties":{}}] \ No newline at end of file +[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":430,"versionName":"4.0.4 Alpha","enabled":true,"outputFile":"commonRelease-4.0.4 Alpha.apk","fullName":"commonRelease","baseName":"common-release"},"path":"commonRelease-4.0.4 Alpha.apk","properties":{}}] \ No newline at end of file diff --git a/project-versions.json b/project-versions.json index 39a00902..25349cea 100644 --- a/project-versions.json +++ b/project-versions.json @@ -1,6 +1,6 @@ { - "appVersionCode": 426, - "appVersionName": "4.0.3 Alpha7", + "appVersionCode": 430, + "appVersionName": "4.0.4 Alpha", "target": 28, "mini": 17, "compile": 28,