修复某些情况下timer工作不正常
This commit is contained in:
@@ -7,6 +7,7 @@ import org.autojs.autojs.runtime.ScriptRuntime
|
||||
import org.mozilla.javascript.BaseFunction
|
||||
import org.mozilla.javascript.Context
|
||||
import org.mozilla.javascript.Scriptable
|
||||
import org.mozilla.javascript.Undefined
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import kotlin.random.Random
|
||||
|
||||
@@ -22,6 +23,7 @@ class Timer(
|
||||
private val mRuntime: ScriptRuntime = runtime
|
||||
private val mHandler: Handler = Handler(looper)
|
||||
private val isUiLoop: Boolean = looper == Looper.getMainLooper()
|
||||
private val context: Context? by lazy { Context.getCurrentContext() }
|
||||
|
||||
constructor(runtime: ScriptRuntime, ) : this(runtime, Looper.myLooper()!!)
|
||||
|
||||
@@ -36,17 +38,22 @@ class Timer(
|
||||
return id
|
||||
}
|
||||
|
||||
private fun callFunction(callback: Any, thiz: Any?, args :Any?) {
|
||||
val myArgs = args?.let { args as Array<*> }?: emptyArray<Any>()
|
||||
val map = myArgs.map { Context.javaToJS(it, callback as BaseFunction) }
|
||||
private fun callFunction(callback: Any, thiz: Any?, args: Any?) {
|
||||
val func = callback as BaseFunction
|
||||
val map: Array<Any> =
|
||||
(args as? Array<*>)?.map { Context.javaToJS(it, callback.parentScope) }
|
||||
?.toTypedArray() ?: emptyArray()
|
||||
try {
|
||||
(callback as BaseFunction).call(Context.getCurrentContext(),callback.parentScope,
|
||||
thiz as? Scriptable?, map.toTypedArray()
|
||||
func.call(
|
||||
context ?: Context.enter(), func.parentScope,
|
||||
thiz as? Scriptable ?: Undefined.SCRIPTABLE_UNDEFINED, map
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
if (isUiLoop) {
|
||||
mRuntime.exit(e)
|
||||
} else throw e
|
||||
}finally {
|
||||
context ?: Context.exit()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#Wed Jun 14 13:27:56 CST 2023
|
||||
BUILD_TIME=1686720476407
|
||||
#Wed Jun 14 18:20:43 CST 2023
|
||||
BUILD_TIME=1686738043084
|
||||
COMPILE_SDK_VERSION=33
|
||||
JAVA_VERSION=20
|
||||
MIN_SDK_VERSION=24
|
||||
TARGET_SDK_VERSION=33
|
||||
VERSION_BUILD=1914
|
||||
VERSION_BUILD=1916
|
||||
VERSION_NAME=6.3.1
|
||||
|
||||
Reference in New Issue
Block a user