6.3.4 Alpha2 - 新增 Paddle Lite / WebSocket; 修复屏幕旋转浮动按钮异常; 优化日志复制与导出

This commit is contained in:
SuperMonster003
2023-10-03 18:08:36 +08:00
parent 4674f94520
commit 4481f539f9
164 changed files with 3149 additions and 1428 deletions

View File

@@ -6,9 +6,42 @@
# v6.3.4
###### 2023/07/25
###### 2023/10/03
* `新增` ocr 模块支持 Paddle Lite 引擎 (by [TonyJiangWJ](https://github.com/TonyJiangWJ)) _[`pr #120`](http://pr.autojs6.com/120)_
* `新增` WebSocket 模块 (参阅 项目文档 > [颜色类](https://docs.autojs6.com/#/webSocketType))
* `新增` device.rotation / device.orientation 等方法
* `新增` 内部 Java 类支持 class 静态属性访问
* `修复` VSCode 插件保存文件到本地时文件扩展名信息丢失的问题
* `修复` 使用协程特性运行项目产生未捕获异常致使应用崩溃的问题
* `修复` 重启或退出应用时浮动按钮无法记录其位置状态信息的问题
* `修复` 设备屏幕方向改变时无法获取更新后的设备配置信息的问题
* `修复` 屏幕旋转至横向时 Toolbar 标题字体过小的问题
* `修复` 屏幕旋转至横向时应用主页的页签排版过于拥挤的问题
* `修复` 屏幕旋转至横向时浮动按钮可能溢出屏幕的问题 _[`issue #90`](http://issues.autojs6.com/90)_
* `修复` 屏幕多次旋转时无法恢复浮动按钮的坐标及屏幕侧边方向的问题
* `修复` 消息浮动框在多个脚本同时运行时可能存在被遮蔽的问题 _[`issue #67`](http://issues.autojs6.com/67)_
* `修复` 使用广播分析布局时点击布局无法弹出菜单且导致应用崩溃的问题
* `修复` 第二次及以后创建的 WebSocket 实例均无法正常触发监听器的问题
* `修复` 重新合并部分 PR (by [aiselp](https://github.com/aiselp)) 以解决部分脚本无法正常结束运行的问题 _[`pr #75`](http://pr.autojs6.com/75)_ _[`pr #78`](http://pr.autojs6.com/78)_
* `修复` 撤销 importPackage 的全局重定向方法以避免某些作用域下的包导入异常 _[`issue #88`](http://issues.autojs6.com/88)_
* `修复` 日志活动页面使用复制或导出功能时可能导致应用崩溃的问题
* `优化` 日志活动页面导出功能重命名为发送功能并重新实现符合实际意义的导出功能
* `优化` 日志活动页面发送功能支持条目数量过大时自动截取并作出提示
* `优化` ocr 模块同时兼容 Google MLKit 及 Paddle Lite 引擎 (参阅 项目文档 > [光学字符识别](https://docs.autojs6.com/#/ocr?id=p-mode))
* `优化` 提升无障碍服务自动启动的成功概率
* `优化` 构建工具自适应 Java 发行版本以尽量避免 "无效的发行版本" 问题
* `优化` 部分 Kotlin 注解处理由 kapt 迁移至 KSP
* `优化` 附加 Rikka Shizuku 版本 13.1.5
* `优化` 升级 Gradle Compile 版本 33 -> 34
* `优化` 升级 Gradle 版本 8.3-rc-1 -> 8.4-rc-3
* `优化` 升级 Apache Commons Lang3 版本 3.12.0 -> 3.13.0
* `优化` 升级 Glide 版本 4.15.1 -> 4.16.0
* `优化` 升级 Android Analytics 版本 14.3.0 -> 14.4.0
* `优化` 升级 Androidx WebKit 版本 1.7.0 -> 1.8.0
* `优化` 升级 Androidx Preference 版本 1.2.0 -> 1.2.1
* `优化` 升级 Androidx Annotation 版本 1.6.0 -> 1.7.0
* `优化` 升级 Androidx Recyclerview 版本 1.3.0 -> 1.3.1
# v6.3.3
@@ -62,7 +95,7 @@
* `优化` 服务端模式开启后保持常开状态 (除非手动关闭或应用进程结束) _[`issue #64`](http://issues.autojs6.com/64#issuecomment-1596990158)_
* `优化` 实现 AutoJs6 与 VSCode 插件的双向版本检测并提示异常检测结果 _[`issue #89`](http://issues.autojs6.com/89)_
* `优化` 增加短信数据读取权限 (android.permission.READ_SMS) (默认关闭)
* `优化` findMultiColors 方法内部实现 (by [LYS](https://github.com/LYS86)) _[`pr #72`](http://pr.autojs6.com/72)_
* `优化` findMultiColors 方法内部实现 (by [LYS86](https://github.com/LYS86)) _[`pr #72`](http://pr.autojs6.com/72)_
* `优化` runtime.loadDex/loadJar/load 支持按目录级别加载或同时加载多个文件
* `优化` 升级 Leakcanary 版本 2.11 -> 2.12
* `优化` 升级 Android Analytics 版本 14.2.0 -> 14.3.0
@@ -166,7 +199,7 @@
* `优化` 升级 Zip4j 版本 2.11.2 -> 2.11.5
* `优化` 升级 Junit 版本 5.9.2 -> 5.9.3
* `优化` 升级 Androidx Annotation 版本 1.5.0 -> 1.6.0
* `优化` 升级 Jackson Databind 版本 2.14.1 -> 2.14.2
* `优化` 升级 Jackson DataBind 版本 2.14.1 -> 2.14.2
* `优化` 升级 Desugar JDK Libs 版本 2.0.0 -> 2.0.3
# v6.2.0

View File

@@ -278,7 +278,7 @@
<h3>OCR 特性<span><a class="mark" href="#qa_ocr" id="qa_ocr">#</a></span></h3>
<p>AutoJs6 的 OCR 特性是基于 <a href="https://developers.google.com/ml-kit?hl=zh-cn">Google ML Kit</a> 的 <a href="https://developers.google.com/ml-kit/vision/text-recognition/android?hl=zh-cn">文字识别 API</a> 实现的.</p>
<blockquote>
<p>注: AutoJs6 的 <a href="http://project.autojs6.com/blob/master/app/src/main/java/org/autojs/autojs/runtime/api/MlKitOCR.kt">OCR 实现源码</a> 参考自 <a href="https://github.com/TonyJiangWJ">TonyJiangWJ</a> 的 <a href="https://github.com/TonyJiangWJ/Auto.js">开源项目</a>.</p>
<p>注: AutoJs6 的 <a href="http://project.autojs6.com/blob/master/app/src/main/java/org/autojs/autojs/runtime/api/OcrMLKit.kt">OCR 实现源码</a> 参考自 <a href="https://github.com/TonyJiangWJ">TonyJiangWJ</a> 的 <a href="https://github.com/TonyJiangWJ/Auto.js">开源项目</a>.</p>
</blockquote>
<blockquote>
<p>参阅: <a href="ocr.html">光学字符识别 (OCR)</a> 模块</p>

View File

@@ -23,6 +23,7 @@ let Crypto = org.autojs.autojs.core.crypto.Crypto;
let Image = org.autojs.autojs.core.image.ImageWrapper;
let ColorTable = org.autojs.autojs.core.image.ColorTable;
let Canvas = org.autojs.autojs.core.graphics.ScriptCanvas;
let EventEmitter = org.autojs.autojs.core.eventloop.EventEmitter;
let UiObject = org.autojs.autojs.core.automator.UiObject;
let UiObjectCollection = org.autojs.autojs.core.automator.UiObjectCollection;
let ImageWrapper = org.autojs.autojs.core.image.ImageWrapper;
@@ -33,6 +34,7 @@ let OkHttpClient = Packages.okhttp3.OkHttpClient;
let ScriptInterruptedException = org.autojs.autojs.runtime.exception.ScriptInterruptedException;
let ReentrantLock = java.util.concurrent.locks.ReentrantLock;
let ScreenMetrics = org.autojs.autojs.runtime.api.ScreenMetrics;
let ScriptRuntime = org.autojs.autojs.runtime.ScriptRuntime;
let StandardCharsets = java.nio.charset.StandardCharsets;
let WebView = android.webkit.WebView;
let WebViewClient = android.webkit.WebViewClient;
@@ -93,13 +95,6 @@ let JsWebView = org.autojs.autojs.core.ui.widget.JsWebView;
/* Global assignment. */
Object.assign(this, {
io: Packages.io,
okio: Packages.okio,
de: Packages.de,
ezy: Packages.ezy,
kotlin: Packages.kotlin,
okhttp3: Packages.okhttp3,
androidx: Packages.androidx,
isNullish(o) {
// nullish coalescing operator: ??
return o === null || o === undefined;
@@ -358,15 +353,29 @@ Object.assign(this, {
__importClass__(typeof clazz === 'string' ? Packages[clazz] : clazz);
});
},
// 重定向 importPackage 使其支持字符串参数.
/**
* @global
*/
importPackage() {
Array.from(arguments).forEach(pkg => {
__importPackage__(typeof pkg === 'string' ? Packages[pkg] : pkg);
});
},
// FIXME by SuperMonster003 on Jul 27, 2023.
// ! This makes importPackage() behave abnormally
// ! when calling it in a JavaScript module,
// ! even with "with" scope binding expression.
// !
// // 重定向 importPackage 使其支持字符串参数.
// /**
// * @global
// */
// importPackage() {
// let args = Array.from(arguments);
// let expression =
// 'args.forEach((pkg) => {' + '\n' +
// ' __importPackage__(typeof pkg === \'string\' ? Packages[pkg] : pkg);' + '\n' +
// '});';
// // @ScopeBinding
// // noinspection WithStatementJS
// with (context) {
// return (/* @IIFE */ function () {
// return eval(expression);
// })();
// }
// },
/**
* @global
*/
@@ -485,7 +494,7 @@ Object.assign(this, {
/* ! ocr < images */
/* ! ocr < files */
[ 'ocr', 'paddle_ocr' ],
[ 'ocr' ],
/* Safe to put last regardless of the order, no guarantee ;). */
[ 'floaty', 'storages', 'device', 'recorder', 'toast' ],
@@ -498,7 +507,7 @@ Object.assign(this, {
bindPrologue() {
// 重定向 require 以支持相对路径和 npm 模块.
global.Module = require('jvm-npm');
global.require = id => Module.require(id);
global.require = Module.require;
global.i18n.loadAll();
global.i18n.setLocale('default');

View File

@@ -3,7 +3,7 @@
let { util, plugins } = global;
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Arrayx}
*/

View File

@@ -3,7 +3,7 @@
let { plugins, Arrayx, Numberx } = global;
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Mathx}
*/
@@ -14,7 +14,7 @@ module.exports = (scriptRuntime, scope) => {
* @implements Internal.Mathx
*/
const MathxCtor = function () {
// Empty interface body.
/* Empty body. */
};
MathxCtor.prototype = {

View File

@@ -3,7 +3,7 @@
let { util, plugins } = global;
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Numberx}
*/

View File

@@ -3,7 +3,7 @@
let { autojs } = global;
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.RootAutomator}
*/

View File

@@ -5,7 +5,7 @@
let { autojs, shell, files, util } = global;
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.App}
*/
@@ -30,7 +30,7 @@ module.exports = function (scriptRuntime, scope) {
* @extends Internal.App
*/
const App = function () {
// Empty interface body.
/* Empty body. */
};
App.prototype = {

View File

@@ -5,7 +5,7 @@
let { util } = global;
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Autojs}
*/
@@ -24,7 +24,7 @@ module.exports = function (scriptRuntime, scope) {
* @implements Internal.Autojs
*/
const Autojs = function () {
// Empty interface body.
/* Empty body. */
};
Autojs.prototype = {
@@ -54,6 +54,18 @@ module.exports = function (scriptRuntime, scope) {
},
R: global.R,
name: context.getString(R.strings.app_name),
get rotation() {
return ScreenMetrics.getRotation();
},
get orientation() {
return ScreenMetrics.getOrientation();
},
isScreenPortrait() {
return ScreenMetrics.isScreenPortrait();
},
isScreenLandscape() {
return ScreenMetrics.isScreenLandscape();
},
isRootAvailable() {
return RootUtils.isRootAvailable();
},

View File

@@ -5,7 +5,7 @@
let { util } = global;
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Automator}
*/
@@ -136,8 +136,8 @@ module.exports = function (scriptRuntime, scope) {
gestureAsync(duration, points) {
return rtAutomator.gestureAsync.apply(rtAutomator, [ 0 ].concat(Array.from(arguments)));
},
swipe(x1, y1, x2, y2, delay) {
return rtAutomator.swipe(x1, y1, x2, y2, delay);
swipe(x1, y1, x2, y2, duration) {
return rtAutomator.swipe(x1, y1, x2, y2, duration);
},
isServiceRunning() {
return rtAutomator.isServiceRunning();

View File

@@ -1,5 +1,5 @@
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Base64}
*/
@@ -11,7 +11,7 @@ module.exports = function (scriptRuntime, scope) {
* @implements Internal.Base64
*/
const Base64Ctor = function () {
// Empty interface body.
/* Empty body. */
};
Base64Ctor.prototype = {

View File

@@ -5,7 +5,7 @@
let { util } = global;
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Colors}
*/
@@ -63,10 +63,10 @@ module.exports = function (scriptRuntime, scope) {
Color.prototype = {
constructor: Color,
toString() {
return this.digest();
return this.summary();
},
digest() {
return colors.digest.apply(colors, [ this.color ].concat(Array.from(arguments)));
summary() {
return colors.summary.apply(colors, [ this.color ].concat(Array.from(arguments)));
},
toHex() {
return colors.toHex.apply(colors, [ this.color ].concat(Array.from(arguments)));
@@ -250,7 +250,7 @@ module.exports = function (scriptRuntime, scope) {
* @extends Internal.Colors
*/
const Colors = function () {
// Empty class body.
/* Empty body. */
};
Colors.prototype = {
@@ -666,7 +666,7 @@ module.exports = function (scriptRuntime, scope) {
let args = [ _.Color ].concat(Array.from(arguments));
return new (Function.prototype.bind.apply(_.Color, args));
},
digest(color) {
summary(color) {
let [ r, g, b, a ] = this.toRgba(color);
let niceA = _.toDoubleComponent(a).toFixed(2).replace(/0$/, '');
return `hex(${this.toHex(color)}), rgba(${r},${g},${b}/${niceA}), int(${this.toInt(color)})`;

View File

@@ -4,7 +4,7 @@
let { files, util, s13n } = global;
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Console}
*/
@@ -27,7 +27,7 @@ module.exports = function (scriptRuntime, scope) {
* @extends Internal.Console
*/
const Console = function () {
// Empty interface body.
/* Empty body. */
};
Console.prototype = {

View File

@@ -3,7 +3,7 @@
let { engines, global: _global } = global;
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Continuation}
*/
@@ -41,7 +41,13 @@ module.exports = function (scriptRuntime, scope) {
*/
let result = this.cont.suspend();
if (result.error !== null) {
throw result.error;
// throw result.error;
if (typeof result.error.message === 'string') {
ScriptRuntime.popException(result.error.message);
} else {
ScriptRuntime.popException(String(result.error));
}
return result.error;
}
return result.result;
},
@@ -64,7 +70,7 @@ module.exports = function (scriptRuntime, scope) {
*/
const Continuation = function () {
return Object.assign(function () {
// Empty interface body.
/* Empty body. */
}, Continuation.prototype);
};
@@ -97,7 +103,7 @@ module.exports = function (scriptRuntime, scope) {
* @implements Internal.Continuation.PromiseExtension
*/
const PromiseExtension = function () {
// Empty interface body.
/* Empty body. */
};
Object.assign(PromiseExtension.prototype, {

View File

@@ -3,12 +3,11 @@
let { util } = global;
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Device}
*/
module.exports = function (scriptRuntime, scope) {
const ScreenMetrics = org.autojs.autojs.runtime.api.ScreenMetrics;
const NetworkUtils = org.autojs.autojs.util.NetworkUtils;
const DeviceUtils = org.autojs.autojs.util.DeviceUtils;
@@ -20,7 +19,7 @@ module.exports = function (scriptRuntime, scope) {
* @extends Internal.Device
*/
const Device = function () {
// Empty interface body.
/* Empty body. */
};
Device.prototype = {
@@ -32,7 +31,10 @@ module.exports = function (scriptRuntime, scope) {
return ScreenMetrics.getDeviceScreenHeight();
},
get rotation() {
return ScreenMetrics.getRotation();
return rtDevice.getRotation();
},
get orientation() {
return rtDevice.getOrientation();
},
get density() {
return ScreenMetrics.getDeviceScreenDensity();
@@ -63,6 +65,12 @@ module.exports = function (scriptRuntime, scope) {
isScreenOff() {
return !rtDevice.isScreenOn();
},
isScreenPortrait() {
return rtDevice.isScreenPortrait();
},
isScreenLandscape() {
return rtDevice.isScreenLandscape();
},
getIpAddress(useIPv4) {
return useIPv4 === undefined
? NetworkUtils.getIpAddress()

View File

@@ -3,7 +3,7 @@
let { colors, threads, ui } = global;
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Dialogs}
*/
@@ -19,7 +19,7 @@ module.exports = function (scriptRuntime, scope) {
* @implements Internal.Dialogs
*/
const Dialogs = function () {
// Empty interface body.
/* Empty body. */
};
Dialogs.prototype = {

View File

@@ -3,7 +3,7 @@
let { files } = global;
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Engines}
*/
@@ -18,7 +18,7 @@ module.exports = function (scriptRuntime, scope) {
* @extends Internal.Engines
*/
const Engines = function () {
// Empty class body.
/* Empty body. */
};
Engines.prototype = {

View File

@@ -1,7 +1,7 @@
// noinspection JSUnusedGlobalSymbols
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Events}
*/
@@ -12,7 +12,7 @@ module.exports = function (scriptRuntime, scope) {
* @extends Internal.Events
*/
const Events = function () {
// Empty class body.
/* Empty body. */
};
Events.prototype = {
@@ -37,7 +37,7 @@ module.exports = function (scriptRuntime, scope) {
* @implements Internal.Keys
*/
const Keys = function () {
// Empty interface body.
/* Empty body. */
};
Keys.prototype = {

View File

@@ -1,5 +1,5 @@
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Files}
*/
@@ -12,7 +12,7 @@ module.exports = function (scriptRuntime, scope) {
* @extends Internal.Files
*/
const Files = function () {
// Empty class body.
/* Empty body. */
};
Files.prototype = {

View File

@@ -1,5 +1,7 @@
// noinspection UnnecessaryLocalVariableJS
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Floaty}
*/
@@ -12,7 +14,7 @@ module.exports = function (scriptRuntime, scope) {
* @implements Internal.Floaty
*/
const Floaty = function () {
// Empty interface body.
/* Empty body. */
};
Floaty.prototype = {
@@ -28,6 +30,7 @@ module.exports = function (scriptRuntime, scope) {
},
hasPermission: () => rtFloaty.hasPermission(),
requestPermission: () => rtFloaty.requestPermission(),
ensurePermission: () => rtFloaty.ensurePermission(),
};
return Floaty;

View File

@@ -7,8 +7,6 @@ let { autojs, console, device, pickup, ui, s13n, Numberx } = global;
/* Here, importClass() is not recommended for intelligent code completion in IDE like WebStorm. */
/* The same is true of destructuring assignment syntax (like `let {Uri} = android.net`). */
let ScriptRuntime = org.autojs.autojs.runtime.ScriptRuntime;
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} runtime
* @param {org.mozilla.javascript.Scriptable | global} scope

View File

@@ -5,7 +5,7 @@
let { ui } = global;
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Http}
*/
@@ -26,7 +26,7 @@ module.exports = function (scriptRuntime, scope) {
* @implements Internal.Http
*/
const Http = function () {
// Empty interface body.
/* Empty body. */
};
Http.prototype = {

View File

@@ -5,7 +5,7 @@
let { files } = global;
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.I18n}
*/

View File

@@ -5,7 +5,7 @@
let { files, util, ui, threads } = global;
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Images}
*/
@@ -42,7 +42,7 @@ module.exports = function (scriptRuntime, scope) {
*/
const Images = function () {
return Object.assign(function () {
// Empty interface body.
/* Empty body. */
}, Images.prototype);
};
@@ -577,19 +577,23 @@ module.exports = function (scriptRuntime, scope) {
};
/**
* @class
* @extends Images.MatchingResult
* @param {Images.TemplateMatch[] | java.lang.Iterable<Images.TemplateMatch>} list
*/
const MatchingResult = function (list) {
Object.defineProperties(this, {
matches: {
value: Array.isArray(list) ? list : scriptRuntime.bridges.getBridges().toArray(list),
enumerable: true,
},
points: {
get() {
return this.matches.map(m => m.point);
},
enumerable: false,
Object.assign(this, {
matches: (() => {
if (Array.isArray(list)) {
return list;
}
// noinspection UnnecessaryLocalVariableJS
/** @type Images.TemplateMatch[] */
let results = scriptRuntime.bridges.getBridges().toArray(list);
return results;
})(),
get points() {
return this.matches.map(m => m.point);
},
});
};
@@ -606,6 +610,9 @@ module.exports = function (scriptRuntime, scope) {
if (!this.matches.length) {
return null;
}
/**
* @type Images.TemplateMatch
*/
let target = this.matches[0];
this.matches.forEach(m => target = compareFn(target, m) > 0 ? m : target);
return target;

View File

@@ -1,5 +1,5 @@
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Media}
*/
@@ -10,7 +10,7 @@ module.exports = function (scriptRuntime, scope) {
* @extends Internal.Media
*/
const Media = function () {
// Empty interface body.
/* Empty body. */
};
Media.prototype = {

View File

@@ -1,7 +1,7 @@
// noinspection JSUnusedLocalSymbols,UnnecessaryLocalVariableJS
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Notice}
*/
@@ -47,7 +47,7 @@ module.exports = function (scriptRuntime, scope) {
* @implements {Notice.Config}
*/
const Config = function () {
// Empty interface body.
/* Empty body. */
};
Config.prototype = {
@@ -86,7 +86,7 @@ module.exports = function (scriptRuntime, scope) {
* @implements {Notice.Channel}
*/
const Channel = function () {
// Empty interface body.
/* Empty body. */
};
Channel.prototype = {

View File

@@ -1,95 +1,228 @@
// noinspection UnnecessaryLocalVariableJS,JSUnusedLocalSymbols
// noinspection JSUnusedLocalSymbols
/* Overwritten protection. */
let { images, files } = global;
let { images } = global;
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Ocr}
*/
module.exports = function (scriptRuntime, scope) {
const rtOcr = scriptRuntime.mlKitOCR;
let _ = {
OcrCtor: (/* @IIFE */ () => {
/**
* @type {{[modeName in Internal.Ocr.ModeName]: Internal.Ocr.ModeName}}
*/
const modeName = {
mlkit: 'mlkit',
paddle: 'paddle',
unknown: 'unknown',
};
/**
* @type {Internal.Ocr.ModeName}
*/
let _mode = modeName.unknown;
const defaultPrivateDescriptor = {
configurable: false,
writable: false,
enumerable: false,
};
const defaultProtectedDescriptor = {
configurable: false,
writable: false,
enumerable: true, /* Emphasis. */
};
const instanceFunc = function (img, options) {
if (typeof arguments[0] === 'string') {
let img = images.read(/* path = */ arguments[0]);
if (img === null) {
throw TypeError(`Invalid image of path "${arguments[0]}" for ocr(img, options?)`);
}
return OcrCtor.prototype.recognizeText(img.oneShot(), options);
}
return OcrCtor.prototype.recognizeText.apply(OcrCtor.prototype, arguments);
};
/**
* @implements Internal.Ocr
*/
const OcrCtor = function () {
/** @global */
const ocr = function (img, options) {
if (typeof arguments[0] === 'string') {
let img = images.read(/* path = */ arguments[0]);
if (img === null) {
throw TypeError(`Invalid image of path "${arguments[0]}" for ocr(img, options?)`);
}
return OcrCtor.prototype.recognizeText(img.oneShot(), options);
}
return OcrCtor.prototype.recognizeText.apply(OcrCtor.prototype, arguments);
};
return Object.assign(ocr, OcrCtor.prototype);
let o = Object.assign(instanceFunc, OcrCtor.prototype);
Object.defineProperties(instanceFunc, Object.getOwnPropertyDescriptors(OcrCtor.prototype));
return o;
};
OcrCtor.prototype = {
constructor: OcrCtor,
recognizeText(img, options) {
_modeName: modeName,
_forcibleModeArgIndex: 10,
mlkit: require('ocr-mlkit')(scriptRuntime, scope),
paddle: require('ocr-paddle')(scriptRuntime, scope),
get mode() {
return _mode;
},
set mode(mode) {
this.tap(mode);
},
tap(mode) {
if (mode === this.mlkit || String(mode).toLowerCase() === modeName.mlkit) {
_mode = modeName.mlkit;
} else if (mode === this.paddle || String(mode).toLowerCase() === modeName.paddle) {
_mode = modeName.paddle;
} else {
_mode = modeName.unknown;
throw TypeError(`Unknown mode (value: ${mode}, species: ${species(mode)}) for ocr.tap(mode)`);
}
},
recognizeText() {
if (typeof arguments[0] === 'string') {
// @Signature
// recognizeText(imgPath: string, options?: DetectOptionsMLKit | DetectOptionsPaddle): string[];
// recognizeText(imgPath: string, region: Images.Options.Region): string[];
let img = images.read(/* path = */ arguments[0]);
if (img === null) {
throw TypeError(`Invalid image of path "${arguments[0]}" for ocr.recognizeText(img, options?)`);
}
return this.recognizeText(img.oneShot(), options);
// @Overload
// recognizeText(img: ImageWrapper, options?: DetectOptionsMLKit | DetectOptionsPaddle): string[];
// recognizeText(img: ImageWrapper, region: Images.Options.Region): string[];
return this.recognizeText(img.oneShot(), arguments[1]);
}
if (_.shouldTakenAsRegion(arguments[1])) {
// @Signature recognizeText(img: ImageWrapper, region: Images.Options.Region): string[];
// @Overload recognizeText(img: ImageWrapper, options: DetectOptionsMLKit | DetectOptionsPaddle): string[];
return this.recognizeText(img, { region: arguments[1] });
}
let opt = options || {};
// @Signature recognizeText(img: ImageWrapper, options?: DetectOptionsMLKit | DetectOptionsPaddle): string[];
/** @type {Internal.Ocr.DetectOptions} */
let opt = /* options */ arguments[1] || {};
let region = opt.region;
if (region === null) {
return [];
}
if (region === undefined) {
return Array.from(rtOcr.recognizeText(img));
/** @type Internal.Ocr.RecognizeTextMethod */
let recognizeTextMethod;
switch (arguments[OcrCtor.prototype._forcibleModeArgIndex] || _mode) {
case modeName.mlkit:
recognizeTextMethod = this.mlkit.recognizeTextMethodCreator(opt);
break;
case modeName.paddle:
recognizeTextMethod = this.paddle.recognizeTextMethodCreator(opt);
break;
default:
throw TypeError(`Can't call ocr.recognizeText with an unknown mode (value: ${_mode}, species: ${species(_mode)})`);
}
let results = Array.from(rtOcr.recognizeText(images.clip(img, region).oneShot()));
let img = arguments[0];
if (region === undefined) {
return recognizeTextMethod(img);
}
let results = recognizeTextMethod(
images.clip(img, region).oneShot(),
);
img.shoot();
return results;
},
detect(img, options) {
detect() {
if (typeof arguments[0] === 'string') {
// @Signature
// detect(imgPath: string, options?: DetectOptionsMLKit | DetectOptionsPaddle): org.autojs.autojs.runtime.api.OcrResult[];
// detect(imgPath: string, region: Images.Options.Region): org.autojs.autojs.runtime.api.OcrResult[];
let img = images.read(/* path = */ arguments[0]);
if (img === null) {
throw TypeError(`Invalid image of path "${arguments[0]}" for ocr.detect(img, options?)`);
}
return this.detect(img.oneShot(), options);
// @Overload
// detect(img: ImageWrapper, options?: DetectOptionsMLKit | DetectOptionsPaddle): org.autojs.autojs.runtime.api.OcrResult[];
// detect(img: ImageWrapper, region: Images.Options.Region): org.autojs.autojs.runtime.api.OcrResult[];
return this.detect(img.oneShot(), arguments[1]);
}
if (_.shouldTakenAsRegion(arguments[1])) {
// @Signature detect(img: ImageWrapper, region: Images.Options.Region): org.autojs.autojs.runtime.api.OcrResult[];
// @Overload detect(img: ImageWrapper, options: DetectOptionsMLKit | DetectOptionsPaddle): org.autojs.autojs.runtime.api.OcrResult[];
return this.detect(img, { region: arguments[1] });
}
let opt = options || {};
// @Signature detect(img: ImageWrapper, options?: DetectOptionsMLKit | DetectOptionsPaddle): org.autojs.autojs.runtime.api.OcrResult[];
let opt = /* options */ arguments[1] || {};
let region = opt.region;
if (region === null) {
return [];
}
/**
* @type {org.autojs.autojs.runtime.api.OcrResult[]}
*/
let resultList = rtOcr.detect(region !== undefined ? images.clip(img, region).oneShot() : img).toArray();
if (!isNullish(region)) {
resultList.forEach((result) => {
let rect = images.buildRegion(img, region);
result.bounds.offset(rect.x, rect.y);
});
/** type {Internal.Ocr.DetectMethod} */
let detectMethod;
switch (_mode) {
case modeName.mlkit:
detectMethod = this.mlkit.detectMethodCreator(opt);
break;
case modeName.paddle:
detectMethod = this.paddle.detectMethodCreator(opt);
break;
default:
throw TypeError(`Can't call ocr.detect with an unknown mode (value: ${_mode}, species: ${species(_mode)})`);
}
return Array.from(resultList);
let img = arguments[0];
if (region === undefined) {
return detectMethod(img);
}
let results = detectMethod(images.clip(img, region).oneShot());
results.forEach((result) => {
let rect = images.buildRegion(img, region);
result.bounds.offset(rect.x, rect.y);
});
img.shoot();
return results;
},
summary() {
return [
`[ OCR summary ]`,
`Current mode: ${this.mode}`,
`Available modes: [ ${Object.values(modeName).filter(n => n !== modeName.unknown).join(', ')} ]`,
].join('\n');
},
toString() {
return this.summary();
},
};
/* Set prototype descriptors. */
Object.defineProperties(OcrCtor.prototype, {
_modeName: defaultPrivateDescriptor,
_forcibleModeArgIndex: defaultPrivateDescriptor,
mode: { configurable: false },
constructor: defaultProtectedDescriptor,
mlkit: defaultProtectedDescriptor,
paddle: defaultProtectedDescriptor,
tap: defaultProtectedDescriptor,
summary: defaultProtectedDescriptor,
toString: defaultProtectedDescriptor,
});
return OcrCtor;
})(),
shouldTakenAsRegion(o) {
@@ -104,5 +237,8 @@ module.exports = function (scriptRuntime, scope) {
*/
const ocr = new _.OcrCtor();
/* Init OCR mode with MLKit. */
ocr.mode = 'mlkit';
return ocr;
};

View File

@@ -1,120 +0,0 @@
// noinspection UnnecessaryLocalVariableJS,JSUnusedLocalSymbols
/* Overwritten protection. */
let { images } = global;
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Ocr}
*/
module.exports = function (scriptRuntime, scope) {
const rtOcr = scriptRuntime.paddleOCR;
let _ = {
OcrCtor: (/* @IIFE */ () => {
/**
* @implements Internal.Ocr
*/
const OcrCtor = function () {
/** @global */
const ocr = function (img, options) {
if (typeof arguments[0] === 'string') {
let img = images.read(/* path = */ arguments[0]);
if (img === null) {
throw TypeError(`Invalid image of path "${arguments[0]}" for ocr(img, options?)`);
}
return OcrCtor.prototype.recognizeText(img.oneShot(), options);
}
return OcrCtor.prototype.recognizeText.apply(OcrCtor.prototype, arguments);
};
return Object.assign(ocr, OcrCtor.prototype);
};
OcrCtor.prototype = {
constructor: OcrCtor,
recognizeText(img, options) {
if (typeof arguments[0] === 'string') {
let img = images.read(/* path = */ arguments[0]);
if (img === null) {
throw TypeError(`Invalid image of path "${arguments[0]}" for ocr.recognizeText(img, options?)`);
}
return this.recognizeText(img.oneShot(), options);
}
if (_.shouldTakenAsRegion(arguments[1])) {
return this.recognizeText(img, { region: arguments[1] });
}
let opt = options || {};
let region = opt.region;
if (region === null) {
return [];
}
let cpuThreadNum = opt.cpuThreadNum || 4
let useSlim = opt.useSlim
if (useSlim === undefined) {
// 默认使用轻量化模型
useSlim = true
}
if (region === undefined) {
return Array.from(rtOcr.recognizeText(img, cpuThreadNum, useSlim));
}
let results = Array.from(rtOcr.recognizeText(images.clip(img, region).oneShot()));
img.shoot();
return results;
},
detect(img, options) {
if (typeof arguments[0] === 'string') {
let img = images.read(/* path = */ arguments[0]);
if (img === null) {
throw TypeError(`Invalid image of path "${arguments[0]}" for ocr.detect(img, options?)`);
}
return this.detect(img.oneShot(), options);
}
if (_.shouldTakenAsRegion(arguments[1])) {
return this.detect(img, { region: arguments[1] });
}
let opt = options || {};
let region = opt.region;
if (region === null) {
return [];
}
let cpuThreadNum = opt.cpuThreadNum || 4
let useSlim = opt.useSlim
if (useSlim === undefined) {
// 默认使用轻量化模型
useSlim = true
}
/**
* @type {org.autojs.autojs.runtime.api.OcrResult[]}
*/
let resultList = rtOcr.detect(region !== undefined ? images.clip(img, region).oneShot() : img, cpuThreadNum, useSlim).toArray();
if (!isNullish(region)) {
resultList.forEach((result) => {
let rect = images.buildRegion(img, region);
result.bounds.offset(rect.x, rect.y);
});
}
return Array.from(resultList);
},
};
return OcrCtor;
})(),
shouldTakenAsRegion(o) {
return o instanceof org.opencv.core.Rect
|| o instanceof android.graphics.Rect
|| Array.isArray(o);
},
};
/**
* @type {Internal.Ocr}
*/
const ocr = new _.OcrCtor();
return ocr;
};

View File

@@ -1,5 +1,5 @@
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Plugins}
*/
@@ -10,7 +10,7 @@ module.exports = function (scriptRuntime, scope) {
* @implements Internal.Plugins
*/
const Plugins = function () {
// Empty interface body.
/* Empty body. */
};
Plugins.prototype = {

View File

@@ -1,7 +1,7 @@
// noinspection JSUnusedGlobalSymbols
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Recorder}
*/

View File

@@ -1,7 +1,7 @@
// noinspection JSUnusedLocalSymbols,UnnecessaryLocalVariableJS
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.S13n}
*/
@@ -12,7 +12,7 @@ module.exports = function (scriptRuntime, scope) {
* @extends Internal.S13n
*/
const S13n = function () {
// Empty interface body.
/* Empty body. */
};
S13n.prototype = {

View File

@@ -5,7 +5,7 @@
let { i18n } = global;
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {() => Internal.Selector}
*/

View File

@@ -1,5 +1,5 @@
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Sensors}
*/
@@ -10,7 +10,7 @@ module.exports = function (scriptRuntime, scope) {
* @extends Internal.Sensors
*/
const Sensors = function () {
// Empty interface body.
/* Empty body. */
};
Sensors.prototype = {

View File

@@ -1,5 +1,5 @@
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Shell}
*/

View File

@@ -1,5 +1,5 @@
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Storages}
*/
@@ -47,7 +47,7 @@ module.exports = function (scriptRuntime, scope) {
* @implements Internal.Storages
*/
const Storage = function () {
// Empty interface body.
/* Empty body. */
};
Storage.prototype = {

View File

@@ -5,7 +5,7 @@
let { ui, threads, files } = global;
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Tasks}
*/
@@ -22,7 +22,7 @@ module.exports = function (scriptRuntime, scope) {
* @implements Internal.Tasks
*/
let Task = function () {
// Empty interface body.
/* Empty body. */
};
Task.prototype = {

View File

@@ -1,7 +1,7 @@
// noinspection NpmUsedModulesInstalled
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Threads}
*/
@@ -18,7 +18,7 @@ module.exports = function (scriptRuntime, scope) {
* @implements Internal.Threads
*/
const Threads = function () {
// Empty interface body.
/* Empty body. */
};
Threads.prototype = {
@@ -73,7 +73,7 @@ module.exports = function (scriptRuntime, scope) {
* @implements Internal.Threads.PromiseExtension
*/
const PromiseExtension = function () {
// Empty interface body.
/* Empty body. */
};
Object.assign(PromiseExtension.prototype, {

View File

@@ -1,5 +1,5 @@
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Timers}
*/
@@ -11,7 +11,7 @@ module.exports = function (scriptRuntime, scope) {
* @implements Internal.Timers
*/
const Timers = function () {
// Empty interface body.
/* Empty body. */
};
Timers.prototype = {

View File

@@ -1,86 +1,26 @@
// noinspection UnnecessaryLocalVariableJS,JSUnusedLocalSymbols
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Toast}
*/
module.exports = function (scriptRuntime, scope) {
let rtToast = scriptRuntime.toast;
let _ = {
uiHandler: runtime.getUiHandler(),
toasts: {
/**
* @type {Set<android.widget.Toast>}
*/
pool: new Set(),
lock: new ReentrantLock(),
add(t) {
if (t instanceof Toast) {
this.lock.lock();
this.pool.add(t);
this.addCallback(t);
this.lock.unlock();
}
},
/**
* @param {android.widget.Toast} t
*/
addCallback(t) {
_.uiHandler.postDelayed(new java.lang.Runnable({
run: () => _.toasts.remove(t),
}), this.getDuration(t) + 1e3 /* As toast may show with some delay. */);
},
remove(t) {
if (this.pool.has(t)) {
this.lock.lock();
this.pool.delete(t);
this.lock.unlock();
}
},
dismissAll() {
if (this.pool.size > 0) {
this.lock.lock();
this.pool.forEach((t) => t.cancel());
this.pool.clear();
this.lock.unlock();
}
},
getDuration(t) {
let du = {
SHORT_DELAY: 2e3,
LONG_DELAY: 3.5e3,
};
switch (t.getDuration()) {
case Toast.LENGTH_SHORT:
return du.SHORT_DELAY;
case Toast.LENGTH_LONG:
return du.LONG_DELAY;
default:
return Math.max.apply(null, Object.values(du));
}
},
},
ToastCtor: (/* @IIFE */ () => {
/**
* @implements Internal.Toast
*/
const ToastCtor = function () {
// @Caution by SuperMonster003 on Oct 11, 2022.
// ! android.widget.Toast.makeText() doesn't work well on Android API Level 28 (Android 9) [P].
// ! There hasn't been a solution for this so far.
// ! Tested devices:
// ! 1. SONY XPERIA XZ1 Compact (G8441)
// ! 2. Android Studio AVD (Android 9.0 x86)
const Ctor = function () {
/** @global */
const toast = function (msg, isLong, isForcible) {
const instance = function (msg, isLong, isForcible) {
let $ = {
rex: {
badge: {
long: /^l(ong)?$/i,
short: /^s(hort)?$/i,
forcible: /^f(orcible)?$/i,
},
toast() {
this.init(arguments);
this.show();
},
init() {
this.message = isNullish(msg) ? '' : String(msg);
this.isForcible = this.parseIsForcible(isForcible);
@@ -94,13 +34,13 @@ module.exports = function (scriptRuntime, scope) {
return Boolean(isLong);
}
if (typeof isLong === 'string') {
if (this.rex.long.test(isLong)) {
if (this.badge.long.test(isLong)) {
return true;
}
if (this.rex.short.test(isLong)) {
if (this.badge.short.test(isLong)) {
return false;
}
if (this.rex.forcible.test(isLong)) {
if (this.badge.forcible.test(isLong)) {
this.isForcible = true;
return false;
}
@@ -116,42 +56,31 @@ module.exports = function (scriptRuntime, scope) {
return Boolean(isForcible);
}
if (typeof isForcible === 'string') {
if (this.rex.forcible.test(isForcible)) {
if (this.badge.forcible.test(isForcible)) {
return true;
}
throw Error(`Invalid param: {name: isForcible, value: ${isForcible}, type: ${species(isForcible)}.`);
}
return false;
},
show() {
_.uiHandler.post(() => {
if ($.isForcible) {
_.toasts.dismissAll();
}
let len = $.isLong ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT;
let o = Toast.makeText(_.uiHandler.getContext(), $.message, len);
_.toasts.add(o);
o.show();
});
makeToast() {
rtToast.makeToast(this.message, this.isLong, this.isForcible);
},
};
$.toast();
$.init();
$.makeToast();
};
return Object.assign(toast, ToastCtor.prototype);
return Object.assign(instance, Ctor.prototype);
};
ToastCtor.prototype = {
constructor: ToastCtor,
dismissAll() {
_.uiHandler.post(() => {
_.toasts.dismissAll();
});
},
Ctor.prototype = {
constructor: Ctor,
dismissAll: () => rtToast.dismissAll(),
};
return ToastCtor;
return Ctor;
})(),
};

View File

@@ -5,7 +5,7 @@
let { files } = global;
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.UI}
*/
@@ -54,7 +54,7 @@ module.exports = function (scriptRuntime, scope) {
* @extends Internal.UI
*/
const UI = function () {
// Empty class body.
/* Empty body. */
};
UI.prototype = {
@@ -67,7 +67,7 @@ module.exports = function (scriptRuntime, scope) {
let Widget = function () {
this.__attrs__ = {};
return Object.assign(function () {
// Empty interface body.
/* Empty body. */
}, Widget.prototype);
};

View File

@@ -22,7 +22,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Util}
*/
@@ -38,7 +38,7 @@ module.exports = function (scriptRuntime, scope) {
* @implements Internal.Util
*/
const Util = function () {
// Empty interface body.
/* Empty body. */
};
Util.prototype = {

View File

@@ -5,7 +5,7 @@
let { http } = global;
/**
* @param {org.autojs.autojs.runtime.ScriptRuntime} scriptRuntime
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.Web}
*/
@@ -20,7 +20,7 @@ module.exports = function (scriptRuntime, scope) {
* @implements Internal.Web
*/
const Web = function () {
// Empty interface body.
/* Empty body. */
};
Web.prototype = {
@@ -43,7 +43,7 @@ module.exports = function (scriptRuntime, scope) {
return new InjectableWebClient(Context.getCurrentContext(), scope);
},
newWebSocket(url) {
return new org.autojs.autojs.core.web.WebSocket(http.__okhttp__, url);
return new scope.WebSocket(url);
},
};
@@ -55,6 +55,33 @@ module.exports = function (scriptRuntime, scope) {
*/
let methods = [ 'newInjectableWebView', 'newInjectableWebClient', 'newWebSocket' ];
__asGlobal__(web, methods, scope);
const WebSocket = function () {
if (!(this instanceof WebSocket)) {
throw TypeError('WebSocket must be called as constructor');
}
if (arguments[0] instanceof MutableOkHttp) {
this.client = arguments[0];
this.url = arguments[1];
} else {
this.client = http.__okhttp__;
this.url = arguments[0];
}
if (typeof this.url !== 'string') {
throw TypeError(`Invalid url (value: ${this.url}, species: ${species(this.url)}) for WebSocket`);
}
return new org.autojs.autojs.core.web.WebSocket(this.client, this.url);
};
/* Append all primitive static fields. */
Object.keys(org.autojs.autojs.core.web.WebSocket).forEach((key) => {
let value = org.autojs.autojs.core.web.WebSocket[key]
if (isPrimitive(value)) {
WebSocket[key] = value;
}
});
scope.WebSocket = WebSocket;
},
};

View File

@@ -0,0 +1,50 @@
// noinspection UnnecessaryLocalVariableJS,JSUnusedLocalSymbols
/**
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.OcrMLKit}
*/
module.exports = function (scriptRuntime, scope) {
const rtOcrMLKit = scriptRuntime.ocrMLKit;
let _ = {
OcrMLKitCtor: (/* @IIFE */ () => {
/**
* @implements Internal.OcrMLKit
*/
const OcrMLKitCtor = function () {
return Object.assign(function () {
let argArray = Array.from(arguments);
/** @type {Internal.Ocr.ModeName} */
argArray[ocr['_forcibleModeArgIndex']] = ocr['_modeName']['mlkit'];
return ocr.recognizeText.apply(ocr, argArray);
}, OcrMLKitCtor.prototype);
};
OcrMLKitCtor.prototype = {
constructor: OcrMLKitCtor,
recognizeTextMethodCreator(options) {
return function (img) {
return Array.from(rtOcrMLKit.recognizeText(img));
};
},
detectMethodCreator(options) {
return function (img) {
return Array.from(rtOcrMLKit.detect(img).toArray());
};
},
};
return OcrMLKitCtor;
})(),
};
/**
* @type {Internal.OcrMLKit}
*/
const ocrMLKit = new _.OcrMLKitCtor();
return ocrMLKit;
};

View File

@@ -0,0 +1,68 @@
// noinspection UnnecessaryLocalVariableJS,JSUnusedLocalSymbols
/**
* @param {ScriptRuntime} scriptRuntime
* @param {org.mozilla.javascript.Scriptable | global} scope
* @return {Internal.OcrPaddle}
*/
module.exports = function (scriptRuntime, scope) {
const rtOcrPaddle = scriptRuntime.ocrPaddle;
let _ = {
OcrPaddleCtor: (/* @IIFE */ () => {
/**
* @implements Internal.OcrPaddle
*/
const OcrPaddleCtor = function () {
return Object.assign(function () {
let argArray = Array.from(arguments);
/** @type {Internal.Ocr.ModeName} */
argArray[ocr['_forcibleModeArgIndex']] = ocr['_modeName']['paddle'];
return ocr.recognizeText.apply(ocr, argArray);
}, OcrPaddleCtor.prototype);
};
OcrPaddleCtor.prototype = {
constructor: OcrPaddleCtor,
recognizeTextMethodCreator(options) {
return function (img) {
const { cpuThreadNum, useSlim } = options;
let niceUseSlim = useSlim === undefined ? true : Boolean(useSlim);
let niceCpuThreadNum = cpuThreadNum || 4;
return Array.from(rtOcrPaddle.recognizeText(
img,
niceCpuThreadNum,
niceUseSlim,
));
};
},
detectMethodCreator(options) {
return function (img) {
const { cpuThreadNum, useSlim } = options;
let niceUseSlim = useSlim === undefined ? true : Boolean(useSlim);
let niceCpuThreadNum = cpuThreadNum || 4;
return Array.from(rtOcrPaddle.detect(
img,
niceCpuThreadNum,
niceUseSlim,
).toArray());
};
},
};
return OcrPaddleCtor;
})(),
};
/**
* @type {Internal.OcrPaddle}
*/
const ocrPaddle = new _.OcrPaddleCtor();
return ocrPaddle;
};

View File

@@ -0,0 +1,7 @@
auto();
events.observeKey();
events.setKeyInterceptionEnabled(true);
events.on('volume_down', () => {
app.sendBroadcast('bounds');
exit();
});

View File

@@ -1,22 +1,24 @@
var num1 = dialogs.input("请输入第一个数字");
var op = dialogs.singleChoice("请选择运算", ["加", "减", "乘", "除", "幂"]);
var num2 = dialogs.input("请输入第二个数字");
var result = 0;
switch(op){
case 0:
result = num1 + num2;
break;
case 1:
result = num1 - num2;
break;
case 2:
result = num1 * num2;
break;
case 3:
result = num1 / num2;
break;
case 4:
result = Math.pow(num1, num2);
break;
}
alert("运算结果", result);
(/* @IIFE */ function () {
var num1 = dialogs.input('请输入第一个数字');
var op = dialogs.singleChoice('请选择运算', [ '加', '减', '乘', '除', '幂' ]);
var num2 = dialogs.input('请输入第二个数字');
var result = 0;
switch (op) {
case 0:
result = num1 + num2;
break;
case 1:
result = num1 - num2;
break;
case 2:
result = num1 * num2;
break;
case 3:
result = num1 / num2;
break;
case 4:
result = Math.pow(num1, num2);
break;
}
alert('运算结果', result);
})();

View File

@@ -8,7 +8,7 @@
* 每一个的时长都为350毫秒
*/
gestures([350, [300, 400], [300, 1400]],
gestures([0, 350, [300, 400], [300, 1400]],
[350, [600, 400], [600, 1400]],
[350, [900, 400], [900, 1400]]
);