6.7.0 - Alpha23 - Fine tuning

This commit is contained in:
SuperMonster003
2026-03-09 21:01:48 +08:00
parent e5e251ae72
commit 6be328f00c
28 changed files with 101 additions and 100 deletions

2
.gitignore vendored
View File

@@ -6,6 +6,8 @@
*.log *.log
*.ffs_db *.ffs_db
*.patch *.patch
*.salive
.tmp_*.txt
.DS_Store .DS_Store
.externalNativeBuild .externalNativeBuild

View File

@@ -68,7 +68,7 @@ public class ProcessShell extends AbstractShell {
@Override @Override
public void exit() { public void exit() {
if (mProcess != null) { if (mProcess != null) {
Log.d(TAG, "exit: pid = " + ProcessUtils.getProcessPid(mProcess)); // Log.d(TAG, "exit: pid = " + ProcessUtils.getProcessPid(mProcess));
mProcess.destroy(); mProcess.destroy();
mProcess = null; mProcess = null;
} }
@@ -202,11 +202,11 @@ public class ProcessShell extends AbstractShell {
} }
os.writeBytes(COMMAND_EXIT); os.writeBytes(COMMAND_EXIT);
os.flush(); os.flush();
Log.d(TAG, "pid = " + ProcessUtils.getProcessPid(process)); // Log.d(TAG, "pid = " + ProcessUtils.getProcessPid(process));
commandResult = new Result(process.waitFor(), commandResult = new Result(process.waitFor(),
readAll(process.getInputStream()), readAll(process.getInputStream()),
readAll(process.getErrorStream())); readAll(process.getErrorStream()));
Log.d(TAG, commandResult.toString()); // Log.d(TAG, commandResult.toString());
} catch (Exception e) { } catch (Exception e) {
// @Overwrite by SuperMonster003 on Apr 26, 2022. // @Overwrite by SuperMonster003 on Apr 26, 2022.
// ! Try writing exception into commandResult and make it visible to AutoJs6 console. // ! Try writing exception into commandResult and make it visible to AutoJs6 console.

View File

@@ -7,6 +7,8 @@ import android.os.Looper
import android.widget.Toast import android.widget.Toast
import org.autojs.autojs.runtime.ScriptRuntime import org.autojs.autojs.runtime.ScriptRuntime
import java.util.ArrayDeque import java.util.ArrayDeque
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
/** /**
* Toast global queue manager. * Toast global queue manager.
@@ -25,6 +27,7 @@ import java.util.ArrayDeque
object ScriptToast { object ScriptToast {
private const val MAX_GLOBAL_QUEUE_SIZE = 32 private const val MAX_GLOBAL_QUEUE_SIZE = 32
private const val ENQUEUE_SYNC_WAIT_MS = 1_000L
private val mainHandler = Handler(Looper.getMainLooper()) private val mainHandler = Handler(Looper.getMainLooper())
private val queue = ArrayDeque<ToastTask>(MAX_GLOBAL_QUEUE_SIZE) private val queue = ArrayDeque<ToastTask>(MAX_GLOBAL_QUEUE_SIZE)
@@ -52,7 +55,18 @@ object ScriptToast {
// Must be called on the main thread. // Must be called on the main thread.
// zh-CN: 必须在主线程调用. // zh-CN: 必须在主线程调用.
if (Looper.myLooper() != Looper.getMainLooper()) { if (Looper.myLooper() != Looper.getMainLooper()) {
mainHandler.post { enqueueToast(context, scriptRuntime, message, isLong) } val appContext = context.applicationContext
val latch = CountDownLatch(1)
mainHandler.postAtFrontOfQueue {
try {
enqueueToast(appContext, scriptRuntime, message, isLong)
} finally {
latch.countDown()
}
}
runCatching {
latch.await(ENQUEUE_SYNC_WAIT_MS, TimeUnit.MILLISECONDS)
}
return return
} }

View File

@@ -13,6 +13,7 @@ import org.autojs.autojs.core.ui.dialog.JsDialog
import org.autojs.autojs.core.ui.dialog.JsDialogBuilder import org.autojs.autojs.core.ui.dialog.JsDialogBuilder
import org.autojs.autojs.core.ui.nativeview.NativeView import org.autojs.autojs.core.ui.nativeview.NativeView
import org.autojs.autojs.event.BackCompat.TAG_KEY_INSTALLED import org.autojs.autojs.event.BackCompat.TAG_KEY_INSTALLED
import org.autojs.autojs.rhino.ArgumentGuards
import org.autojs.autojs.rhino.ArgumentGuards.Companion.component1 import org.autojs.autojs.rhino.ArgumentGuards.Companion.component1
import org.autojs.autojs.rhino.ArgumentGuards.Companion.component2 import org.autojs.autojs.rhino.ArgumentGuards.Companion.component2
import org.autojs.autojs.rhino.ArgumentGuards.Companion.component3 import org.autojs.autojs.rhino.ArgumentGuards.Companion.component3
@@ -65,7 +66,7 @@ class Dialogs(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) {
::multiChoice.name, ::multiChoice.name,
) )
companion object { companion object : ArgumentGuards() {
private enum class PropertyConverter { private enum class PropertyConverter {
COLOR_INT, BOOLEAN, COLOR_INT, BOOLEAN,

View File

@@ -5,6 +5,7 @@ import io.github.g00fy2.versioncompare.Version
import org.autojs.autojs.annotation.RhinoFunctionBody import org.autojs.autojs.annotation.RhinoFunctionBody
import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface
import org.autojs.autojs.core.automator.UiObject import org.autojs.autojs.core.automator.UiObject
import org.autojs.autojs.rhino.ArgumentGuards
import org.autojs.autojs.rhino.ArgumentGuards.Companion.component1 import org.autojs.autojs.rhino.ArgumentGuards.Companion.component1
import org.autojs.autojs.rhino.ArgumentGuards.Companion.component2 import org.autojs.autojs.rhino.ArgumentGuards.Companion.component2
import org.autojs.autojs.rhino.ArgumentGuards.Companion.component3 import org.autojs.autojs.rhino.ArgumentGuards.Companion.component3
@@ -117,7 +118,7 @@ class Global(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRunti
"i18n" to Supplier { scriptRuntime.js_mod_i18n }, "i18n" to Supplier { scriptRuntime.js_mod_i18n },
) )
companion object { companion object : ArgumentGuards() {
@Suppress("FunctionName") @Suppress("FunctionName")
@JvmStatic @JvmStatic

View File

@@ -1,6 +1,7 @@
package org.autojs.autojs.runtime.api.augment.global package org.autojs.autojs.runtime.api.augment.global
import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface
import org.autojs.autojs.rhino.ArgumentGuards
import org.autojs.autojs.runtime.ScriptRuntime import org.autojs.autojs.runtime.ScriptRuntime
import org.autojs.autojs.runtime.api.augment.Augmentable import org.autojs.autojs.runtime.api.augment.Augmentable
import org.autojs.autojs.runtime.api.augment.util.Util import org.autojs.autojs.runtime.api.augment.util.Util
@@ -13,7 +14,7 @@ class Legacy(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) {
::isObjectSpecies.name, ::isObjectSpecies.name,
) )
companion object { companion object : ArgumentGuards() {
@JvmStatic @JvmStatic
@RhinoRuntimeFunctionInterface @RhinoRuntimeFunctionInterface

View File

@@ -1,7 +1,7 @@
package org.autojs.autojs.runtime.api.augment.http package org.autojs.autojs.runtime.api.augment.http
import org.autojs.autojs.annotation.RhinoStandardFunctionInterface import org.autojs.autojs.annotation.RhinoStandardFunctionInterface
import org.autojs.autojs.rhino.ArgumentGuards.Companion.ensureArgumentsIsEmpty import org.autojs.autojs.rhino.ArgumentGuards
import org.autojs.autojs.runtime.api.StringReadable import org.autojs.autojs.runtime.api.StringReadable
import org.autojs.autojs.runtime.api.augment.converter.core.Bytes import org.autojs.autojs.runtime.api.augment.converter.core.Bytes
import org.autojs.autojs.util.RhinoUtils import org.autojs.autojs.util.RhinoUtils
@@ -37,7 +37,7 @@ class HttpSaveResult @JvmOverloads constructor(
"}", "}",
).joinToString("\n") ).joinToString("\n")
companion object { companion object : ArgumentGuards() {
const val RESULT_OK = 0 const val RESULT_OK = 0

View File

@@ -11,6 +11,7 @@ import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface
import org.autojs.autojs.core.image.ColorDetector import org.autojs.autojs.core.image.ColorDetector
import org.autojs.autojs.core.image.ImageWrapper import org.autojs.autojs.core.image.ImageWrapper
import org.autojs.autojs.core.image.capture.ScreenCapturer import org.autojs.autojs.core.image.capture.ScreenCapturer
import org.autojs.autojs.rhino.ArgumentGuards
import org.autojs.autojs.rhino.extension.AnyExtensions.isJsArray import org.autojs.autojs.rhino.extension.AnyExtensions.isJsArray
import org.autojs.autojs.rhino.extension.AnyExtensions.isJsNullish import org.autojs.autojs.rhino.extension.AnyExtensions.isJsNullish
import org.autojs.autojs.rhino.extension.AnyExtensions.isJsNumber import org.autojs.autojs.rhino.extension.AnyExtensions.isJsNumber
@@ -161,7 +162,7 @@ class Images(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime), AsEmitt
) )
@Suppress("MayBeConstant") @Suppress("MayBeConstant")
companion object { companion object : ArgumentGuards() {
private val TAG = Images::class.java.simpleName private val TAG = Images::class.java.simpleName

View File

@@ -1,6 +1,7 @@
package org.autojs.autojs.runtime.api.augment.mediainfo package org.autojs.autojs.runtime.api.augment.mediainfo
import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface
import org.autojs.autojs.rhino.ArgumentGuards
import org.autojs.autojs.runtime.ScriptRuntime import org.autojs.autojs.runtime.ScriptRuntime
import org.autojs.autojs.runtime.api.augment.Augmentable import org.autojs.autojs.runtime.api.augment.Augmentable
import org.autojs.autojs.runtime.api.augment.Invokable import org.autojs.autojs.runtime.api.augment.Invokable
@@ -17,7 +18,7 @@ class Mediainfo(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRu
read(scriptRuntime, arrayOf(path)) read(scriptRuntime, arrayOf(path))
} }
companion object { companion object : ArgumentGuards() {
@JvmStatic @JvmStatic
@RhinoRuntimeFunctionInterface @RhinoRuntimeFunctionInterface

View File

@@ -2,6 +2,7 @@ package org.autojs.autojs.runtime.api.augment.mediainfo
import org.autojs.autojs.annotation.RhinoFunctionBody import org.autojs.autojs.annotation.RhinoFunctionBody
import org.autojs.autojs.annotation.RhinoStandardFunctionInterface import org.autojs.autojs.annotation.RhinoStandardFunctionInterface
import org.autojs.autojs.rhino.ArgumentGuards
import org.autojs.autojs.rhino.extension.AnyExtensions.isJsNullish import org.autojs.autojs.rhino.extension.AnyExtensions.isJsNullish
import org.autojs.autojs.rhino.extension.AnyExtensions.jsBrief import org.autojs.autojs.rhino.extension.AnyExtensions.jsBrief
import org.autojs.autojs.rhino.ArgumentGuards.Companion.ensureArgumentsIsEmpty import org.autojs.autojs.rhino.ArgumentGuards.Companion.ensureArgumentsIsEmpty
@@ -98,7 +99,7 @@ class MediainfoNativeObject(
override fun toStringReadable() = toStringRhino(this) override fun toStringReadable() = toStringRhino(this)
companion object { companion object : ArgumentGuards() {
@JvmStatic @JvmStatic
@RhinoStandardFunctionInterface @RhinoStandardFunctionInterface

View File

@@ -7,6 +7,7 @@ import android.app.NotificationManager
import android.os.Build import android.os.Build
import org.autojs.autojs.annotation.RhinoFunctionBody import org.autojs.autojs.annotation.RhinoFunctionBody
import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface
import org.autojs.autojs.rhino.ArgumentGuards
import org.autojs.autojs.rhino.extension.AnyExtensions.isJsNullish import org.autojs.autojs.rhino.extension.AnyExtensions.isJsNullish
import org.autojs.autojs.rhino.extension.AnyExtensions.jsBrief import org.autojs.autojs.rhino.extension.AnyExtensions.jsBrief
import org.autojs.autojs.rhino.extension.IterableExtensions.toNativeArray import org.autojs.autojs.rhino.extension.IterableExtensions.toNativeArray
@@ -30,7 +31,7 @@ import org.autojs.autojs.runtime.api.augment.notice.Notice as AugmentableNotice
class Channel(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) { class Channel(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) {
companion object { companion object : ArgumentGuards() {
@JvmStatic @JvmStatic
@RhinoRuntimeFunctionInterface @RhinoRuntimeFunctionInterface

View File

@@ -6,6 +6,7 @@ import androidx.core.app.NotificationCompat.BigTextStyle
import androidx.core.app.NotificationCompat.Builder import androidx.core.app.NotificationCompat.Builder
import androidx.core.app.NotificationManagerCompat import androidx.core.app.NotificationManagerCompat
import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface
import org.autojs.autojs.rhino.ArgumentGuards
import org.autojs.autojs.rhino.extension.AnyExtensions.isJsNullish import org.autojs.autojs.rhino.extension.AnyExtensions.isJsNullish
import org.autojs.autojs.rhino.extension.AnyExtensions.jsBrief import org.autojs.autojs.rhino.extension.AnyExtensions.jsBrief
import org.autojs.autojs.rhino.extension.ScriptableExtensions.prop import org.autojs.autojs.rhino.extension.ScriptableExtensions.prop
@@ -210,7 +211,7 @@ class Notice(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRunti
} }
} }
companion object { companion object : ArgumentGuards() {
@JvmStatic @JvmStatic
@RhinoRuntimeFunctionInterface @RhinoRuntimeFunctionInterface

View File

@@ -2,6 +2,7 @@ package org.autojs.autojs.runtime.api.augment.ocr
import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface
import org.autojs.autojs.core.image.ImageWrapper import org.autojs.autojs.core.image.ImageWrapper
import org.autojs.autojs.rhino.ArgumentGuards
import org.autojs.autojs.rhino.ArgumentGuards.Companion.component1 import org.autojs.autojs.rhino.ArgumentGuards.Companion.component1
import org.autojs.autojs.rhino.ArgumentGuards.Companion.component2 import org.autojs.autojs.rhino.ArgumentGuards.Companion.component2
import org.autojs.autojs.rhino.ArgumentGuards.Companion.component3 import org.autojs.autojs.rhino.ArgumentGuards.Companion.component3
@@ -48,7 +49,7 @@ class Ocr(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime)
override fun invoke(vararg args: Any?): NativeArray = recognizeText(scriptRuntime, args) override fun invoke(vararg args: Any?): NativeArray = recognizeText(scriptRuntime, args)
companion object { companion object : ArgumentGuards() {
@JvmStatic @JvmStatic
@RhinoRuntimeFunctionInterface @RhinoRuntimeFunctionInterface

View File

@@ -3,6 +3,7 @@ package org.autojs.autojs.runtime.api.augment.ocr
import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface
import org.autojs.autojs.apkbuilder.ApkBuilder import org.autojs.autojs.apkbuilder.ApkBuilder
import org.autojs.autojs.core.image.ImageWrapper import org.autojs.autojs.core.image.ImageWrapper
import org.autojs.autojs.rhino.ArgumentGuards
import org.autojs.autojs.runtime.ScriptRuntime import org.autojs.autojs.runtime.ScriptRuntime
import org.autojs.autojs.runtime.api.OcrResult import org.autojs.autojs.runtime.api.OcrResult
import org.autojs.autojs.runtime.api.augment.Augmentable import org.autojs.autojs.runtime.api.augment.Augmentable
@@ -23,7 +24,7 @@ class OcrMLKit(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRun
override fun invoke(vararg args: Any?): NativeArray = recognizeText(scriptRuntime, args) override fun invoke(vararg args: Any?): NativeArray = recognizeText(scriptRuntime, args)
@Suppress("unused") @Suppress("unused")
companion object { companion object : ArgumentGuards() {
@JvmStatic @JvmStatic
@RhinoRuntimeFunctionInterface @RhinoRuntimeFunctionInterface

View File

@@ -9,6 +9,7 @@ import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface
import org.autojs.autojs.apkbuilder.ApkBuilder import org.autojs.autojs.apkbuilder.ApkBuilder
import org.autojs.autojs.core.image.ImageWrapper import org.autojs.autojs.core.image.ImageWrapper
import org.autojs.autojs.core.plugin.ocr.PaddleOcrPluginHost import org.autojs.autojs.core.plugin.ocr.PaddleOcrPluginHost
import org.autojs.autojs.rhino.ArgumentGuards
import org.autojs.autojs.rhino.extension.ScriptableObjectExtensions.inquire import org.autojs.autojs.rhino.extension.ScriptableObjectExtensions.inquire
import org.autojs.autojs.runtime.ScriptRuntime import org.autojs.autojs.runtime.ScriptRuntime
import org.autojs.autojs.runtime.api.OcrResult import org.autojs.autojs.runtime.api.OcrResult
@@ -42,7 +43,7 @@ class OcrPaddle(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRu
override fun invoke(vararg args: Any?): NativeArray = recognizeText(scriptRuntime, args) override fun invoke(vararg args: Any?): NativeArray = recognizeText(scriptRuntime, args)
companion object { companion object : ArgumentGuards() {
private const val DEFAULT_CPU_THREAD_NUM = 4 private const val DEFAULT_CPU_THREAD_NUM = 4

View File

@@ -3,6 +3,7 @@ package org.autojs.autojs.runtime.api.augment.ocr
import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface
import org.autojs.autojs.apkbuilder.ApkBuilder import org.autojs.autojs.apkbuilder.ApkBuilder
import org.autojs.autojs.core.image.ImageWrapper import org.autojs.autojs.core.image.ImageWrapper
import org.autojs.autojs.rhino.ArgumentGuards
import org.autojs.autojs.runtime.ScriptRuntime import org.autojs.autojs.runtime.ScriptRuntime
import org.autojs.autojs.runtime.api.OcrResult import org.autojs.autojs.runtime.api.OcrResult
import org.autojs.autojs.runtime.api.augment.Augmentable import org.autojs.autojs.runtime.api.augment.Augmentable
@@ -22,7 +23,7 @@ class OcrRapid(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRun
override fun invoke(vararg args: Any?): NativeArray = recognizeText(scriptRuntime, args) override fun invoke(vararg args: Any?): NativeArray = recognizeText(scriptRuntime, args)
companion object { companion object : ArgumentGuards() {
@JvmStatic @JvmStatic
@RhinoRuntimeFunctionInterface @RhinoRuntimeFunctionInterface

View File

@@ -1,6 +1,7 @@
package org.autojs.autojs.runtime.api.augment.shizuku package org.autojs.autojs.runtime.api.augment.shizuku
import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface
import org.autojs.autojs.rhino.ArgumentGuards
import org.autojs.autojs.rhino.extension.ScriptableExtensions.defineProp import org.autojs.autojs.rhino.extension.ScriptableExtensions.defineProp
import org.autojs.autojs.runtime.ScriptRuntime import org.autojs.autojs.runtime.ScriptRuntime
import org.autojs.autojs.runtime.api.AbstractShell import org.autojs.autojs.runtime.api.AbstractShell
@@ -38,7 +39,7 @@ class Shizuku(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRunt
override fun invoke(vararg args: Any?): AbstractShell.Result = execCommand(scriptRuntime, args) override fun invoke(vararg args: Any?): AbstractShell.Result = execCommand(scriptRuntime, args)
companion object { companion object : ArgumentGuards() {
@JvmStatic @JvmStatic
@RhinoRuntimeFunctionInterface @RhinoRuntimeFunctionInterface

View File

@@ -3,6 +3,7 @@ package org.autojs.autojs.runtime.api.augment.sqlite
import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface
import org.autojs.autojs.core.database.Database import org.autojs.autojs.core.database.Database
import org.autojs.autojs.core.database.Database.DatabaseCallback import org.autojs.autojs.core.database.Database.DatabaseCallback
import org.autojs.autojs.rhino.ArgumentGuards
import org.autojs.autojs.rhino.extension.AnyExtensions.isJsNullish import org.autojs.autojs.rhino.extension.AnyExtensions.isJsNullish
import org.autojs.autojs.rhino.extension.AnyExtensions.jsBrief import org.autojs.autojs.rhino.extension.AnyExtensions.jsBrief
import org.autojs.autojs.rhino.extension.AnyExtensions.jsSanitize import org.autojs.autojs.rhino.extension.AnyExtensions.jsSanitize
@@ -31,7 +32,7 @@ class SQLite(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRunti
open(scriptRuntime, argList) open(scriptRuntime, argList)
} }
companion object { companion object : ArgumentGuards() {
@JvmStatic @JvmStatic
@RhinoRuntimeFunctionInterface @RhinoRuntimeFunctionInterface

View File

@@ -1,6 +1,7 @@
package org.autojs.autojs.runtime.api.augment.sysprops package org.autojs.autojs.runtime.api.augment.sysprops
import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface
import org.autojs.autojs.rhino.ArgumentGuards
import org.autojs.autojs.rhino.extension.AnyExtensions.isJsNullish import org.autojs.autojs.rhino.extension.AnyExtensions.isJsNullish
import org.autojs.autojs.rhino.extension.MapExtensions.toNativeObject import org.autojs.autojs.rhino.extension.MapExtensions.toNativeObject
import org.autojs.autojs.rhino.extension.ScriptableExtensions.prop import org.autojs.autojs.rhino.extension.ScriptableExtensions.prop
@@ -27,7 +28,7 @@ class SysProps(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime), Invok
::getAll.name, ::getAll.name,
) )
companion object { companion object : ArgumentGuards() {
@JvmStatic @JvmStatic
@RhinoRuntimeFunctionInterface @RhinoRuntimeFunctionInterface

View File

@@ -22,6 +22,7 @@ import org.autojs.autojs.core.ui.nativeview.NativeView
import org.autojs.autojs.core.ui.widget.JsListView import org.autojs.autojs.core.ui.widget.JsListView
import org.autojs.autojs.core.ui.widget.JsWebView import org.autojs.autojs.core.ui.widget.JsWebView
import org.autojs.autojs.execution.ScriptExecuteActivity import org.autojs.autojs.execution.ScriptExecuteActivity
import org.autojs.autojs.rhino.ArgumentGuards
import org.autojs.autojs.rhino.ArgumentGuards.Companion.component1 import org.autojs.autojs.rhino.ArgumentGuards.Companion.component1
import org.autojs.autojs.rhino.ArgumentGuards.Companion.component2 import org.autojs.autojs.rhino.ArgumentGuards.Companion.component2
import org.autojs.autojs.rhino.ArgumentGuards.Companion.component3 import org.autojs.autojs.rhino.ArgumentGuards.Companion.component3
@@ -362,7 +363,7 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt
} }
@Suppress("FunctionName") @Suppress("FunctionName")
companion object { companion object : ArgumentGuards() {
private const val WIDGET_KEY = "Widget" private const val WIDGET_KEY = "Widget"

View File

@@ -3,9 +3,9 @@ package org.autojs.autojs.runtime.api.augment.util
import org.autojs.autojs.annotation.RhinoFunctionBody import org.autojs.autojs.annotation.RhinoFunctionBody
import org.autojs.autojs.annotation.RhinoFunctionObjectBody import org.autojs.autojs.annotation.RhinoFunctionObjectBody
import org.autojs.autojs.annotation.RhinoStandardFunctionInterface import org.autojs.autojs.annotation.RhinoStandardFunctionInterface
import org.autojs.autojs.rhino.ArgumentGuards
import org.autojs.autojs.rhino.ArgumentGuards.Companion.component1
import org.autojs.autojs.rhino.extension.AnyExtensions.isJsNullish import org.autojs.autojs.rhino.extension.AnyExtensions.isJsNullish
import org.autojs.autojs.rhino.ArgumentGuards.Companion.ensureArgumentsAtMost
import org.autojs.autojs.rhino.ArgumentGuards.Companion.ensureArgumentsIsEmpty
import org.autojs.autojs.rhino.extension.IterableExtensions.toNativeArray import org.autojs.autojs.rhino.extension.IterableExtensions.toNativeArray
import org.autojs.autojs.runtime.api.StringReadable import org.autojs.autojs.runtime.api.StringReadable
import org.autojs.autojs.util.RhinoUtils import org.autojs.autojs.util.RhinoUtils
@@ -37,7 +37,7 @@ class MorseCodeNativeObject(val parser: MorseCodeParser) : NativeObject(), Strin
@RhinoFunctionObjectBody @RhinoFunctionObjectBody
override fun toStringReadable() = toStringRhino(this) override fun toStringReadable() = toStringRhino(this)
companion object { companion object : ArgumentGuards() {
@JvmStatic @JvmStatic
@RhinoStandardFunctionInterface @RhinoStandardFunctionInterface
@@ -77,7 +77,5 @@ class MorseCodeNativeObject(val parser: MorseCodeParser) : NativeObject(), Strin
val (delay) = it val (delay) = it
(thisObj as MorseCodeNativeObject).parser.vibrate(if (!delay.isJsNullish()) Context.toNumber(delay) else 0.0) (thisObj as MorseCodeNativeObject).parser.vibrate(if (!delay.isJsNullish()) Context.toNumber(delay) else 0.0)
} }
} }
} }

View File

@@ -2,6 +2,7 @@ package org.autojs.autojs.runtime.api.augment.zip
import okhttp3.internal.closeQuietly import okhttp3.internal.closeQuietly
import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface
import org.autojs.autojs.rhino.ArgumentGuards
import org.autojs.autojs.rhino.extension.AnyExtensions.isJsNullish import org.autojs.autojs.rhino.extension.AnyExtensions.isJsNullish
import org.autojs.autojs.rhino.extension.AnyExtensions.jsBrief import org.autojs.autojs.rhino.extension.AnyExtensions.jsBrief
import org.autojs.autojs.rhino.ArgumentGuards.Companion.component1 import org.autojs.autojs.rhino.ArgumentGuards.Companion.component1
@@ -34,7 +35,7 @@ class Zip(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime)
open(scriptRuntime, arrayOf(zipPath)) open(scriptRuntime, arrayOf(zipPath))
} }
companion object { companion object : ArgumentGuards() {
@JvmStatic @JvmStatic
@RhinoRuntimeFunctionInterface @RhinoRuntimeFunctionInterface
@@ -84,7 +85,7 @@ class Zip(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime)
fun zipFiles(scriptRuntime: ScriptRuntime, args: Array<out Any?>): ZipNativeObject = ensureArgumentsLengthInRange(args, 2..3) { argList -> fun zipFiles(scriptRuntime: ScriptRuntime, args: Array<out Any?>): ZipNativeObject = ensureArgumentsLengthInRange(args, 2..3) { argList ->
var (filePathList, destZipPath, options) = argList var (filePathList, destZipPath, options) = argList
require(filePathList is Iterable<*>) { require(filePathList is Iterable<*>) {
"Argument \"filePathList\" ${filePathList.jsBrief()} for zip.${Companion::zipFiles.name} must be an Iterable" "Argument \"filePathList\" ${filePathList.jsBrief()} for zip.zipFiles must be an Iterable"
} }
val fileList = mutableListOf<File>() val fileList = mutableListOf<File>()
filePathList.forEach { filePath -> filePathList.forEach { filePath ->

View File

@@ -13,15 +13,16 @@ import net.lingala.zip4j.model.enums.CompressionMethod
import net.lingala.zip4j.model.enums.EncryptionMethod import net.lingala.zip4j.model.enums.EncryptionMethod
import org.autojs.autojs.annotation.RhinoFunctionBody import org.autojs.autojs.annotation.RhinoFunctionBody
import org.autojs.autojs.annotation.RhinoStandardFunctionInterface import org.autojs.autojs.annotation.RhinoStandardFunctionInterface
import org.autojs.autojs.rhino.ArgumentGuards
import org.autojs.autojs.rhino.ArgumentGuards.Companion.component1
import org.autojs.autojs.rhino.ArgumentGuards.Companion.component2
import org.autojs.autojs.rhino.ArgumentGuards.Companion.component3
import org.autojs.autojs.rhino.ArgumentGuards.Companion.component4
import org.autojs.autojs.rhino.extension.AnyExtensions.isJsNullish import org.autojs.autojs.rhino.extension.AnyExtensions.isJsNullish
import org.autojs.autojs.rhino.extension.AnyExtensions.isJsNumber import org.autojs.autojs.rhino.extension.AnyExtensions.isJsNumber
import org.autojs.autojs.rhino.extension.AnyExtensions.jsBrief import org.autojs.autojs.rhino.extension.AnyExtensions.jsBrief
import org.autojs.autojs.rhino.ArgumentGuards.Companion.ensureArgumentsIsEmpty
import org.autojs.autojs.rhino.ArgumentGuards.Companion.ensureArgumentsLengthInRange
import org.autojs.autojs.rhino.ArgumentGuards.Companion.ensureArgumentsOnlyOne
import org.autojs.autojs.rhino.extension.IterableExtensions.toNativeArray import org.autojs.autojs.rhino.extension.IterableExtensions.toNativeArray
import org.autojs.autojs.rhino.extension.ScriptableObjectExtensions.inquire import org.autojs.autojs.rhino.extension.ScriptableObjectExtensions.inquire
import org.autojs.autojs.util.StringUtils.toFile
import org.autojs.autojs.runtime.ScriptRuntime import org.autojs.autojs.runtime.ScriptRuntime
import org.autojs.autojs.runtime.api.StringReadable import org.autojs.autojs.runtime.api.StringReadable
import org.autojs.autojs.runtime.exception.WrappedIllegalArgumentException import org.autojs.autojs.runtime.exception.WrappedIllegalArgumentException
@@ -36,6 +37,7 @@ import org.autojs.autojs.util.RhinoUtils.coerceStringUppercase
import org.autojs.autojs.util.RhinoUtils.newBaseFunction import org.autojs.autojs.util.RhinoUtils.newBaseFunction
import org.autojs.autojs.util.RhinoUtils.newNativeObject import org.autojs.autojs.util.RhinoUtils.newNativeObject
import org.autojs.autojs.util.RhinoUtils.undefined import org.autojs.autojs.util.RhinoUtils.undefined
import org.autojs.autojs.util.StringUtils.toFile
import org.mozilla.javascript.BaseFunction import org.mozilla.javascript.BaseFunction
import org.mozilla.javascript.Context import org.mozilla.javascript.Context
import org.mozilla.javascript.Function import org.mozilla.javascript.Function
@@ -330,7 +332,7 @@ class ZipNativeObject(
else -> SymbolicLinkAction.valueOf(coerceStringUppercase(this)) else -> SymbolicLinkAction.valueOf(coerceStringUppercase(this))
} }
companion object { companion object : ArgumentGuards() {
@JvmStatic @JvmStatic
@RhinoStandardFunctionInterface @RhinoStandardFunctionInterface
@@ -375,7 +377,7 @@ class ZipNativeObject(
val zip = thisObj as ZipNativeObject val zip = thisObj as ZipNativeObject
val (filePath, options) = argList val (filePath, options) = argList
val file = zip.scriptRuntime.files.nonNullPath(coerceString(filePath)).toFile() val file = zip.scriptRuntime.files.nonNullPath(coerceString(filePath)).toFile()
val zipParameters = zip.buildZipParameters(Companion::addFile.name, options) val zipParameters = zip.buildZipParameters("addFile", options)
undefined { zip.zipFile.addFile(file, zipParameters) } undefined { zip.zipFile.addFile(file, zipParameters) }
} }
@@ -385,13 +387,13 @@ class ZipNativeObject(
val zip = thisObj as ZipNativeObject val zip = thisObj as ZipNativeObject
val (filePathList, options) = argList val (filePathList, options) = argList
require(filePathList is Iterable<*>) { require(filePathList is Iterable<*>) {
"Argument \"filePathList\" ${filePathList.jsBrief()} for ${ZipNativeObject::class.java.simpleName}#${Companion::addFiles.name} must be an Iterable" "Argument \"filePathList\" ${filePathList.jsBrief()} for ${ZipNativeObject::class.java.simpleName}#${"addFiles"} must be an Iterable"
} }
val fileList = mutableListOf<File>() val fileList = mutableListOf<File>()
filePathList.forEach { rawFilePath -> filePathList.forEach { rawFilePath ->
fileList.add(zip.scriptRuntime.files.nonNullPath(coerceString(rawFilePath)).toFile()) fileList.add(zip.scriptRuntime.files.nonNullPath(coerceString(rawFilePath)).toFile())
} }
val zipParameters = zip.buildZipParameters(Companion::addFiles.name, options) val zipParameters = zip.buildZipParameters("addFiles", options)
undefined { zip.zipFile.addFiles(fileList, zipParameters) } undefined { zip.zipFile.addFiles(fileList, zipParameters) }
} }
@@ -401,7 +403,7 @@ class ZipNativeObject(
val zip = thisObj as ZipNativeObject val zip = thisObj as ZipNativeObject
val (filePath, options) = argList val (filePath, options) = argList
val file = zip.scriptRuntime.files.nonNullPath(coerceString(filePath)).toFile() val file = zip.scriptRuntime.files.nonNullPath(coerceString(filePath)).toFile()
val zipParameters = zip.buildZipParameters(Companion::addFolder.name, options) val zipParameters = zip.buildZipParameters("addFolder", options)
undefined { zip.zipFile.addFolder(file, zipParameters) } undefined { zip.zipFile.addFolder(file, zipParameters) }
} }
@@ -411,7 +413,7 @@ class ZipNativeObject(
val zip = thisObj as ZipNativeObject val zip = thisObj as ZipNativeObject
val (rawDestPath, options) = argList val (rawDestPath, options) = argList
val destPath = zip.scriptRuntime.files.nonNullPath(coerceString(rawDestPath)) val destPath = zip.scriptRuntime.files.nonNullPath(coerceString(rawDestPath))
val unzipParameters = zip.buildUnzipParameters(Companion::extractAll.name, options) val unzipParameters = zip.buildUnzipParameters("extractAll", options)
undefined { zip.zipFile.extractAll(destPath, unzipParameters) } undefined { zip.zipFile.extractAll(destPath, unzipParameters) }
} }
@@ -423,7 +425,7 @@ class ZipNativeObject(
val zipFilePath = zip.scriptRuntime.files.nonNullPath(coerceString(rawZipFilePath)) val zipFilePath = zip.scriptRuntime.files.nonNullPath(coerceString(rawZipFilePath))
val destPath = zip.scriptRuntime.files.nonNullPath(coerceString(rawDestPath)) val destPath = zip.scriptRuntime.files.nonNullPath(coerceString(rawDestPath))
val newFileName = rawNewFileName.takeUnless { it.isJsNullish() }?.let { coerceString(it) } val newFileName = rawNewFileName.takeUnless { it.isJsNullish() }?.let { coerceString(it) }
val unzipParameters = zip.buildUnzipParameters(Companion::extractFile.name, options) val unzipParameters = zip.buildUnzipParameters("extractFile", options)
undefined { zip.zipFile.extractFile(zipFilePath, destPath, newFileName, unzipParameters) } undefined { zip.zipFile.extractFile(zipFilePath, destPath, newFileName, unzipParameters) }
} }

View File

@@ -2,13 +2,11 @@ package org.autojs.autojs.theme.app
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.res.Configuration
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewAnimationUtils import android.view.ViewAnimationUtils
import androidx.annotation.StringRes
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
@@ -47,6 +45,7 @@ import org.autojs.autojs.ui.BaseActivity
import org.autojs.autojs.ui.main.drawer.DrawerFragment.Companion.Event.ThemeColorLayoutSwitchedEvent import org.autojs.autojs.ui.main.drawer.DrawerFragment.Companion.Event.ThemeColorLayoutSwitchedEvent
import org.autojs.autojs.util.ColorUtils import org.autojs.autojs.util.ColorUtils
import org.autojs.autojs.util.IntentUtils.startSafely import org.autojs.autojs.util.IntentUtils.startSafely
import org.autojs.autojs.util.StringUtils
import org.autojs.autojs.util.ViewUtils import org.autojs.autojs.util.ViewUtils
import org.autojs.autojs.util.ViewUtils.onceGlobalLayout import org.autojs.autojs.util.ViewUtils.onceGlobalLayout
import org.autojs.autojs.util.ViewUtils.setColorsByColorLuminance import org.autojs.autojs.util.ViewUtils.setColorsByColorLuminance
@@ -55,7 +54,7 @@ import org.autojs.autojs.util.ViewUtils.setNavigationIconColorByColorLuminance
import org.autojs.autojs.util.ViewUtils.setTitlesTextColorByColorLuminance import org.autojs.autojs.util.ViewUtils.setTitlesTextColorByColorLuminance
import org.autojs.autojs6.R import org.autojs.autojs6.R
import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.EventBus
import java.util.* import java.util.Locale
import kotlin.math.absoluteValue import kotlin.math.absoluteValue
import kotlin.math.hypot import kotlin.math.hypot
import kotlin.properties.Delegates import kotlin.properties.Delegates
@@ -537,7 +536,7 @@ abstract class ColorSelectBaseActivity : BaseActivity() {
val normalizedQuery = normalizeForMatching(searchTerm) val normalizedQuery = normalizeForMatching(searchTerm)
colorItems.filter { colorItem -> colorItems.filter { colorItem ->
val colorHex = String.format("#%06X", 0xFFFFFF and getColor(colorItem.colorRes)) val colorHex = String.format("#%06X", 0xFFFFFF and getColor(colorItem.colorRes))
val enName by lazy { getLocalizedString(this@ColorSelectBaseActivity, colorItem.nameRes, Locale.forLanguageTag("en")) } val enName by lazy { StringUtils.getStringForLocale(this@ColorSelectBaseActivity, Locale.forLanguageTag("en"), colorItem.nameRes) }
val localizedName by lazy { getString(colorItem.nameRes) } val localizedName by lazy { getString(colorItem.nameRes) }
when { when {
searchTerm.startsWith("#") -> { searchTerm.startsWith("#") -> {
@@ -577,12 +576,6 @@ abstract class ColorSelectBaseActivity : BaseActivity() {
return input.replace("[^\\p{L}\\p{N}]+".toRegex(), "") return input.replace("[^\\p{L}\\p{N}]+".toRegex(), "")
} }
private fun getLocalizedString(context: Context, @StringRes resId: Int, locale: Locale): String {
val config = Configuration(context.resources.configuration).apply { setLocale(locale) }
val localizedContext = context.createConfigurationContext(config)
return localizedContext.getString(resId)
}
private fun isRegexSearch(query: String?): Boolean { private fun isRegexSearch(query: String?): Boolean {
if (query.isNullOrBlank()) return false if (query.isNullOrBlank()) return false
return query.length > 2 && query.startsWith("/") && query.endsWith("/") return query.length > 2 && query.startsWith("/") && query.endsWith("/")

View File

@@ -719,9 +719,6 @@ class CodeEditText : AppCompatEditText {
// zh-CN: 当用户触摸文本区域 (非行号区域) 时尽早通知外层. // zh-CN: 当用户触摸文本区域 (非行号区域) 时尽早通知外层.
if (event.action == MotionEvent.ACTION_DOWN && event.x >= paddingLeft) { if (event.action == MotionEvent.ACTION_DOWN && event.x >= paddingLeft) {
onUserTouchInTextArea?.invoke() onUserTouchInTextArea?.invoke()
// Best-effort IME wake-up for devices/ROMs where tap-to-show may be missed.
// zh-CN: 兜底唤起输入法, 兼容部分设备/ROM 点按后未自动弹出软键盘的情况.
requestSoftInputIfEditable()
} }
// 如果行号区域被按下 // 如果行号区域被按下
@@ -754,20 +751,6 @@ class CodeEditText : AppCompatEditText {
return super.onTouchEvent(event) return super.onTouchEvent(event)
} }
private fun requestSoftInputIfEditable() {
if (mReadOnly || !showSoftInputOnFocus) return
if (!isFocusable || !isFocusableInTouchMode) return
post {
if (mReadOnly || !showSoftInputOnFocus) return@post
if (!hasFocus()) {
requestFocus()
}
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager ?: return@post
imm.showSoftInput(this@CodeEditText, InputMethodManager.SHOW_IMPLICIT)
}
}
fun removeBreakpoint(line: Int): Boolean { fun removeBreakpoint(line: Int): Boolean {
breakpoints.remove(line) ?: return false breakpoints.remove(line) ?: return false
breakpointChangeListener?.onBreakpointChange(line, false) breakpointChangeListener?.onBreakpointChange(line, false)
@@ -807,9 +790,6 @@ class CodeEditText : AppCompatEditText {
} }
companion object { companion object {
const val TAG = "CodeEditText" const val TAG = "CodeEditText"
} }
} }

View File

@@ -2,15 +2,14 @@ package org.autojs.autojs.ui.edit.keyboard
import android.content.Context import android.content.Context
import android.content.SharedPreferences import android.content.SharedPreferences
import android.content.res.Configuration import androidx.core.content.edit
import org.autojs.autojs.core.pref.Language import org.autojs.autojs.core.pref.Language
import org.autojs.autojs.util.LocaleUtils import org.autojs.autojs.util.LocaleUtils
import org.autojs.autojs.util.StringUtils
import org.autojs.autojs6.R import org.autojs.autojs6.R
import org.json.JSONArray import org.json.JSONArray
import org.json.JSONObject import org.json.JSONObject
import java.util.Locale
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
import androidx.core.content.edit
/** /**
* Symbol profiles store for editor symbol bar. * Symbol profiles store for editor symbol bar.
@@ -235,7 +234,7 @@ object SymbolsConfigStore {
Language.values().forEach { lang -> Language.values().forEach { lang ->
if (lang == Language.AUTO) return@forEach if (lang == Language.AUTO) return@forEach
val s = getStringForLocale(context, lang.locale, R.string.text_symbols_profile_default_name) val s = StringUtils.getStringForLocale(context, lang.locale, R.string.text_symbols_profile_default_name)
.trim() .trim()
if (s.isNotBlank()) add(s) if (s.isNotBlank()) add(s)
} }
@@ -253,13 +252,6 @@ object SymbolsConfigStore {
return getAllDefaultNameAliases(context).any { it == n } return getAllDefaultNameAliases(context).any { it == n }
} }
private fun getStringForLocale(context: Context, locale: Locale, resId: Int): String {
val cfg = Configuration(context.resources.configuration)
cfg.setLocale(locale)
val localized = context.createConfigurationContext(cfg)
return localized.resources.getString(resId)
}
private fun readRootOrCreate(context: Context): JSONObject { private fun readRootOrCreate(context: Context): JSONObject {
val sp = prefs(context) val sp = prefs(context)
val raw = sp.getString(KEY_PROFILES_JSON, null) val raw = sp.getString(KEY_PROFILES_JSON, null)

View File

@@ -1,7 +1,9 @@
package org.autojs.autojs.util package org.autojs.autojs.util
import android.content.Context
import android.content.res.Configuration import android.content.res.Configuration
import android.text.TextUtils import android.text.TextUtils
import androidx.annotation.StringRes
import androidx.core.net.toUri import androidx.core.net.toUri
import com.ibm.icu.text.CharsetDetector import com.ibm.icu.text.CharsetDetector
import com.ibm.icu.text.CharsetMatch import com.ibm.icu.text.CharsetMatch
@@ -372,6 +374,14 @@ object StringUtils {
return if (isDir) "$noTail/" else noTail return if (isDir) "$noTail/" else noTail
} }
@JvmStatic
fun getStringForLocale(context: Context, locale: Locale, @StringRes resId: Int): String {
val cfg = Configuration(context.resources.configuration)
cfg.setLocale(locale)
val localized = context.createConfigurationContext(cfg)
return localized.resources.getString(resId)
}
class CharsetMatchWrapper(private val charsetMatch: CharsetMatch?) { class CharsetMatchWrapper(private val charsetMatch: CharsetMatch?) {
val name: String? by lazy { charsetMatch?.name } val name: String? by lazy { charsetMatch?.name }

View File

@@ -7,6 +7,8 @@ import android.os.Looper
import android.util.Log import android.util.Log
import org.autojs.plugin.paddle.ocr.api.OcrOptions import org.autojs.plugin.paddle.ocr.api.OcrOptions
import org.autojs.plugin.paddle.ocr.api.OcrResult import org.autojs.plugin.paddle.ocr.api.OcrResult
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
/** /**
* Native bridge based on com.baidu.paddle.lite.ocr.Predictor. * Native bridge based on com.baidu.paddle.lite.ocr.Predictor.
@@ -37,37 +39,28 @@ class PredictorNativeBridge : NativeBridge {
// Predictor.init() may do heavy work and should not block main thread. // Predictor.init() may do heavy work and should not block main thread.
// zh-CN: Predictor.init() 可能较耗时, 不应阻塞主线程. // zh-CN: Predictor.init() 可能较耗时, 不应阻塞主线程.
val ok = if (Looper.getMainLooper() == Looper.myLooper()) { val ok = if (Looper.getMainLooper() == Looper.myLooper()) {
val lock = Object() val latch = CountDownLatch(1)
val completed = booleanArrayOf(false)
val initResult = booleanArrayOf(false) val initResult = booleanArrayOf(false)
Thread { Thread {
initResult[0] = initInternal(context, profile) initResult[0] = initInternal(context, profile)
synchronized(lock) { latch.countDown()
completed[0] = true
lock.notifyAll()
}
}.start() }.start()
val deadline = System.currentTimeMillis() + 60_000
var interrupted = false var interrupted = false
synchronized(lock) { try {
try { val completed = latch.await(60, TimeUnit.SECONDS)
while (!completed[0]) { if (!completed) {
val remaining = deadline - System.currentTimeMillis() interrupted = false
if (remaining <= 0) break
lock.wait(remaining)
}
} catch (_: InterruptedException) {
Thread.currentThread().interrupt()
interrupted = true
} }
} catch (_: InterruptedException) {
Thread.currentThread().interrupt()
interrupted = true
} }
!interrupted && completed[0] && initResult[0] !interrupted && latch.count == 0L && initResult[0]
} else { } else {
initInternal(context, profile) initInternal(context, profile)
} }
if (!ok) { if (!ok) {
throw IllegalStateException(context.getString(R.string.error_failed_to_initialize_paddle_ocr_predictor)) throw IllegalStateException(context.getString(R.string.error_failed_to_initialize_paddle_ocr_predictor))
} }