From 3bd9a04272ad51f5da8e0c77f3d48c529e40da29 Mon Sep 17 00:00:00 2001 From: aiselp Date: Fri, 18 Aug 2023 22:19:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E4=BA=9B=E4=BB=A3=E7=A0=81=E7=BB=86?= =?UTF-8?q?=E8=8A=82=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- autojs/src/main/assets/init.js | 24 ++++----- .../axios/browser-libs/XMLHttpRequest.js | 50 ++++++++++--------- autojs/src/main/assets/modules/npm/stream.js | 4 +- .../com/stardust/autojs/runtime/api/UI.java | 1 - 4 files changed, 42 insertions(+), 37 deletions(-) diff --git a/autojs/src/main/assets/init.js b/autojs/src/main/assets/init.js index 0cf8feae2..76cbe84cb 100644 --- a/autojs/src/main/assets/init.js +++ b/autojs/src/main/assets/init.js @@ -48,19 +48,19 @@ runtime.init(); } }; - // 初始化基础模块 - global.timers = require('__timers__.js')(runtime, global); + // 初始化基础模块 + global.timers = require('__timers__.js')(runtime, global); - //初始化不依赖环境的模块 - global.JSON = require('__json2__.js'); - global.util = global.$util = require('__util__.js'); - global.device = runtime.device; + //初始化不依赖环境的模块 + global.JSON = require('__json2__.js'); + global.util = global.$util = require('__util__.js'); + global.device = runtime.device; - global.process = require('process') - global.Promise = require('bluebird.js'); + global.process = require('process') + global.Promise = require('bluebird'); - //设置JavaScriptBridges用于与Java层的交互和数据转换 - runtime.bridges.setBridges(require('__bridges__.js')); + //设置JavaScriptBridges用于与Java层的交互和数据转换 + runtime.bridges.setBridges(require('__bridges__.js')); //初始化全局函数 require("__globals__")(runtime, global); @@ -68,13 +68,13 @@ runtime.init(); (function (scope) { var modules = ['app', 'automator', 'console', 'dialogs', 'files', 'io', 'selector', 'shell', 'web', 'ui', "images", "threads", "events", "engines", "RootAutomator", "http", "storages", "floaty", - "sensors", "media", "plugins", "continuation", "$zip", "$base64", "$crypto","paddle"]; + "sensors", "media", "plugins", "continuation", "$zip", "$base64", "$crypto", "paddle"]; var len = modules.length; for (var i = 0; i < len; i++) { var m = modules[i]; let module = require('__' + m + '__')(scope.runtime, scope); scope[m] = module; - if(!m.startsWith('$')) { + if (!m.startsWith('$')) { scope['$' + m] = module; } } diff --git a/autojs/src/main/assets/modules/axios/browser-libs/XMLHttpRequest.js b/autojs/src/main/assets/modules/axios/browser-libs/XMLHttpRequest.js index 5d65a8ff3..1fb211154 100644 --- a/autojs/src/main/assets/modules/axios/browser-libs/XMLHttpRequest.js +++ b/autojs/src/main/assets/modules/axios/browser-libs/XMLHttpRequest.js @@ -126,32 +126,36 @@ setReadonlyAttribute(xhr, '_call', call, false); call.enqueue({ onFailure(call, e) { - xhr._setReadyState(4); - setReadonlyAttribute(xhr, 'statusText', e.message) - if (e instanceof InterruptedIOException) { - xhr.dispatchEvent(new Event('timeout')); - } - xhr.dispatchEvent(new Event('error')) - xhr.dispatchEvent(new Event('loadend')) - atl.removeTask() - }, - onResponse(call, res) { - setReadonlyAttribute(xhr, 'status', res.code()); - setReadonlyAttribute(xhr, 'statusText', res.message()); - setReadonlyAttribute(xhr, 'responseURL', res.request().url().toString()) - setReadonlyAttribute(xhr, '_resHeaders', res.headers(), false) - xhr._setReadyState(2); - try { - XMLHttpRequest._parserResBody - .parser(xhr.responseType, xhr, res.body()); - - } catch (e) { - res.close(); + setImmediate(() => { xhr._setReadyState(4); + setReadonlyAttribute(xhr, 'statusText', e.message) + if (e instanceof InterruptedIOException) { + xhr.dispatchEvent(new Event('timeout')); + } xhr.dispatchEvent(new Event('error')) xhr.dispatchEvent(new Event('loadend')) - } - atl.removeTask(); + atl.removeTask() + }) + }, + onResponse(call, res) { + setImmediate(() => { + setReadonlyAttribute(xhr, 'status', res.code()); + setReadonlyAttribute(xhr, 'statusText', res.message()); + setReadonlyAttribute(xhr, 'responseURL', res.request().url().toString()) + setReadonlyAttribute(xhr, '_resHeaders', res.headers(), false) + xhr._setReadyState(2); + try { + XMLHttpRequest._parserResBody + .parser(xhr.responseType, xhr, res.body()); + + } catch (e) { + res.close(); + xhr._setReadyState(4); + xhr.dispatchEvent(new Event('error')) + xhr.dispatchEvent(new Event('loadend')) + } + atl.removeTask(); + }) } }) } diff --git a/autojs/src/main/assets/modules/npm/stream.js b/autojs/src/main/assets/modules/npm/stream.js index 477a4509d..27a0b1eea 100644 --- a/autojs/src/main/assets/modules/npm/stream.js +++ b/autojs/src/main/assets/modules/npm/stream.js @@ -18,9 +18,11 @@ function addTask(th, fn, callback) { }) } function createThread() { - return threads.start(() => { + let th = threads.start(() => { setInterval(() => { }, 1000) }) + th.waitFor() + return th } stream.fromInputStream = function (inp, options) { diff --git a/autojs/src/main/java/com/stardust/autojs/runtime/api/UI.java b/autojs/src/main/java/com/stardust/autojs/runtime/api/UI.java index be8f6f01f..dad1701b4 100644 --- a/autojs/src/main/java/com/stardust/autojs/runtime/api/UI.java +++ b/autojs/src/main/java/com/stardust/autojs/runtime/api/UI.java @@ -2,7 +2,6 @@ import android.content.Context; import android.graphics.drawable.Drawable; -import androidx.annotation.Nullable; import com.stardust.autojs.core.graphics.ScriptCanvasView; import com.stardust.autojs.core.ui.inflater.DynamicLayoutInflater;