6.7.0 - Alpha21 - Fine tuning
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package org.autojs.autojs.runtime
|
||||
|
||||
import org.autojs.autojs.annotation.ScriptInterface
|
||||
import org.autojs.autojs.core.automator.UiObjectCollection
|
||||
import org.autojs.autojs.engine.RhinoJavaScriptEngine
|
||||
import org.autojs.autojs.util.RhinoUtils.callFunction
|
||||
@@ -15,15 +16,17 @@ import org.mozilla.javascript.Undefined
|
||||
|
||||
/**
|
||||
* Created by Stardust on Jul 21, 2017.
|
||||
* Modified by SuperMonster003 as of May 26, 2022.
|
||||
* Transformed by SuperMonster003 on Nov 7, 2023.
|
||||
* Modified by SuperMonster003 as of Feb 13, 2026.
|
||||
*
|
||||
* @Reference to aiselp (https://github.com/aiselp) on Nov 7, 2023.
|
||||
* https://github.com/kkevsekk1/AutoX/pull/529/commits/782f1c3c12dee64d9b1ad70aba462afaf60313a4#diff-b8e544bc658140f04a7fa7171cc938032f18c92495ca25bb08e2d2eb546b70f5
|
||||
*/
|
||||
class ScriptBridges : IScriptBridges {
|
||||
|
||||
lateinit var engine: RhinoJavaScriptEngine
|
||||
@get:ScriptInterface
|
||||
var engine: RhinoJavaScriptEngine? = null
|
||||
private set
|
||||
|
||||
fun setup(engine: RhinoJavaScriptEngine) {
|
||||
this.engine = engine
|
||||
@@ -43,11 +46,11 @@ class ScriptBridges : IScriptBridges {
|
||||
val niceArgs = args.map { Context.javaToJS(it, niceScope) }.toTypedArray()
|
||||
val thisObj = Context.javaToJS(target, niceScope) as? Scriptable ?: Undefined.SCRIPTABLE_UNDEFINED
|
||||
|
||||
callFunction(engine.runtime, func, niceScope, thisObj, niceArgs)
|
||||
callFunction(engine?.runtime, func, niceScope, thisObj, niceArgs)
|
||||
}
|
||||
|
||||
override fun toArray(o: Iterable<*>?): NativeArray = useJsContext { cx ->
|
||||
val scope = engine.runtime.topLevelScope
|
||||
val scope = engine?.runtime?.topLevelScope ?: cx.initStandardObjects()
|
||||
cx.newArray(scope, o?.map { Context.javaToJS(it, scope) }?.toTypedArray()) as NativeArray
|
||||
}
|
||||
|
||||
@@ -72,12 +75,15 @@ class ScriptBridges : IScriptBridges {
|
||||
override fun toString(obj: Any?): String =
|
||||
Context.toString(obj)
|
||||
|
||||
override fun toPrimitive(obj: Any?): Any? =
|
||||
Context.javaToJS(obj, engine.runtime.topLevelScope)
|
||||
override fun toPrimitive(obj: Any?): Any? = useJsContext { cx ->
|
||||
val scope = engine?.runtime?.topLevelScope ?: cx.initStandardObjects()
|
||||
Context.javaToJS(obj, scope)
|
||||
}
|
||||
|
||||
private fun <T> useJsContext(f: (Context) -> T): T {
|
||||
val currentContext = Context.getCurrentContext()
|
||||
return try {
|
||||
val engine = engine ?: return f(Context.enter())
|
||||
// Enter Context via engine to ensure WrapFactory and AutoJsContext binding are installed.
|
||||
// zh-CN: 通过 engine 进入 Context, 确保 WrapFactory 与 AutoJsContext 绑定已安装.
|
||||
f(currentContext ?: engine.enterContext())
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.ArrayDeque
|
||||
*/
|
||||
object ScriptToast {
|
||||
|
||||
private const val MAX_GLOBAL_QUEUE_SIZE = 17
|
||||
private const val MAX_GLOBAL_QUEUE_SIZE = 32
|
||||
|
||||
private val mainHandler = Handler(Looper.getMainLooper())
|
||||
private val queue = ArrayDeque<ToastTask>(MAX_GLOBAL_QUEUE_SIZE)
|
||||
@@ -56,13 +56,15 @@ object ScriptToast {
|
||||
return
|
||||
}
|
||||
|
||||
val task = ToastTask(message, duration, ownerId)
|
||||
|
||||
if (queue.size >= MAX_GLOBAL_QUEUE_SIZE) {
|
||||
// Discard newest task when the queue is full.
|
||||
// zh-CN: 当队列已满时丢弃最新任务.
|
||||
return
|
||||
// Keep newest: discard oldest when queue is full.
|
||||
// zh-CN: 保留最新: 队列满时丢弃最旧任务.
|
||||
queue.removeFirstOrNull()
|
||||
}
|
||||
|
||||
queue.addLast(ToastTask(message, duration, ownerId))
|
||||
queue.addLast(task)
|
||||
|
||||
tryShowNextLocked(context.applicationContext)
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ object VersionCodes : Augmentable() {
|
||||
val (_, month, day, year) = it.groupValues
|
||||
"$year,${monthMap[month.lowercase().slice(0..2)]!!.minus(1)},$day"
|
||||
}
|
||||
val (year, month, day) = replaceFullDate.split(',').map { it.toInt() }
|
||||
val (year, month, day) = replaceFullDate.split(',').map { it.toIntOrNull() ?: return@parseTimestamp 0 }
|
||||
return Calendar.getInstance().apply {
|
||||
clear()
|
||||
set(year, month, day)
|
||||
|
||||
Reference in New Issue
Block a user