Skip to content

Commit

Permalink
一些代码细节优化
Browse files Browse the repository at this point in the history
  • Loading branch information
aiselp committed Aug 18, 2023
1 parent e6ecf16 commit 3bd9a04
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 37 deletions.
24 changes: 12 additions & 12 deletions autojs/src/main/assets/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,33 @@ 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);
//初始化一般模块
(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;
}
}
Expand Down
50 changes: 27 additions & 23 deletions autojs/src/main/assets/modules/axios/browser-libs/XMLHttpRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
})
}
})
}
Expand Down
4 changes: 3 additions & 1 deletion autojs/src/main/assets/modules/npm/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3bd9a04

Please sign in to comment.