6.6.0 - 内置模块重写; 新增部分模块及方法; 修复高版本安卓系统兼容问题; 优化文件管理器及打包功能体验
This commit is contained in:
56
app/src/main/assets/modules/axios/browser-libs/utils.js
Normal file
56
app/src/main/assets/modules/axios/browser-libs/utils.js
Normal file
@@ -0,0 +1,56 @@
|
||||
(function() {
|
||||
function setReadonlyAttribute(obj, att, value, enumerable) {
|
||||
enumerable = (enumerable === undefined) ? true : enumerable
|
||||
Object.defineProperty(obj, att, {
|
||||
value,
|
||||
writable: false,
|
||||
configurable: true,
|
||||
enumerable,
|
||||
})
|
||||
}
|
||||
|
||||
function copyInputStream(inputstream, outputstream) {
|
||||
let buffer = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 1024 * 16);
|
||||
let length = 0;
|
||||
while ((length = inputstream.read(buffer)) > 0) {
|
||||
outputstream.write(buffer, 0, length);
|
||||
}
|
||||
outputstream.flush();
|
||||
}
|
||||
//此对象用于确保在多线程执行异步任务时主线程不会因空闲而停止
|
||||
function AsyncThreadLock() {
|
||||
this.lock = threads.lock();
|
||||
this.tasks = 0;
|
||||
this.intervalId = null;
|
||||
}
|
||||
setReadonlyAttribute(AsyncThreadLock, 'teeFn', function() {
|
||||
this.intervalId = setInterval(() => {
|
||||
this.lock.lock();
|
||||
if (this.tasks === 0) {
|
||||
clearInterval(this.intervalId)
|
||||
this.intervalId = null;
|
||||
}
|
||||
this.lock.unlock();
|
||||
}, 200)
|
||||
}, false)
|
||||
|
||||
AsyncThreadLock.prototype.addTask = function() {
|
||||
this.lock.lock();
|
||||
this.tasks++;
|
||||
if (this.intervalId === null) {
|
||||
AsyncThreadLock.teeFn.call(this)
|
||||
}
|
||||
this.lock.unlock();
|
||||
}
|
||||
AsyncThreadLock.prototype.removeTask = function() {
|
||||
this.lock.lock();
|
||||
this.tasks--;
|
||||
this.lock.unlock();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
setReadonlyAttribute,
|
||||
copyInputStream,
|
||||
AsyncThreadLock,
|
||||
}
|
||||
})()
|
||||
Reference in New Issue
Block a user