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

@@ -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;
})(),
};