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